@angular-modernizer/adapter-mcp 0.3.0 → 1.1.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 (298) hide show
  1. package/README.md +181 -282
  2. package/dist/cli.js +21 -13
  3. package/dist/core/project-analyzer.d.ts +3 -12
  4. package/dist/core/project-analyzer.js +3 -12
  5. package/dist/index.d.ts +122 -6
  6. package/dist/index.js +49 -5
  7. package/dist/mcp-watcher.d.ts +32 -7
  8. package/dist/mcp-watcher.js +16 -15
  9. package/dist/scan-host/scan-host.d.ts +119 -0
  10. package/dist/scan-host/scan-host.js +376 -0
  11. package/dist/scan-host/scan-protocol.d.ts +35 -0
  12. package/dist/scan-host/scan-protocol.js +6 -0
  13. package/dist/scan-host/scan-worker.d.ts +14 -0
  14. package/dist/scan-host/scan-worker.js +48 -0
  15. package/dist/server/limited-stdio-transport.d.ts +75 -0
  16. package/dist/server/limited-stdio-transport.js +115 -0
  17. package/dist/server/mcp-server.d.ts +20 -18
  18. package/dist/server/mcp-server.js +42 -79
  19. package/dist/server/package-version.d.ts +16 -0
  20. package/dist/server/package-version.js +37 -0
  21. package/dist/server/sdk-server.d.ts +71 -0
  22. package/dist/server/sdk-server.js +113 -0
  23. package/dist/server/tool-registry.d.ts +6 -9
  24. package/dist/server/tool-registry.js +6 -12
  25. package/dist/streaming/progress-store.d.ts +22 -5
  26. package/dist/streaming/progress-store.js +9 -5
  27. package/dist/tools/analyze-build-impact.d.ts +276 -35
  28. package/dist/tools/analyze-build-impact.js +175 -28
  29. package/dist/tools/analyze-core-to-shared.d.ts +176 -16
  30. package/dist/tools/analyze-core-to-shared.js +124 -19
  31. package/dist/tools/analyze-parser-performance.d.ts +209 -15
  32. package/dist/tools/analyze-parser-performance.js +119 -56
  33. package/dist/tools/analyze-project.d.ts +349 -17
  34. package/dist/tools/analyze-project.js +282 -97
  35. package/dist/tools/check-incremental-compatibility.d.ts +74 -12
  36. package/dist/tools/check-incremental-compatibility.js +69 -10
  37. package/dist/tools/collect-feedback.d.ts +225 -21
  38. package/dist/tools/collect-feedback.js +199 -118
  39. package/dist/tools/compare-health.d.ts +413 -0
  40. package/dist/tools/compare-health.js +479 -0
  41. package/dist/tools/extract-libraries.d.ts +200 -24
  42. package/dist/tools/extract-libraries.js +131 -27
  43. package/dist/tools/find-angular-symbol.d.ts +92 -24
  44. package/dist/tools/find-angular-symbol.js +70 -20
  45. package/dist/tools/find-component-hosts.d.ts +603 -27
  46. package/dist/tools/find-component-hosts.js +223 -19
  47. package/dist/tools/find-usages.d.ts +102 -22
  48. package/dist/tools/find-usages.js +81 -21
  49. package/dist/tools/get-bootstrap-execution.d.ts +183 -25
  50. package/dist/tools/get-bootstrap-execution.js +109 -25
  51. package/dist/tools/get-call-graph.d.ts +127 -12
  52. package/dist/tools/get-call-graph.js +84 -19
  53. package/dist/tools/get-operation-progress-tool.d.ts +126 -8
  54. package/dist/tools/get-operation-progress-tool.js +124 -12
  55. package/dist/tools/get-operation-progress.d.ts +27 -1
  56. package/dist/tools/get-operation-progress.js +5 -5
  57. package/dist/tools/helpers/analysis-output.d.ts +182 -0
  58. package/dist/tools/helpers/analysis-output.js +165 -0
  59. package/dist/tools/helpers/batch-kernel.d.ts +14 -0
  60. package/dist/tools/helpers/batch-kernel.js +12 -0
  61. package/dist/tools/helpers/build-schemas.d.ts +36 -0
  62. package/dist/tools/helpers/build-schemas.js +23 -0
  63. package/dist/tools/helpers/citation-file-source.d.ts +10 -0
  64. package/dist/tools/helpers/citation-file-source.js +82 -0
  65. package/dist/tools/helpers/compact-output.d.ts +2 -1
  66. package/dist/tools/helpers/compact-output.js +2 -1
  67. package/dist/tools/helpers/finding-window.d.ts +43 -0
  68. package/dist/tools/helpers/finding-window.js +64 -0
  69. package/dist/tools/helpers/health-delta.d.ts +99 -0
  70. package/dist/tools/helpers/health-delta.js +236 -0
  71. package/dist/tools/helpers/investigation-schemas.d.ts +93 -0
  72. package/dist/tools/helpers/investigation-schemas.js +48 -0
  73. package/dist/tools/helpers/library-imports.d.ts +57 -0
  74. package/dist/tools/helpers/library-imports.js +151 -0
  75. package/dist/tools/helpers/load-source-files.d.ts +30 -0
  76. package/dist/tools/helpers/load-source-files.js +34 -0
  77. package/dist/tools/helpers/output-contract.d.ts +32 -0
  78. package/dist/tools/helpers/output-contract.js +32 -0
  79. package/dist/tools/helpers/platform-root-resolver.d.ts +55 -25
  80. package/dist/tools/helpers/platform-root-resolver.js +75 -48
  81. package/dist/tools/helpers/process-output.d.ts +19 -0
  82. package/dist/tools/helpers/process-output.js +31 -0
  83. package/dist/tools/helpers/project-cache.d.ts +60 -37
  84. package/dist/tools/helpers/project-cache.js +54 -37
  85. package/dist/tools/helpers/project-decorators.d.ts +14 -0
  86. package/dist/tools/helpers/project-decorators.js +22 -0
  87. package/dist/tools/helpers/rule-matcher.js +5 -0
  88. package/dist/tools/helpers/rule-runner.d.ts +25 -13
  89. package/dist/tools/helpers/rule-runner.js +45 -24
  90. package/dist/tools/helpers/scan-cache.d.ts +22 -0
  91. package/dist/tools/helpers/scan-cache.js +34 -0
  92. package/dist/tools/helpers/scan-engine.d.ts +107 -0
  93. package/dist/tools/helpers/scan-engine.js +197 -0
  94. package/dist/tools/helpers/scan-plan.d.ts +5 -2
  95. package/dist/tools/helpers/scan-plan.js +18 -3
  96. package/dist/tools/helpers/scope-paths.d.ts +17 -0
  97. package/dist/tools/helpers/scope-paths.js +32 -0
  98. package/dist/tools/helpers/suggestion-generator.d.ts +9 -13
  99. package/dist/tools/helpers/suggestion-generator.js +0 -12
  100. package/dist/tools/helpers/tool-cache.d.ts +11 -0
  101. package/dist/tools/helpers/tool-cache.js +15 -0
  102. package/dist/tools/helpers/tool-context.d.ts +63 -0
  103. package/dist/tools/helpers/tool-context.js +79 -0
  104. package/dist/tools/helpers/transform-safety.d.ts +40 -0
  105. package/dist/tools/helpers/transform-safety.js +87 -0
  106. package/dist/tools/helpers/validation-output.d.ts +53 -0
  107. package/dist/tools/helpers/validation-output.js +48 -0
  108. package/dist/tools/inspect-form-group.d.ts +262 -24
  109. package/dist/tools/inspect-form-group.js +134 -13
  110. package/dist/tools/inspect-i18n.d.ts +410 -23
  111. package/dist/tools/inspect-i18n.js +213 -13
  112. package/dist/tools/inspect-template.d.ts +260 -22
  113. package/dist/tools/inspect-template.js +174 -13
  114. package/dist/tools/learn-patterns.d.ts +210 -13
  115. package/dist/tools/learn-patterns.js +113 -12
  116. package/dist/tools/list-imports.d.ts +152 -34
  117. package/dist/tools/list-imports.js +124 -18
  118. package/dist/tools/orchestrate-migration.d.ts +159 -14
  119. package/dist/tools/orchestrate-migration.js +147 -20
  120. package/dist/tools/parse-stack-trace.d.ts +78 -21
  121. package/dist/tools/parse-stack-trace.js +44 -7
  122. package/dist/tools/plan-migration.d.ts +395 -26
  123. package/dist/tools/plan-migration.js +173 -22
  124. package/dist/tools/resolve-type.d.ts +57 -9
  125. package/dist/tools/resolve-type.js +49 -12
  126. package/dist/tools/review-feedback.d.ts +214 -16
  127. package/dist/tools/review-feedback.js +142 -57
  128. package/dist/tools/rollback-changes.d.ts +88 -7
  129. package/dist/tools/rollback-changes.js +74 -19
  130. package/dist/tools/run-angular-cli.d.ts +57 -12
  131. package/dist/tools/run-angular-cli.js +76 -13
  132. package/dist/tools/run-build.d.ts +127 -13
  133. package/dist/tools/run-build.js +128 -16
  134. package/dist/tools/run-schematic.d.ts +82 -12
  135. package/dist/tools/run-schematic.js +115 -18
  136. package/dist/tools/scan-all.d.ts +88 -23
  137. package/dist/tools/scan-all.js +161 -220
  138. package/dist/tools/scan-angular.d.ts +60 -19
  139. package/dist/tools/scan-angular.js +100 -141
  140. package/dist/tools/scan-architecture.d.ts +92 -24
  141. package/dist/tools/scan-architecture.js +268 -211
  142. package/dist/tools/scan-solid.d.ts +59 -19
  143. package/dist/tools/scan-solid.js +98 -139
  144. package/dist/tools/search-codebase.d.ts +110 -23
  145. package/dist/tools/search-codebase.js +67 -11
  146. package/dist/tools/server-status.d.ts +392 -26
  147. package/dist/tools/server-status.js +260 -27
  148. package/dist/tools/suggest-improvements.d.ts +105 -10
  149. package/dist/tools/suggest-improvements.js +91 -51
  150. package/dist/tools/trace-output-flow.d.ts +713 -26
  151. package/dist/tools/trace-output-flow.js +396 -33
  152. package/dist/tools/transform-code-batch.d.ts +3 -0
  153. package/dist/tools/transform-code-batch.js +10 -5
  154. package/dist/tools/transform-code.d.ts +402 -18
  155. package/dist/tools/transform-code.js +708 -649
  156. package/dist/tools/validate-before-transform.d.ts +136 -7
  157. package/dist/tools/validate-before-transform.js +65 -9
  158. package/dist/tools/validate-project-compatibility.d.ts +82 -15
  159. package/dist/tools/validate-project-compatibility.js +84 -15
  160. package/dist/tools/validate-transformation.d.ts +243 -8
  161. package/dist/tools/validate-transformation.js +127 -23
  162. package/dist/tools/verify-citations.d.ts +202 -0
  163. package/dist/tools/verify-citations.js +221 -0
  164. package/dist/types.d.ts +78 -11
  165. package/dist/types.js +0 -5
  166. package/dist/utils/format-tool-response.d.ts +22 -59
  167. package/dist/utils/format-tool-response.js +25 -134
  168. package/package.json +31 -20
  169. package/dist/cli.d.ts.map +0 -1
  170. package/dist/cli.js.map +0 -1
  171. package/dist/core/project-analyzer.d.ts.map +0 -1
  172. package/dist/core/project-analyzer.js.map +0 -1
  173. package/dist/index.d.ts.map +0 -1
  174. package/dist/index.js.map +0 -1
  175. package/dist/mcp-watcher.d.ts.map +0 -1
  176. package/dist/mcp-watcher.js.map +0 -1
  177. package/dist/server/json-rpc-handler.d.ts +0 -98
  178. package/dist/server/json-rpc-handler.d.ts.map +0 -1
  179. package/dist/server/json-rpc-handler.js +0 -301
  180. package/dist/server/json-rpc-handler.js.map +0 -1
  181. package/dist/server/mcp-server.d.ts.map +0 -1
  182. package/dist/server/mcp-server.js.map +0 -1
  183. package/dist/server/stdio-guard.d.ts.map +0 -1
  184. package/dist/server/stdio-guard.js.map +0 -1
  185. package/dist/server/tool-registry.d.ts.map +0 -1
  186. package/dist/server/tool-registry.js.map +0 -1
  187. package/dist/streaming/progress-store.d.ts.map +0 -1
  188. package/dist/streaming/progress-store.js.map +0 -1
  189. package/dist/tools/analyze-build-impact.d.ts.map +0 -1
  190. package/dist/tools/analyze-build-impact.js.map +0 -1
  191. package/dist/tools/analyze-core-to-shared.d.ts.map +0 -1
  192. package/dist/tools/analyze-core-to-shared.js.map +0 -1
  193. package/dist/tools/analyze-parser-performance.d.ts.map +0 -1
  194. package/dist/tools/analyze-parser-performance.js.map +0 -1
  195. package/dist/tools/analyze-project.d.ts.map +0 -1
  196. package/dist/tools/analyze-project.js.map +0 -1
  197. package/dist/tools/check-incremental-compatibility.d.ts.map +0 -1
  198. package/dist/tools/check-incremental-compatibility.js.map +0 -1
  199. package/dist/tools/collect-feedback.d.ts.map +0 -1
  200. package/dist/tools/collect-feedback.js.map +0 -1
  201. package/dist/tools/extract-libraries.d.ts.map +0 -1
  202. package/dist/tools/extract-libraries.js.map +0 -1
  203. package/dist/tools/find-angular-symbol.d.ts.map +0 -1
  204. package/dist/tools/find-angular-symbol.js.map +0 -1
  205. package/dist/tools/find-component-hosts.d.ts.map +0 -1
  206. package/dist/tools/find-component-hosts.js.map +0 -1
  207. package/dist/tools/find-usages.d.ts.map +0 -1
  208. package/dist/tools/find-usages.js.map +0 -1
  209. package/dist/tools/get-bootstrap-execution.d.ts.map +0 -1
  210. package/dist/tools/get-bootstrap-execution.js.map +0 -1
  211. package/dist/tools/get-call-graph.d.ts.map +0 -1
  212. package/dist/tools/get-call-graph.js.map +0 -1
  213. package/dist/tools/get-operation-progress-tool.d.ts.map +0 -1
  214. package/dist/tools/get-operation-progress-tool.js.map +0 -1
  215. package/dist/tools/get-operation-progress.d.ts.map +0 -1
  216. package/dist/tools/get-operation-progress.js.map +0 -1
  217. package/dist/tools/helpers/compact-output.d.ts.map +0 -1
  218. package/dist/tools/helpers/compact-output.js.map +0 -1
  219. package/dist/tools/helpers/feedback-analyzer.d.ts.map +0 -1
  220. package/dist/tools/helpers/feedback-analyzer.js.map +0 -1
  221. package/dist/tools/helpers/find-ts-config.d.ts.map +0 -1
  222. package/dist/tools/helpers/find-ts-config.js.map +0 -1
  223. package/dist/tools/helpers/platform-root-resolver.d.ts.map +0 -1
  224. package/dist/tools/helpers/platform-root-resolver.js.map +0 -1
  225. package/dist/tools/helpers/project-cache.d.ts.map +0 -1
  226. package/dist/tools/helpers/project-cache.js.map +0 -1
  227. package/dist/tools/helpers/rule-matcher.d.ts.map +0 -1
  228. package/dist/tools/helpers/rule-matcher.js.map +0 -1
  229. package/dist/tools/helpers/rule-runner.d.ts.map +0 -1
  230. package/dist/tools/helpers/rule-runner.js.map +0 -1
  231. package/dist/tools/helpers/scan-plan.d.ts.map +0 -1
  232. package/dist/tools/helpers/scan-plan.js.map +0 -1
  233. package/dist/tools/helpers/stack-frame-file-index.d.ts.map +0 -1
  234. package/dist/tools/helpers/stack-frame-file-index.js.map +0 -1
  235. package/dist/tools/helpers/suggestion-generator.d.ts.map +0 -1
  236. package/dist/tools/helpers/suggestion-generator.js.map +0 -1
  237. package/dist/tools/inspect-form-group.d.ts.map +0 -1
  238. package/dist/tools/inspect-form-group.js.map +0 -1
  239. package/dist/tools/inspect-i18n.d.ts.map +0 -1
  240. package/dist/tools/inspect-i18n.js.map +0 -1
  241. package/dist/tools/inspect-template.d.ts.map +0 -1
  242. package/dist/tools/inspect-template.js.map +0 -1
  243. package/dist/tools/learn-patterns.d.ts.map +0 -1
  244. package/dist/tools/learn-patterns.js.map +0 -1
  245. package/dist/tools/list-imports.d.ts.map +0 -1
  246. package/dist/tools/list-imports.js.map +0 -1
  247. package/dist/tools/orchestrate-migration.d.ts.map +0 -1
  248. package/dist/tools/orchestrate-migration.js.map +0 -1
  249. package/dist/tools/parse-stack-trace.d.ts.map +0 -1
  250. package/dist/tools/parse-stack-trace.js.map +0 -1
  251. package/dist/tools/plan-migration.d.ts.map +0 -1
  252. package/dist/tools/plan-migration.js.map +0 -1
  253. package/dist/tools/resolve-type.d.ts.map +0 -1
  254. package/dist/tools/resolve-type.js.map +0 -1
  255. package/dist/tools/review-feedback.d.ts.map +0 -1
  256. package/dist/tools/review-feedback.js.map +0 -1
  257. package/dist/tools/rollback-changes.d.ts.map +0 -1
  258. package/dist/tools/rollback-changes.js.map +0 -1
  259. package/dist/tools/run-angular-cli.d.ts.map +0 -1
  260. package/dist/tools/run-angular-cli.js.map +0 -1
  261. package/dist/tools/run-build.d.ts.map +0 -1
  262. package/dist/tools/run-build.js.map +0 -1
  263. package/dist/tools/run-schematic.d.ts.map +0 -1
  264. package/dist/tools/run-schematic.js.map +0 -1
  265. package/dist/tools/scan-all.d.ts.map +0 -1
  266. package/dist/tools/scan-all.js.map +0 -1
  267. package/dist/tools/scan-angular.d.ts.map +0 -1
  268. package/dist/tools/scan-angular.js.map +0 -1
  269. package/dist/tools/scan-architecture.d.ts.map +0 -1
  270. package/dist/tools/scan-architecture.js.map +0 -1
  271. package/dist/tools/scan-solid.d.ts.map +0 -1
  272. package/dist/tools/scan-solid.js.map +0 -1
  273. package/dist/tools/search-codebase.d.ts.map +0 -1
  274. package/dist/tools/search-codebase.js.map +0 -1
  275. package/dist/tools/server-status.d.ts.map +0 -1
  276. package/dist/tools/server-status.js.map +0 -1
  277. package/dist/tools/shared/scan-types.d.ts +0 -200
  278. package/dist/tools/shared/scan-types.d.ts.map +0 -1
  279. package/dist/tools/shared/scan-types.js +0 -7
  280. package/dist/tools/shared/scan-types.js.map +0 -1
  281. package/dist/tools/suggest-improvements.d.ts.map +0 -1
  282. package/dist/tools/suggest-improvements.js.map +0 -1
  283. package/dist/tools/trace-output-flow.d.ts.map +0 -1
  284. package/dist/tools/trace-output-flow.js.map +0 -1
  285. package/dist/tools/transform-code-batch.d.ts.map +0 -1
  286. package/dist/tools/transform-code-batch.js.map +0 -1
  287. package/dist/tools/transform-code.d.ts.map +0 -1
  288. package/dist/tools/transform-code.js.map +0 -1
  289. package/dist/tools/validate-before-transform.d.ts.map +0 -1
  290. package/dist/tools/validate-before-transform.js.map +0 -1
  291. package/dist/tools/validate-project-compatibility.d.ts.map +0 -1
  292. package/dist/tools/validate-project-compatibility.js.map +0 -1
  293. package/dist/tools/validate-transformation.d.ts.map +0 -1
  294. package/dist/tools/validate-transformation.js.map +0 -1
  295. package/dist/types.d.ts.map +0 -1
  296. package/dist/types.js.map +0 -1
  297. package/dist/utils/format-tool-response.d.ts.map +0 -1
  298. package/dist/utils/format-tool-response.js.map +0 -1
