@angular-modernizer/adapter-mcp 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/README.md +81 -65
  2. package/dist/cli.js +8 -0
  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 +118 -3
  6. package/dist/index.js +46 -3
  7. package/dist/mcp-watcher.d.ts +28 -8
  8. package/dist/mcp-watcher.js +7 -7
  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 +7 -0
  16. package/dist/server/mcp-server.d.ts +11 -7
  17. package/dist/server/mcp-server.js +4 -7
  18. package/dist/server/sdk-server.d.ts +1 -0
  19. package/dist/server/tool-registry.d.ts +3 -7
  20. package/dist/server/tool-registry.js +1 -7
  21. package/dist/streaming/progress-store.d.ts +22 -5
  22. package/dist/streaming/progress-store.js +9 -5
  23. package/dist/tools/analyze-build-impact.d.ts +58 -36
  24. package/dist/tools/analyze-build-impact.js +36 -29
  25. package/dist/tools/analyze-core-to-shared.d.ts +42 -12
  26. package/dist/tools/analyze-core-to-shared.js +11 -10
  27. package/dist/tools/analyze-parser-performance.d.ts +23 -22
  28. package/dist/tools/analyze-parser-performance.js +20 -18
  29. package/dist/tools/analyze-project.d.ts +87 -14
  30. package/dist/tools/analyze-project.js +140 -122
  31. package/dist/tools/check-incremental-compatibility.d.ts +13 -11
  32. package/dist/tools/check-incremental-compatibility.js +11 -8
  33. package/dist/tools/collect-feedback.d.ts +41 -26
  34. package/dist/tools/collect-feedback.js +32 -23
  35. package/dist/tools/compare-health.d.ts +76 -19
  36. package/dist/tools/compare-health.js +26 -19
  37. package/dist/tools/extract-libraries.d.ts +44 -20
  38. package/dist/tools/extract-libraries.js +16 -17
  39. package/dist/tools/find-angular-symbol.d.ts +27 -25
  40. package/dist/tools/find-angular-symbol.js +19 -16
  41. package/dist/tools/find-component-hosts.d.ts +33 -27
  42. package/dist/tools/find-component-hosts.js +27 -24
  43. package/dist/tools/find-usages.d.ts +25 -23
  44. package/dist/tools/find-usages.js +21 -18
  45. package/dist/tools/get-bootstrap-execution.d.ts +35 -27
  46. package/dist/tools/get-bootstrap-execution.js +28 -25
  47. package/dist/tools/get-call-graph.d.ts +19 -14
  48. package/dist/tools/get-call-graph.js +26 -23
  49. package/dist/tools/get-operation-progress-tool.d.ts +12 -6
  50. package/dist/tools/get-operation-progress-tool.js +11 -6
  51. package/dist/tools/get-operation-progress.d.ts +26 -0
  52. package/dist/tools/helpers/analysis-output.d.ts +5 -0
  53. package/dist/tools/helpers/batch-kernel.d.ts +14 -0
  54. package/dist/tools/helpers/batch-kernel.js +12 -0
  55. package/dist/tools/helpers/compact-output.d.ts +2 -1
  56. package/dist/tools/helpers/compact-output.js +2 -1
  57. package/dist/tools/helpers/health-delta.d.ts +27 -14
  58. package/dist/tools/helpers/health-delta.js +11 -14
  59. package/dist/tools/helpers/project-cache.d.ts +123 -36
  60. package/dist/tools/helpers/project-cache.js +227 -43
  61. package/dist/tools/helpers/rule-runner.d.ts +23 -16
  62. package/dist/tools/helpers/rule-runner.js +24 -17
  63. package/dist/tools/helpers/scan-engine.d.ts +107 -0
  64. package/dist/tools/helpers/scan-engine.js +197 -0
  65. package/dist/tools/helpers/scan-plan.d.ts +1 -1
  66. package/dist/tools/helpers/scan-plan.js +1 -1
  67. package/dist/tools/helpers/suggestion-generator.d.ts +9 -13
  68. package/dist/tools/helpers/suggestion-generator.js +0 -12
  69. package/dist/tools/helpers/tool-cache.d.ts +11 -0
  70. package/dist/tools/helpers/tool-cache.js +15 -0
  71. package/dist/tools/helpers/tool-context.d.ts +11 -8
  72. package/dist/tools/helpers/tool-context.js +5 -8
  73. package/dist/tools/inspect-form-group.d.ts +34 -27
  74. package/dist/tools/inspect-form-group.js +27 -24
  75. package/dist/tools/inspect-i18n.d.ts +31 -25
  76. package/dist/tools/inspect-i18n.js +23 -20
  77. package/dist/tools/inspect-template.d.ts +32 -25
  78. package/dist/tools/inspect-template.js +26 -23
  79. package/dist/tools/learn-patterns.d.ts +88 -12
  80. package/dist/tools/learn-patterns.js +17 -11
  81. package/dist/tools/list-imports.d.ts +45 -28
  82. package/dist/tools/list-imports.js +26 -23
  83. package/dist/tools/orchestrate-migration.d.ts +31 -9
  84. package/dist/tools/orchestrate-migration.js +12 -7
  85. package/dist/tools/parse-stack-trace.d.ts +23 -21
  86. package/dist/tools/parse-stack-trace.js +10 -7
  87. package/dist/tools/plan-migration.d.ts +67 -27
  88. package/dist/tools/plan-migration.js +22 -21
  89. package/dist/tools/resolve-type.d.ts +20 -10
  90. package/dist/tools/resolve-type.js +21 -13
  91. package/dist/tools/review-feedback.d.ts +27 -24
  92. package/dist/tools/review-feedback.js +24 -20
  93. package/dist/tools/rollback-changes.d.ts +13 -9
  94. package/dist/tools/rollback-changes.js +10 -7
  95. package/dist/tools/run-angular-cli.d.ts +12 -10
  96. package/dist/tools/run-angular-cli.js +11 -8
  97. package/dist/tools/run-build.d.ts +13 -11
  98. package/dist/tools/run-build.js +11 -8
  99. package/dist/tools/run-schematic.d.ts +12 -10
  100. package/dist/tools/run-schematic.js +11 -8
  101. package/dist/tools/scan-all.d.ts +69 -12
  102. package/dist/tools/scan-all.js +55 -122
  103. package/dist/tools/scan-angular.d.ts +41 -9
  104. package/dist/tools/scan-angular.js +66 -135
  105. package/dist/tools/scan-architecture.d.ts +75 -14
  106. package/dist/tools/scan-architecture.js +180 -185
  107. package/dist/tools/scan-solid.d.ts +40 -9
  108. package/dist/tools/scan-solid.js +64 -133
  109. package/dist/tools/search-codebase.d.ts +32 -26
  110. package/dist/tools/search-codebase.js +15 -12
  111. package/dist/tools/server-status.d.ts +116 -24
  112. package/dist/tools/server-status.js +85 -26
  113. package/dist/tools/suggest-improvements.d.ts +22 -19
  114. package/dist/tools/suggest-improvements.js +21 -17
  115. package/dist/tools/trace-output-flow.d.ts +34 -27
  116. package/dist/tools/trace-output-flow.js +27 -24
  117. package/dist/tools/transform-code.d.ts +71 -10
  118. package/dist/tools/transform-code.js +148 -54
  119. package/dist/tools/validate-before-transform.d.ts +24 -9
  120. package/dist/tools/validate-before-transform.js +10 -7
  121. package/dist/tools/validate-project-compatibility.d.ts +18 -13
  122. package/dist/tools/validate-project-compatibility.js +17 -11
  123. package/dist/tools/validate-transformation.d.ts +28 -11
  124. package/dist/tools/validate-transformation.js +14 -8
  125. package/dist/tools/verify-citations.d.ts +37 -16
  126. package/dist/tools/verify-citations.js +19 -16
  127. package/dist/types.d.ts +40 -10
  128. package/dist/types.js +0 -5
  129. package/package.json +12 -18
  130. package/dist/tools/shared/scan-types.d.ts +0 -200
  131. package/dist/tools/shared/scan-types.js +0 -7
@@ -1,26 +1,29 @@
1
- /**
2
- * @angular-modernizer/adapter-mcp - Comprehensive Scan Tool
3
- *
4
- * MCP tool for comprehensive scanning with all plugins:
5
- * - SolidPlugin (7 rules): SOLID principles
6
- * - AngularPlugin (28 rules): Angular best practices
7
- * - ArchitecturePlugin (17 rules): Architectural issues
8
- * Total: 52 rules
9
- */
10
1
  import type { MCPTool, ToolAnnotations, ToolContext } from '../types.js';
11
2
  import { type CancelledExecution } from './helpers/tool-context.js';
12
3
  import { type ScanCounts } from './helpers/analysis-output.js';
13
- interface ScanAllResult {
4
+ /** Result of the scan-all tool. */
5
+ export interface ScanAllResult {
6
+ /** The requested page of violations (`maxResults`, `resultOffset`). */
14
7
  violations: {
8
+ /** Position-based id of the violation in the full result (`all-<index>`). */
15
9
  id: string;
10
+ /** Rule that reported the violation, e.g. `solid:circular-dependency`. */
16
11
  ruleId: string;
12
+ /** Severity reported by the rule. */
17
13
  severity: 'error' | 'warning' | 'info';
14
+ /** Rule message. */
18
15
  message: string;
16
+ /** File path relative to `rootPath`. */
19
17
  filePath: string;
18
+ /** 1-based line of the finding, when the rule reports one. */
20
19
  line?: number;
20
+ /** Column of the finding, when the rule reports one. */
21
21
  column?: number;
22
+ /** Rule category; `General` when the rule sets none. */
22
23
  category: string;
24
+ /** Fix suggested by the rule; only with `includeAutoFixes`. */
23
25
  suggestedFix?: string;
26
+ /** Rule-specific details. */
24
27
  metadata?: Record<string, unknown>;
25
28
  }[];
26
29
  /** Counts over all violations, independent of the page. */
@@ -29,60 +32,111 @@ interface ScanAllResult {
29
32
  summary: string;
30
33
  /** Set when the client cancelled the scan; counts cover the analyzed files. */
31
34
  execution?: CancelledExecution;
35
+ /** Scan metadata. */
32
36
  metadata: {
37
+ /** Ids of the rules that ran. */
33
38
  rulesExecuted: string[];
39
+ /** Duration of the scan in milliseconds. */
34
40
  duration: number;
41
+ /** Root path of the scanned project. */
35
42
  projectRoot: string;
43
+ /** Cache figures of this run; same values as {@link ScanAllResult.cache}. */
36
44
  cacheStats?: {
45
+ /** Files selected for the scan. */
37
46
  totalFilesChecked: number;
47
+ /** Files whose findings came from the cache. */
38
48
  filesFromCache: number;
49
+ /** Files analyzed in this run. */
39
50
  filesToProcess: number;
51
+ /** Hit rate of the scan-all cache in percent. */
40
52
  hitRate: number;
53
+ /** Cache hits per cache source. */
41
54
  hitsBySource: Record<string, number>;
42
55
  };
43
56
  };
57
+ /**
58
+ * Cache figures of this run. scan-all reads and writes only its own cache
59
+ * (`.angular-modernizer-cache/all/`); `hitRate` and `hitsBySource` refer to it.
60
+ */
44
61
  cache?: {
62
+ /** Files selected for the scan. */
45
63
  totalFilesChecked: number;
64
+ /** Files whose findings came from the cache. */
46
65
  filesFromCache: number;
66
+ /** Files analyzed in this run. */
47
67
  filesToProcess: number;
68
+ /** Hit rate of the scan-all cache in percent. */
48
69
  hitRate: number;
70
+ /** Cache hits per cache source. */
49
71
  hitsBySource: Record<string, number>;
72
+ /** Statistics of the cache manager. */
50
73
  stats: {
74
+ /** Entries in the cache. */
51
75
  totalEntries: number;
76
+ /** Size of the cache in bytes. */
52
77
  totalSize: number;
78
+ /** Cache hits. */
53
79
  hits: number;
80
+ /** Cache misses. */
54
81
  misses: number;
82
+ /** Hit rate in percent. */
55
83
  hitRate: number;
84
+ /** Entries per entry type. */
56
85
  entriesByType: {
86
+ /** AST entries. */
57
87
  ast: number;
88
+ /** Analysis result entries. */
58
89
  analysis: number;
59
90
  };
60
91
  };
61
92
  };
93
+ /** Orchestration figures; set only when `orchestration.useWorkerThreads` is set. */
62
94
  orchestration?: {
95
+ /** Whether the scan ran in parallel. */
63
96
  parallel: boolean;
97
+ /** Whether only changed files were analyzed (always `false` here). */
64
98
  incremental: boolean;
99
+ /** Files selected for the scan. */
65
100
  filesAnalyzed: number;
101
+ /** Files skipped (always 0 here). */
66
102
  filesSkipped: number;
103
+ /** Hit rate of the cache in percent. */
67
104
  cacheHitRate: number;
105
+ /** Duration of the scan in milliseconds. */
68
106
  duration: number;
107
+ /** Files per second. */
69
108
  throughput: number;
70
109
  };
110
+ /** What the page covers of all violations. */
71
111
  pagination?: {
112
+ /** Number of all violations. */
72
113
  totalResults: number;
114
+ /** Number of violations in this page. */
73
115
  returnedResults: number;
116
+ /** Offset of the page (`resultOffset`). */
74
117
  offset: number;
118
+ /** Whether violations follow after this page. */
75
119
  hasMore: boolean;
76
120
  };
77
121
  }
78
122
  /**
79
- * Comprehensive scan with all available plugins (52 rules total).
123
+ * MCP tool `scan-all`: one scan with all analysis plugins (52 rules total).
124
+ *
125
+ * @remarks
126
+ * Plugins and rules:
127
+ * - SolidPlugin (7 rules): SOLID principles
128
+ * - AngularPlugin (28 rules): Angular best practices
129
+ * - ArchitecturePlugin (17 rules): architectural issues
80
130
  */
81
131
  export declare class ScanAllTool implements MCPTool {
82
132
  readonly name = "scan-all";
83
133
  readonly title = "Scan All Rules";
84
134
  readonly annotations: ToolAnnotations;
85
135
  readonly description: string;
136
+ /**
137
+ * JSON Schema of the tool arguments.
138
+ * @hidden
139
+ */
86
140
  readonly inputSchema: {
87
141
  type: string;
88
142
  additionalProperties: boolean;
@@ -152,6 +206,10 @@ export declare class ScanAllTool implements MCPTool {
152
206
  };
153
207
  required: string[];
154
208
  };
209
+ /**
210
+ * JSON Schema of the tool result (`structuredContent`).
211
+ * @hidden
212
+ */
155
213
  readonly outputSchema: {
156
214
  type: "object";
157
215
  properties: Record<string, unknown>;
@@ -164,5 +222,4 @@ export declare class ScanAllTool implements MCPTool {
164
222
  */
165
223
  private loadConfig;
166
224
  }
167
- export {};
168
225
  //# sourceMappingURL=scan-all.d.ts.map
@@ -1,28 +1,13 @@
1
- /**
2
- * @angular-modernizer/adapter-mcp - Comprehensive Scan Tool
3
- *
4
- * MCP tool for comprehensive scanning with all plugins:
5
- * - SolidPlugin (7 rules): SOLID principles
6
- * - AngularPlugin (28 rules): Angular best practices
7
- * - ArchitecturePlugin (17 rules): Architectural issues
8
- * Total: 52 rules
9
- */
10
- /* eslint-disable @typescript-eslint/no-unsafe-assignment */
11
1
  import { findTsConfig } from './helpers/find-ts-config.js';
12
- import { Kernel, MultiCacheFallbackManager, RealFileSystemAdapter, createToolCacheConfig, createMultiCacheConfig, loadConfig, } from '@angular-modernizer/core';
13
- import { SolidPlugin } from '@angular-modernizer/plugin-solid';
14
- import { AngularPlugin } from '@angular-modernizer/plugin-angular';
15
- import { ArchitecturePlugin } from '@angular-modernizer/plugin-architecture';
16
- import { ContextFactory } from '@angular-modernizer/plugin-system';
17
- import { createPublicApi } from '@angular-modernizer/api';
2
+ import { MultiCacheFallbackManager, RealFileSystemAdapter, createMultiCacheConfig, loadConfig, } from '@angular-modernizer/core';
18
3
  import { glob } from 'glob';
19
4
  import { relative } from 'node:path';
20
- import { existsSync, statSync } from 'node:fs';
5
+ import { statSync } from 'node:fs';
21
6
  import { FindingWindow } from './helpers/finding-window.js';
22
- import { cancelledExecution, fileProgressMessage, yieldIfCancellable, } from './helpers/tool-context.js';
23
- import { loadSourceFiles } from './helpers/load-source-files.js';
7
+ import { cancelledExecution, fileProgressMessage, } from './helpers/tool-context.js';
8
+ import { runScan } from '../scan-host/scan-host.js';
24
9
  import { describeScan, SCAN_EXECUTION_SCHEMA, scanOutputSchema, } from './helpers/analysis-output.js';
25
- import { dependenciesUnchanged, templateDependencies, } from './helpers/scan-cache.js';
10
+ import { dependenciesUnchanged } from './helpers/scan-cache.js';
26
11
  /**
27
12
  * Version of the cache entries scan-all writes. Entries from before the
28
13
  * per-analyzed-file layout (findings filed under their template, files without
@@ -30,7 +15,13 @@ import { dependenciesUnchanged, templateDependencies, } from './helpers/scan-cac
30
15
  */
31
16
  const SCAN_ALL_CACHE_VERSION = 'scan-all-2';
32
17
  /**
33
- * Comprehensive scan with all available plugins (52 rules total).
18
+ * MCP tool `scan-all`: one scan with all analysis plugins (52 rules total).
19
+ *
20
+ * @remarks
21
+ * Plugins and rules:
22
+ * - SolidPlugin (7 rules): SOLID principles
23
+ * - AngularPlugin (28 rules): Angular best practices
24
+ * - ArchitecturePlugin (17 rules): architectural issues
34
25
  */
35
26
  export class ScanAllTool {
36
27
  name = 'scan-all';
@@ -43,6 +34,10 @@ export class ScanAllTool {
43
34
  };
44
35
  description = 'Comprehensive code quality scan with all plugins (SOLID 7, Angular 28, Architecture 17: 52 rules total). ' +
45
36
  'maxResults (default 1000) and resultOffset page the violations; counts cover all of them, summary is a short text.';
37
+ /**
38
+ * JSON Schema of the tool arguments.
39
+ * @hidden
40
+ */
46
41
  inputSchema = {
47
42
  type: 'object',
48
43
  additionalProperties: false,
@@ -115,6 +110,10 @@ export class ScanAllTool {
115
110
  },
116
111
  required: ['rootPath'],
117
112
  };
113
+ /**
114
+ * JSON Schema of the tool result (`structuredContent`).
115
+ * @hidden
116
+ */
118
117
  outputSchema = scanOutputSchema({
119
118
  cache: { type: 'object' },
120
119
  execution: SCAN_EXECUTION_SCHEMA,
@@ -132,21 +131,6 @@ export class ScanAllTool {
132
131
  if (!tsConfigPath) {
133
132
  throw new Error('Could not find tsconfig.json');
134
133
  }
135
- // Initialize kernel with all plugins and caching
136
- // IMPORTANT: skipAddingFilesFromTsConfig prevents loading dist/, e2e/, etc.
137
- const kernel = new Kernel({
138
- tsConfigPath,
139
- plugins: [
140
- new SolidPlugin(),
141
- new AngularPlugin(),
142
- new ArchitecturePlugin(),
143
- ],
144
- fileSystem: undefined,
145
- projectOptions: {
146
- skipAddingFilesFromTsConfig: true, // We'll add filtered files manually
147
- },
148
- cacheConfig: createToolCacheConfig(mergedParams.rootPath, 'all'),
149
- });
150
134
  // Find files to analyze
151
135
  const includePatterns = mergedParams.includePatterns ?? ['**/*.{ts,tsx}'];
152
136
  const excludePatterns = mergedParams.excludePatterns ?? [
@@ -174,13 +158,6 @@ export class ScanAllTool {
174
158
  const uniqueFiles = Array.from(new Set(allFiles)).sort();
175
159
  const filesToAnalyze = uniqueFiles; // Analyze ALL files found (batch processing prevents memory issues)
176
160
  const maxFiles = mergedParams.maxFiles ?? 100; // Batch size (default 100)
177
- // Initialize kernel
178
- await kernel.initialize();
179
- // Reuse the already-initialized plugin instances from the kernel so that
180
- // ruleConfigs loaded from .angular-modernizer.json are applied correctly.
181
- const allRules = kernel
182
- .getAllPlugins()
183
- .flatMap((p) => p.getAnalysisRules());
184
161
  // ============================================================================
185
162
  // CACHE READ
186
163
  // ============================================================================
@@ -195,9 +172,6 @@ export class ScanAllTool {
195
172
  version: SCAN_ALL_CACHE_VERSION,
196
173
  });
197
174
  await multiCacheManager.initialize();
198
- // Load rules config from .angular-modernizer.json for per-rule overrides (BUG-3)
199
- const fullConfig = loadConfig(mergedParams.rootPath);
200
- const rulesConfig = fullConfig.rules;
201
175
  const cachedResults = []; // eslint-disable-line @typescript-eslint/no-explicit-any
202
176
  const filesToProcess = [];
203
177
  const cacheHitsBySource = {};
@@ -257,84 +231,44 @@ export class ScanAllTool {
257
231
  window.add(cached);
258
232
  }
259
233
  let filesAnalyzed = cachedResults.length;
260
- let cancelled = false;
261
234
  const progressTotal = cachedResults.length + totalFiles;
262
- // Process each batch; cancellation is checked between files
263
- for (let batchNum = 0; batchNum < totalBatches && !cancelled; batchNum++) {
264
- const batchStart = batchNum * batchSize;
265
- const batchEnd = Math.min(batchStart + batchSize, totalFiles);
266
- const batchFiles = filesToProcess.slice(batchStart, batchEnd);
267
- console.info(`\nBatch ${batchNum + 1}/${totalBatches}: Processing files ${batchStart + 1}-${batchEnd} (${batchFiles.length} files)`);
268
- // Clear project and add batch files
269
- const project = kernel.getProject();
270
- // Remove all source files from previous batch
271
- const existingFiles = project.getSourceFiles();
272
- for (const file of existingFiles) {
273
- project.removeSourceFile(file);
274
- }
275
- // Add current batch files, keeping their sorted order: findings must
276
- // come out in the order a warm run reads them from the cache, or pages
277
- // computed cold and warm overlap. A cancel during the load stops the scan.
278
- const loaded = await loadSourceFiles(project, batchFiles, { signal: ctx.signal });
279
- if (loaded.cancelled) {
280
- cancelled = true;
281
- break;
282
- }
283
- const batchSourceFiles = loaded.sourceFiles;
284
- console.info(`Batch ${batchNum + 1}: Project now has ${project.getSourceFiles().length} source files`);
285
- // Create PublicApi for this batch
286
- const api = createPublicApi(project); // eslint-disable-line @typescript-eslint/no-explicit-any
287
- // Analyze files in this batch
288
- let batchViolationCount = 0;
289
- let batchFilesAnalyzed = 0;
290
- for (const sourceFile of batchSourceFiles) {
291
- await yieldIfCancellable(ctx.signal);
292
- if (ctx.signal?.aborted === true) {
293
- cancelled = true;
294
- break;
295
- }
296
- const fileResults = [];
297
- for (const rule of allRules) {
298
- try {
299
- const ruleResults = await rule.analyze(ContextFactory.createAnalysisContext({
300
- sourceFile,
301
- project,
302
- api,
303
- config: rulesConfig,
304
- }));
305
- for (const result of ruleResults) {
306
- const entry = {
307
- ruleId: result.ruleId,
308
- severity: result.severity ?? rule.severity,
309
- message: result.message,
310
- filePath: result.filePath,
311
- line: result.line,
312
- column: result.column,
313
- category: rule.category,
314
- suggestedFix: result.suggestedFix,
315
- metadata: result.metadata,
316
- };
317
- // Always accumulate for cache writes.
318
- fileResults.push(entry);
319
- window.add(entry);
320
- batchViolationCount++;
321
- }
322
- }
323
- catch (error) {
324
- console.warn(`Failed to analyze with rule ${rule.id}:`, error);
325
- }
326
- }
327
- const sourcePath = sourceFile.getFilePath();
328
- entriesForCache.set(sourcePath, {
329
- results: fileResults,
330
- dependencies: templateDependencies(sourcePath, sourceFile.getFullText(), fileResults.map((r) => r.filePath), existsSync),
235
+ // Kernel, batches and rules run in a scan worker (scan-host), so the
236
+ // server keeps reading stdin while the type checker is built. Files that
237
+ // failed to load count as analyzed once their batch is done, as before.
238
+ let batchFilesAnalyzed = 0;
239
+ if (totalFiles > 0) {
240
+ ctx.progress?.(filesAnalyzed, progressTotal, `loading project, ${totalFiles} files to analyze`);
241
+ }
242
+ const engine = await runScan({
243
+ tool: this.name,
244
+ plugins: 'all',
245
+ tsConfigPath,
246
+ rootPath: mergedParams.rootPath,
247
+ files: filesToProcess,
248
+ mode: 'batches',
249
+ batchSize,
250
+ templateDependencies: true,
251
+ }, {
252
+ file: (event) => {
253
+ // Always accumulate for cache writes, also files without findings
254
+ entriesForCache.set(event.filePath, {
255
+ results: event.findings,
256
+ dependencies: event.dependencies ?? [],
331
257
  });
258
+ for (const finding of event.findings) {
259
+ window.add(finding);
260
+ }
332
261
  batchFilesAnalyzed++;
333
262
  ctx.progress?.(filesAnalyzed + batchFilesAnalyzed, progressTotal, fileProgressMessage(filesAnalyzed + batchFilesAnalyzed, progressTotal, window.getTotals().totalViolations));
334
- }
335
- // Files that failed to load count as analyzed, as before
336
- filesAnalyzed += cancelled ? batchFilesAnalyzed : batchFiles.length;
337
- console.info(`Batch ${batchNum + 1}: Found ${batchViolationCount} violations in ${batchFiles.length} files`);
263
+ },
264
+ batchDone: (files) => {
265
+ filesAnalyzed += files;
266
+ batchFilesAnalyzed = 0;
267
+ },
268
+ }, { signal: ctx.signal });
269
+ const cancelled = engine.cancelled;
270
+ if (cancelled) {
271
+ filesAnalyzed += batchFilesAnalyzed;
338
272
  }
339
273
  console.info(`\nBatch processing complete: ${totalBatches} batch(es), ${filesAnalyzed} total files analyzed, ${window.getTotals().totalViolations} total violations`);
340
274
  // ============================================================================
@@ -403,8 +337,7 @@ export class ScanAllTool {
403
337
  hasMore: window.hasMore(),
404
338
  };
405
339
  const duration = Date.now() - startTime;
406
- // Get all rule IDs from the rules we executed
407
- const allRuleIds = allRules.map((r) => r.id);
340
+ const allRuleIds = engine.ruleIds;
408
341
  // Get final cache statistics (Phase 3)
409
342
  const finalStats = multiCacheManager.getStats();
410
343
  return {
@@ -1,23 +1,29 @@
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 type { MCPTool, ToolAnnotations, ToolContext } from '../types.js';
8
2
  import { type ScanCounts } from './helpers/analysis-output.js';
9
3
  import { type CancelledExecution } from './helpers/tool-context.js';
10
- interface ScanAngularResult {
4
+ /** Result of the scan-angular tool. */
5
+ export interface ScanAngularResult {
6
+ /** The requested page of violations (`maxResults`, `resultOffset`). */
11
7
  violations: {
8
+ /** Index-based id of the violation (`angular-<index>`). */
12
9
  id: string;
10
+ /** Rule that reported the violation. */
13
11
  ruleId: string;
12
+ /** Severity reported by the rule. */
14
13
  severity: 'error' | 'warning' | 'info';
14
+ /** Rule message. */
15
15
  message: string;
16
+ /** File path relative to `rootPath`. */
16
17
  filePath: string;
18
+ /** 1-based line of the finding, when the rule reports one. */
17
19
  line?: number;
20
+ /** Column of the finding, when the rule reports one. */
18
21
  column?: number;
22
+ /** Rule category; `Angular` when the rule sets none. */
19
23
  category: string;
24
+ /** Fix suggested by the rule; only with `includeAutoFixes`. */
20
25
  suggestedFix?: string;
26
+ /** Rule-specific details. */
21
27
  metadata?: Record<string, unknown>;
22
28
  }[];
23
29
  /** Counts over all violations, independent of the page. */
@@ -26,35 +32,58 @@ interface ScanAngularResult {
26
32
  summary: string;
27
33
  /** Set when the client cancelled the scan; counts cover the analyzed files. */
28
34
  execution?: CancelledExecution;
35
+ /** Scan metadata. */
29
36
  metadata: {
37
+ /** Ids of the rules that ran. */
30
38
  rulesExecuted: string[];
39
+ /** Duration of the scan in milliseconds. */
31
40
  duration: number;
41
+ /** Root path of the scanned project. */
32
42
  projectRoot: string;
33
43
  };
44
+ /** Orchestration figures; set only when `orchestration.useWorkerThreads` is set. */
34
45
  orchestration?: {
46
+ /** Whether the scan ran in parallel. */
35
47
  parallel: boolean;
48
+ /** Whether only changed files were analyzed (always `false` here). */
36
49
  incremental: boolean;
50
+ /** Files selected for the scan. */
37
51
  filesAnalyzed: number;
52
+ /** Files skipped (always 0 here). */
38
53
  filesSkipped: number;
54
+ /** Cache hit rate (always 0 here). */
39
55
  cacheHitRate: number;
56
+ /** Duration of the scan in milliseconds. */
40
57
  duration: number;
58
+ /** Files per second. */
41
59
  throughput: number;
42
60
  };
61
+ /** What the page covers of all violations. */
43
62
  pagination?: {
63
+ /** Number of all violations. */
44
64
  totalResults: number;
65
+ /** Number of violations in this page. */
45
66
  returnedResults: number;
67
+ /** Offset of the page (`resultOffset`). */
46
68
  offset: number;
69
+ /** Whether violations follow after this page. */
47
70
  hasMore: boolean;
48
71
  };
49
72
  }
50
73
  /**
51
- * Scan for Angular best practice violations using the AngularPlugin.
74
+ * MCP tool `scan-angular`: scans for Angular-specific best practice
75
+ * violations. Runs only the AngularPlugin (28 rules: OnPush, TrackBy,
76
+ * performance, RxJS and others).
52
77
  */
53
78
  export declare class ScanAngularTool implements MCPTool {
54
79
  readonly name = "scan-angular";
55
80
  readonly title = "Scan Angular Patterns";
56
81
  readonly annotations: ToolAnnotations;
57
82
  readonly description: string;
83
+ /**
84
+ * JSON Schema of the tool arguments.
85
+ * @hidden
86
+ */
58
87
  readonly inputSchema: {
59
88
  type: string;
60
89
  additionalProperties: boolean;
@@ -124,6 +153,10 @@ export declare class ScanAngularTool implements MCPTool {
124
153
  };
125
154
  required: string[];
126
155
  };
156
+ /**
157
+ * JSON Schema of the tool result (`structuredContent`).
158
+ * @hidden
159
+ */
127
160
  readonly outputSchema: {
128
161
  type: "object";
129
162
  properties: Record<string, unknown>;
@@ -137,5 +170,4 @@ export declare class ScanAngularTool implements MCPTool {
137
170
  private loadConfig;
138
171
  private calculateSummary;
139
172
  }
140
- export {};
141
173
  //# sourceMappingURL=scan-angular.d.ts.map