@@ -1,25 +1,34 @@
1
- /**
2
- * @angular-modernizer/adapter-mcp - Scan Angular Best Practices Tool
3
- *
4
- * MCP tool for scanning Angular codebases for Angular-specific best practice violations.
5
- * Runs only the AngularPlugin (28 rules: OnPush, TrackBy, Performance, RxJS, etc.).
6
- */
7
1
  import { findTsConfig } from './helpers/find-ts-config.js';
8
- import { Kernel, createToolCacheConfig, loadConfig, } from '@angular-modernizer/core';
9
- import { AngularPlugin } from '@angular-modernizer/plugin-angular';
10
- import { ContextFactory } from '@angular-modernizer/plugin-system';
11
- import { createPublicApi } from '@angular-modernizer/api';
12
2
  import { glob } from 'glob';
13
3
  import { resolve, relative } from 'node:path';
14
4
  import { readFileSync, existsSync } from 'node:fs';
5
+ import { describeScan, SCAN_EXECUTION_SCHEMA, scanOutputSchema, } from './helpers/analysis-output.js';
6
+ import { cancelledExecution, fileProgressMessage, } from './helpers/tool-context.js';
7
+ import { runScan } from '../scan-host/scan-host.js';
8
+ import { openToolCache } from './helpers/tool-cache.js';
15
9
  /**
16
- * Scan for Angular best practice violations using the AngularPlugin.
10
+ * MCP tool `scan-angular`: scans for Angular-specific best practice
11
+ * violations. Runs only the AngularPlugin (28 rules: OnPush, TrackBy,
12
+ * performance, RxJS and others).
17
13
  */
18
14
  export class ScanAngularTool {
19
15
  name = 'scan-angular';
20
- description = 'Scan for Angular best practice violations (OnPush, TrackBy, Performance, RxJS, etc.)';
16
+ title = 'Scan Angular Patterns';
17
+ annotations = {
18
+ readOnlyHint: true,
19
+ destructiveHint: false,
20
+ idempotentHint: true,
21
+ openWorldHint: false,
22
+ };
23
+ description = 'Scan for Angular best practice violations (OnPush, TrackBy, Performance, RxJS, etc.). maxResults (default 1000) ' +
24
+ 'and resultOffset page the violations; counts cover all of them, summary is a short text.';
25
+ /**
26
+ * JSON Schema of the tool arguments.
27
+ * @hidden
28
+ */
21
29
  inputSchema = {
22
30
  type: 'object',
31
+ additionalProperties: false,
23
32
  properties: {
24
33
  rootPath: {
25
34
  type: 'string',
@@ -89,7 +98,12 @@ export class ScanAngularTool {
89
98
  },
90
99
  required: ['rootPath'],
91
100
  };
92
- async execute(args) {
101
+ /**
102
+ * JSON Schema of the tool result (`structuredContent`).
103
+ * @hidden
104
+ */
105
+ outputSchema = scanOutputSchema({ execution: SCAN_EXECUTION_SCHEMA });
106
+ async execute(args, ctx = {}) {
93
107
  const params = args;
94
108
  const config = this.loadConfig(params.rootPath);
95
109
  const mergedParams = { ...config, ...params };
@@ -102,16 +116,6 @@ export class ScanAngularTool {
102
116
  if (!tsConfigPath) {
103
117
  throw new Error('Could not find tsconfig.json');
104
118
  }
105
- // Initialize kernel with AngularPlugin and caching
106
- const kernel = new Kernel({
107
- tsConfigPath,
108
- plugins: [new AngularPlugin()],
109
- fileSystem: undefined,
110
- projectOptions: {
111
- skipAddingFilesFromTsConfig: true, // We'll add filtered files manually
112
- },
113
- cacheConfig: createToolCacheConfig(mergedParams.rootPath, 'angular'),
114
- });
115
119
  // Find files to analyze
116
120
  const includePatterns = mergedParams.includePatterns ?? ['**/*.{ts,tsx}'];
117
121
  const excludePatterns = mergedParams.excludePatterns ?? [
@@ -133,19 +137,11 @@ export class ScanAngularTool {
133
137
  });
134
138
  allFiles.push(...files);
135
139
  }
136
- const uniqueFiles = Array.from(new Set(allFiles));
140
+ // Sorted: glob returns files in no fixed order, the result pages depend on it
141
+ const uniqueFiles = Array.from(new Set(allFiles)).sort();
137
142
  const filesToAnalyze = uniqueFiles; // Analyze ALL files found (batch processing prevents memory issues)
138
143
  const maxFiles = mergedParams.maxFiles ?? 100; // Batch size (default 100)
139
- // Initialize kernel
140
- await kernel.initialize();
141
- // Load rules config from .angular-modernizer.json for per-rule overrides (BUG-3)
142
- const fullConfig = loadConfig(mergedParams.rootPath);
143
- const rulesConfig = fullConfig.rules;
144
- // Get analysis rules from the already-initialized plugin instances so that
145
- // ruleConfigs from .angular-modernizer.json are applied correctly.
146
- const allRules = kernel
147
- .getAllPlugins()
148
- .flatMap((p) => p.getAnalysisRules());
144
+ const cache = await openToolCache(mergedParams.rootPath, 'angular');
149
145
  // ============================================================================
150
146
  // CACHE READ SYSTEM
151
147
  // ============================================================================
@@ -165,28 +161,20 @@ export class ScanAngularTool {
165
161
  // Cache directory: .angular-modernizer-cache/angular/
166
162
  // Cache invalidation: Automatic via mtime/content hash checking
167
163
  // ============================================================================
168
- const cacheManagerForRead = kernel.getCacheManager();
169
164
  const cachedResults = []; // eslint-disable-line @typescript-eslint/no-explicit-any
170
- let filesToProcess = [];
171
- if (cacheManagerForRead) {
172
- for (const filePath of filesToAnalyze) {
173
- const cached = await cacheManagerForRead.getAnalysisResult(filePath);
174
- if (cached?.results && cached.results.length > 0) {
175
- // File is cached and hasn't changed
176
- cachedResults.push(...cached.results);
177
- }
178
- else {
179
- // File not cached or has changed
180
- filesToProcess.push(filePath);
181
- }
165
+ const filesToProcess = [];
166
+ for (const filePath of filesToAnalyze) {
167
+ const cached = await cache.getAnalysisResult(filePath);
168
+ if (cached?.results && cached.results.length > 0) {
169
+ // File is cached and hasn't changed
170
+ cachedResults.push(...cached.results);
171
+ }
172
+ else {
173
+ // File not cached or has changed
174
+ filesToProcess.push(filePath);
182
175
  }
183
- const stats = cacheManagerForRead.getStats();
184
- console.info(`Cache: ${cachedResults.length} results from cache, ${filesToProcess.length} files to analyze (hit rate: ${stats.hitRate.toFixed(1)}%)`);
185
- }
186
- else {
187
- // No cache manager, analyze all files
188
- filesToProcess = filesToAnalyze;
189
176
  }
177
+ console.info(`Cache: ${cachedResults.length} results from cache, ${filesToProcess.length} files to analyze (hit rate: ${cache.getStats().hitRate.toFixed(1)}%)`);
190
178
  // ============================================================================
191
179
  // BATCH PROCESSING SYSTEM
192
180
  // ============================================================================
@@ -206,66 +194,33 @@ export class ScanAngularTool {
206
194
  // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment
207
195
  const results = [...cachedResults];
208
196
  let filesAnalyzed = cachedResults.length;
209
- // Process each batch
210
- for (let batchNum = 0; batchNum < totalBatches; batchNum++) {
211
- const batchStart = batchNum * batchSize;
212
- const batchEnd = Math.min(batchStart + batchSize, totalFiles);
213
- const batchFiles = filesToProcess.slice(batchStart, batchEnd);
214
- console.info(`\nBatch ${batchNum + 1}/${totalBatches}: Processing files ${batchStart + 1}-${batchEnd} (${batchFiles.length} files)`);
215
- // Clear project and add batch files
216
- const project = kernel.getProject();
217
- // Remove all source files from previous batch
218
- const existingFiles = project.getSourceFiles();
219
- for (const file of existingFiles) {
220
- project.removeSourceFile(file);
221
- }
222
- // Add current batch files
223
- for (const filePath of batchFiles) {
224
- try {
225
- project.addSourceFileAtPath(filePath);
226
- }
227
- catch (error) {
228
- console.warn(`Failed to add file ${filePath}:`, error);
229
- }
230
- }
231
- console.info(`Batch ${batchNum + 1}: Project now has ${project.getSourceFiles().length} source files`);
232
- // Create PublicApi for this batch
233
- const api = createPublicApi(project); // eslint-disable-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment
234
- // Analyze files in this batch
235
- let batchViolationCount = 0;
236
- for (const sourceFile of project.getSourceFiles()) {
237
- for (const rule of allRules) {
238
- try {
239
- const ruleResults = await rule.analyze(ContextFactory.createAnalysisContext({
240
- sourceFile,
241
- project,
242
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
243
- api,
244
- config: rulesConfig,
245
- }));
246
- for (const result of ruleResults) {
247
- results.push({
248
- ruleId: result.ruleId,
249
- severity: rule.severity,
250
- message: result.message,
251
- filePath: result.filePath,
252
- line: result.line,
253
- column: result.column,
254
- category: rule.category,
255
- suggestedFix: result.suggestedFix,
256
- metadata: result.metadata,
257
- });
258
- batchViolationCount++;
259
- }
260
- }
261
- catch (error) {
262
- console.warn(`Failed to analyze with rule ${rule.id}:`, error);
263
- }
264
- }
265
- }
266
- filesAnalyzed += batchFiles.length;
267
- console.info(`Batch ${batchNum + 1}: Found ${batchViolationCount} violations in ${batchFiles.length} files`);
197
+ // Kernel, batches and rules run in a scan worker (scan-host), so the
198
+ // server keeps reading stdin while the type checker is built.
199
+ const cachedFiles = filesToAnalyze.length - totalFiles;
200
+ let processedFiles = 0;
201
+ if (totalFiles > 0) {
202
+ ctx.progress?.(cachedFiles, filesToAnalyze.length, `loading project, ${totalFiles} files to analyze`);
268
203
  }
204
+ const engine = await runScan({
205
+ tool: this.name,
206
+ plugins: 'angular',
207
+ tsConfigPath,
208
+ rootPath: mergedParams.rootPath,
209
+ files: filesToProcess,
210
+ mode: 'batches',
211
+ batchSize,
212
+ analyzeProjectFiles: true,
213
+ }, {
214
+ file: (event) => {
215
+ results.push(...event.findings);
216
+ processedFiles++;
217
+ ctx.progress?.(cachedFiles + processedFiles, filesToAnalyze.length, fileProgressMessage(cachedFiles + processedFiles, filesToAnalyze.length, results.length));
218
+ },
219
+ batchDone: (files) => {
220
+ filesAnalyzed += files;
221
+ },
222
+ }, { signal: ctx.signal });
223
+ const cancelled = engine.cancelled;
269
224
  console.info(`\nBatch processing complete: ${totalBatches} batch(es), ${filesAnalyzed} total files analyzed, ${results.length} total violations`);
270
225
  // ============================================================================
271
226
  // CACHE WRITE SYSTEM
@@ -285,26 +240,23 @@ export class ScanAngularTool {
285
240
  // - Parsing Angular templates and metadata takes significant time
286
241
  // - Cache hit eliminates all AST parsing and decorator analysis overhead
287
242
  // ============================================================================
288
- const cacheManager = kernel.getCacheManager();
289
- if (cacheManager) {
290
- // Group results by file path
291
- const resultsByFile = new Map();
292
- for (const result of results) {
293
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
294
- const filePath = result.filePath;
295
- if (!resultsByFile.has(filePath)) {
296
- resultsByFile.set(filePath, []);
297
- }
298
- resultsByFile.get(filePath).push(result);
299
- }
300
- // Write each file's results to cache
301
- for (const [filePath, fileResults] of resultsByFile.entries()) {
302
- await cacheManager.setAnalysisResult(filePath, fileResults);
243
+ // Group results by file path
244
+ const resultsByFile = new Map();
245
+ for (const result of results) {
246
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
247
+ const filePath = result.filePath;
248
+ if (!resultsByFile.has(filePath)) {
249
+ resultsByFile.set(filePath, []);
303
250
  }
304
- // Log cache effectiveness
305
- const stats = cacheManager.getStats();
306
- console.info(`Cached ${resultsByFile.size} files (hit rate: ${stats.hitRate.toFixed(1)}%)`);
251
+ resultsByFile.get(filePath).push(result);
307
252
  }
253
+ // Write each file's results to cache
254
+ for (const [filePath, fileResults] of resultsByFile.entries()) {
255
+ await cache.setAnalysisResult(filePath, fileResults);
256
+ }
257
+ // Log cache effectiveness
258
+ const stats = cache.getStats();
259
+ console.info(`Cached ${resultsByFile.size} files (hit rate: ${stats.hitRate.toFixed(1)}%)`);
308
260
  // Filter by specific rules if requested
309
261
  let violations = results
310
262
  .filter((r) => r.ruleId && r.filePath)
@@ -330,15 +282,25 @@ export class ScanAngularTool {
330
282
  const offset = mergedParams.resultOffset ?? 0;
331
283
  const maxResults = mergedParams.maxResults ?? 1000;
332
284
  const paginatedViolations = violations.slice(offset, offset + maxResults);
333
- // Calculate summary
334
- const summary = this.calculateSummary(paginatedViolations, filesToAnalyze.length);
285
+ // Counts cover every violation, not only the page
286
+ const analyzedFiles = cancelled ? cachedFiles + processedFiles : filesToAnalyze.length;
287
+ const counts = this.calculateSummary(violations, analyzedFiles);
288
+ const execution = cancelled
289
+ ? cancelledExecution(analyzedFiles, filesToAnalyze.length - analyzedFiles)
290
+ : undefined;
291
+ const pagination = {
292
+ totalResults: totalViolations,
293
+ returnedResults: paginatedViolations.length,
294
+ offset,
295
+ hasMore: offset + maxResults < totalViolations,
296
+ };
335
297
  const duration = Date.now() - startTime;
336
- const angularRules = allRules.map((r) => r.id);
298
+ const ruleIds = engine.ruleIds;
337
299
  return {
338
300
  violations: paginatedViolations,
339
- summary,
301
+ counts,
340
302
  metadata: {
341
- rulesExecuted: angularRules,
303
+ rulesExecuted: ruleIds,
342
304
  duration,
343
305
  projectRoot: mergedParams.rootPath,
344
306
  },
@@ -353,12 +315,9 @@ export class ScanAngularTool {
353
315
  throughput: filesToAnalyze.length / (duration / 1000),
354
316
  }
355
317
  : undefined,
356
- pagination: {
357
- totalResults: totalViolations,
358
- returnedResults: paginatedViolations.length,
359
- offset,
360
- hasMore: offset + maxResults < totalViolations,
361
- },
318
+ pagination,
319
+ ...(execution === undefined ? {} : { execution }),
320
+ summary: describeScan(counts, paginatedViolations, pagination, execution === undefined ? [] : [execution.note]),
362
321
  };
363
322
  }
364
323
  /**
@@ -1,10 +1,5 @@
1
- /**
2
- * @angular-modernizer/adapter-mcp - Scan Architecture Tool
3
- *
4
- * MCP tool for scanning Angular codebases for architectural issues.
5
- * Runs only the ArchitecturePlugin (17 rules: import cycles, layer violations, god objects, etc.).
6
- */
7
- import type { MCPTool } from '../types.js';
1
+ import type { MCPTool, ToolAnnotations, ToolContext } from '../types.js';
2
+ import { type ScanCounts } from './helpers/analysis-output.js';
8
3
  import { type RuleTiming } from './helpers/rule-runner.js';
9
4
  /**
10
5
  * Scope configuration for targeted scanning.
@@ -33,28 +28,39 @@ interface ScanScope {
33
28
  /**
34
29
  * Resolved scope information returned in results.
35
30
  */
36
- interface ResolvedScope {
31
+ export interface ResolvedScope {
32
+ /** Scope type that was scanned. */
37
33
  type: ScanScope['type'];
34
+ /** Project or feature names from the requested scope. */
38
35
  names?: string[];
36
+ /** Folder paths from the requested scope. */
39
37
  paths?: string[];
38
+ /** Paths the scope resolved to; files below them are scanned. */
40
39
  resolvedPaths: string[];
40
+ /** Number of files in scope that were selected for the scan. */
41
41
  matchedFiles: number;
42
42
  }
43
43
  /**
44
44
  * Run details of a scan.
45
45
  */
46
- interface ScanExecution {
46
+ export interface ScanExecution {
47
+ /** Time budget of the scan in milliseconds; `0` means no budget. */
47
48
  maxDurationMs: number;
49
+ /** `true` when the time budget or a cancellation stopped the scan early. */
48
50
  incomplete: boolean;
51
+ /** Why the scan stopped early. */
49
52
  stopReason?: 'time-budget' | 'cancelled';
53
+ /** Files that were not analyzed because the scan stopped early. */
50
54
  skippedFiles: number;
55
+ /** Time per rule, slowest first. */
51
56
  ruleTimings: RuleTiming[];
57
+ /** Human-readable note on an incomplete scan. */
52
58
  note?: string;
53
59
  }
54
60
  /**
55
61
  * Result from the scan-architecture tool.
56
62
  */
57
- interface ScanArchitectureResult {
63
+ export interface ScanArchitectureResult {
58
64
  /**
59
65
  * Operation ID for streaming mode (when streaming=true).
60
66
  */
@@ -63,33 +69,44 @@ interface ScanArchitectureResult {
63
69
  * All violations found.
64
70
  */
65
71
  violations: {
72
+ /** Violation id built from rule id, file, line and column. */
66
73
  id: string;
74
+ /** Rule that reported the violation, e.g. `solid:circular-dependency`. */
67
75
  ruleId: string;
76
+ /** Severity reported by the rule, else the rule's default severity. */
68
77
  severity: 'error' | 'warning' | 'info';
78
+ /** Rule message. */
69
79
  message: string;
80
+ /** File the violation was reported on. */
70
81
  filePath: string;
82
+ /** 1-based line of the finding, when the rule reports one. */
71
83
  line?: number;
84
+ /** Column of the finding, when the rule reports one. */
72
85
  column?: number;
86
+ /** Category of the rule. */
73
87
  category: string;
88
+ /** Fix suggested by the rule. */
74
89
  suggestedFix?: string;
90
+ /** Rule-specific details. */
75
91
  metadata?: Record<string, unknown>;
76
92
  }[];
77
93
  /**
78
- * Summary statistics.
94
+ * Counts over all violations, independent of the page.
79
95
  */
80
- summary: {
81
- totalViolations: number;
82
- analyzedFiles: number;
83
- bySeverity: Record<string, number>;
84
- byCategory: Record<string, number>;
85
- byRule: Record<string, number>;
86
- };
96
+ counts: ScanCounts;
97
+ /**
98
+ * Human-readable summary for LLM consumption.
99
+ */
100
+ summary: string;
87
101
  /**
88
102
  * Analysis metadata.
89
103
  */
90
104
  metadata: {
105
+ /** Ids of the rules that ran. */
91
106
  rulesExecuted: string[];
107
+ /** Duration of the scan in milliseconds. */
92
108
  duration: number;
109
+ /** Root path of the scanned project. */
93
110
  projectRoot: string;
94
111
  };
95
112
  /**
@@ -101,25 +118,42 @@ interface ScanArchitectureResult {
101
118
  */
102
119
  scope?: ResolvedScope;
103
120
  /**
104
- * Orchestration metrics (Phase 5b/6d/7b).
121
+ * Orchestration metrics; set when `orchestration.parallel` or
122
+ * `orchestration.incremental` is set.
105
123
  */
106
124
  orchestration?: {
125
+ /** Value of `orchestration.parallel`. */
107
126
  parallel: boolean;
127
+ /** Value of `orchestration.incremental`. */
108
128
  incremental: boolean;
129
+ /** Value of `orchestration.useWorkerThreads`. */
109
130
  useWorkerThreads?: boolean;
131
+ /** Value of `orchestration.autoSelectMode`. */
110
132
  autoSelectMode?: boolean;
133
+ /** Files analyzed. */
111
134
  filesAnalyzed: number;
135
+ /** Files skipped by incremental analysis. */
112
136
  filesSkipped: number;
137
+ /** Cache hit rate of incremental analysis. */
113
138
  cacheHitRate: number;
139
+ /** Duration of the scan in milliseconds. */
114
140
  duration: number;
141
+ /** Files per second. */
115
142
  throughput: number;
143
+ /** Parallel execution figures of the kernel. */
116
144
  workerStats?: {
145
+ /** Completed tasks. */
117
146
  completedTasks: number;
147
+ /** Average task duration in milliseconds. */
118
148
  averageTaskDuration: number;
149
+ /** Summed CPU time of all tasks. */
119
150
  totalCpuTime: number;
120
151
  };
152
+ /** Resource limits from `orchestration.resourceLimits`. */
121
153
  resourceUsage?: {
154
+ /** Maximum number of workers. */
122
155
  maxWorkers?: number;
156
+ /** Memory limit. */
123
157
  maxMemory?: number;
124
158
  };
125
159
  };
@@ -127,19 +161,28 @@ interface ScanArchitectureResult {
127
161
  * Pagination metadata (when pagination is used).
128
162
  */
129
163
  pagination?: {
164
+ /** Number of all violations. */
130
165
  totalResults: number;
166
+ /** Number of violations in this page. */
131
167
  returnedResults: number;
168
+ /** Offset of the page (`resultOffset`). */
132
169
  offset: number;
170
+ /** Whether violations follow after this page. */
133
171
  hasMore: boolean;
134
172
  };
135
173
  /**
136
174
  * Progress state (if enableProgress was true).
137
175
  */
138
176
  progress?: {
177
+ /** Processed items. */
139
178
  current: number;
179
+ /** Items in total. */
140
180
  total: number;
181
+ /** Progress in percent. */
141
182
  percentage: number;
183
+ /** Estimated remaining time; 0 when unknown. */
142
184
  eta: number;
185
+ /** Progress event type of the kernel's progress reporter. */
143
186
  phase: string;
144
187
  };
145
188
  /**
@@ -151,23 +194,33 @@ interface ScanArchitectureResult {
151
194
  * Intermediate results from each pipeline stage (fluent API only).
152
195
  */
153
196
  intermediateResults?: Record<string, {
197
+ /** Whether the stage succeeded. */
154
198
  success: boolean;
199
+ /** Violations found by the stage. */
155
200
  violations?: number;
201
+ /** Files processed by the stage. */
156
202
  filesProcessed?: number;
203
+ /** Stage message. */
157
204
  message?: string;
158
205
  }>;
159
206
  }
160
207
  /**
161
- * Scan Architecture Tool
162
- *
163
- * Provides architectural analysis capabilities through MCP with the rules of
164
- * the ArchitecturePlugin.
208
+ * MCP tool `scan-architecture`: scans for architectural issues. Runs only the
209
+ * ArchitecturePlugin (17 rules: import cycles, layer violations, god objects
210
+ * and others).
165
211
  */
166
212
  export declare class ScanArchitectureTool implements MCPTool {
167
213
  readonly name = "scan-architecture";
214
+ readonly title = "Scan Architecture";
215
+ readonly annotations: ToolAnnotations;
168
216
  readonly description: string;
217
+ /**
218
+ * JSON Schema of the tool arguments.
219
+ * @hidden
220
+ */
169
221
  readonly inputSchema: {
170
222
  type: string;
223
+ additionalProperties: boolean;
171
224
  properties: {
172
225
  rootPath: {
173
226
  type: string;
@@ -331,7 +384,22 @@ export declare class ScanArchitectureTool implements MCPTool {
331
384
  };
332
385
  required: string[];
333
386
  };
334
- execute(args: Record<string, unknown>): Promise<ScanArchitectureResult>;
387
+ /**
388
+ * JSON Schema of the tool result (`structuredContent`).
389
+ * @hidden
390
+ */
391
+ readonly outputSchema: {
392
+ type: "object";
393
+ properties: Record<string, unknown>;
394
+ required: string[];
395
+ };
396
+ execute(args: Record<string, unknown>, ctx?: ToolContext): Promise<ScanArchitectureResult>;
397
+ /**
398
+ * Runs the rules through the scan engine (in a scan worker when enabled)
399
+ * and appends each file's findings to `violations`. A worker terminated by
400
+ * a cancel leaves no run summary; it is rebuilt from the files received.
401
+ */
402
+ private runRules;
335
403
  /**
336
404
  * Execute analysis using fluent API.
337
405
  */