@angular-modernizer/adapter-mcp 1.2.0 → 2.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.
- package/CHANGELOG.md +688 -0
- package/README.md +84 -445
- package/dist/cli.js +9 -1
- package/dist/core/project-analyzer.js +2 -2
- package/dist/index.d.ts +10 -0
- package/dist/index.js +1 -0
- package/dist/scan-host/scan-host.d.ts +7 -0
- package/dist/scan-host/scan-host.js +73 -10
- package/dist/scan-host/scan-protocol.d.ts +2 -0
- package/dist/scan-host/scan-worker.js +14 -8
- package/dist/server/limited-stdio-transport.d.ts +6 -3
- package/dist/server/limited-stdio-transport.js +26 -9
- package/dist/server/mcp-server.js +1 -1
- package/dist/server/sdk-server.d.ts +14 -3
- package/dist/server/sdk-server.js +54 -6
- package/dist/server/tool-registry.d.ts +3 -1
- package/dist/server/tool-registry.js +8 -3
- package/dist/streaming/progress-store.d.ts +19 -7
- package/dist/streaming/progress-store.js +19 -8
- package/dist/tools/analyze-build-impact.d.ts +7 -4
- package/dist/tools/analyze-build-impact.js +8 -3
- package/dist/tools/analyze-core-to-shared.d.ts +10 -6
- package/dist/tools/analyze-core-to-shared.js +63 -60
- package/dist/tools/analyze-parser-performance.d.ts +57 -13
- package/dist/tools/analyze-parser-performance.js +67 -6
- package/dist/tools/analyze-project.d.ts +55 -4
- package/dist/tools/analyze-project.js +104 -15
- package/dist/tools/check-incremental-compatibility.d.ts +30 -41
- package/dist/tools/check-incremental-compatibility.js +32 -264
- package/dist/tools/collect-feedback.js +15 -2
- package/dist/tools/compare-health.d.ts +40 -4
- package/dist/tools/compare-health.js +22 -5
- package/dist/tools/extract-libraries.js +42 -27
- package/dist/tools/find-angular-symbol.js +3 -2
- package/dist/tools/find-component-hosts.js +3 -2
- package/dist/tools/find-usages.js +21 -12
- package/dist/tools/get-call-graph.js +15 -2
- package/dist/tools/get-operation-progress-tool.d.ts +1 -1
- package/dist/tools/get-operation-progress-tool.js +2 -2
- package/dist/tools/get-operation-progress.d.ts +4 -1
- package/dist/tools/get-operation-progress.js +6 -2
- package/dist/tools/helpers/analysis-output.d.ts +32 -1
- package/dist/tools/helpers/analysis-output.js +25 -1
- package/dist/tools/helpers/build-cache.d.ts +27 -0
- package/dist/tools/helpers/build-cache.js +86 -0
- package/dist/tools/helpers/class-filter.d.ts +18 -0
- package/dist/tools/helpers/class-filter.js +30 -0
- package/dist/tools/helpers/cli-arguments.d.ts +23 -0
- package/dist/tools/helpers/cli-arguments.js +35 -0
- package/dist/tools/helpers/feedback-catalog.d.ts +38 -0
- package/dist/tools/helpers/feedback-catalog.js +196 -0
- package/dist/tools/helpers/feedback-sidecar.d.ts +201 -0
- package/dist/tools/helpers/feedback-sidecar.js +381 -0
- package/dist/tools/helpers/file-type-check.d.ts +34 -0
- package/dist/tools/helpers/file-type-check.js +56 -0
- package/dist/tools/helpers/health-delta.d.ts +6 -0
- package/dist/tools/helpers/health-delta.js +4 -1
- package/dist/tools/helpers/library-import-warning.d.ts +33 -0
- package/dist/tools/helpers/library-import-warning.js +38 -0
- package/dist/tools/helpers/library-imports.d.ts +38 -14
- package/dist/tools/helpers/library-imports.js +128 -23
- package/dist/tools/helpers/output-contract.d.ts +64 -0
- package/dist/tools/helpers/output-contract.js +67 -0
- package/dist/tools/helpers/pattern-anonymizer.d.ts +27 -0
- package/dist/tools/helpers/pattern-anonymizer.js +159 -0
- package/dist/tools/helpers/project-cache.d.ts +5 -4
- package/dist/tools/helpers/project-cache.js +21 -16
- package/dist/tools/helpers/project-decorators.d.ts +11 -4
- package/dist/tools/helpers/project-decorators.js +13 -6
- package/dist/tools/helpers/refresh-apply.d.ts +94 -0
- package/dist/tools/helpers/refresh-apply.js +460 -0
- package/dist/tools/helpers/refresh-inventory.d.ts +106 -0
- package/dist/tools/helpers/refresh-inventory.js +631 -0
- package/dist/tools/helpers/rule-runner.js +3 -1
- package/dist/tools/helpers/scan-cache.d.ts +117 -5
- package/dist/tools/helpers/scan-cache.js +179 -6
- package/dist/tools/helpers/scan-engine.d.ts +43 -6
- package/dist/tools/helpers/scan-engine.js +141 -22
- package/dist/tools/helpers/scan-plan.js +16 -2
- package/dist/tools/helpers/source-map-loader.d.ts +55 -0
- package/dist/tools/helpers/source-map-loader.js +226 -0
- package/dist/tools/helpers/template-check.d.ts +76 -0
- package/dist/tools/helpers/template-check.js +158 -0
- package/dist/tools/helpers/tool-cache.d.ts +7 -2
- package/dist/tools/helpers/tool-cache.js +9 -3
- package/dist/tools/helpers/tool-context.d.ts +18 -0
- package/dist/tools/helpers/tool-context.js +29 -0
- package/dist/tools/helpers/transform-safety.d.ts +151 -1
- package/dist/tools/helpers/transform-safety.js +357 -4
- package/dist/tools/inspect-form-group.js +5 -0
- package/dist/tools/inspect-i18n.d.ts +1 -1
- package/dist/tools/inspect-template.js +8 -2
- package/dist/tools/learn-patterns.d.ts +43 -28
- package/dist/tools/learn-patterns.js +83 -161
- package/dist/tools/list-imports.d.ts +1 -1
- package/dist/tools/orchestrate-migration.d.ts +19 -1
- package/dist/tools/orchestrate-migration.js +52 -10
- package/dist/tools/parse-stack-trace.d.ts +48 -1
- package/dist/tools/parse-stack-trace.js +108 -9
- package/dist/tools/plan-migration.js +22 -10
- package/dist/tools/refresh-state.d.ts +378 -0
- package/dist/tools/refresh-state.js +370 -0
- package/dist/tools/resolve-type.js +10 -3
- package/dist/tools/review-feedback.d.ts +42 -7
- package/dist/tools/review-feedback.js +24 -17
- package/dist/tools/rollback-changes.d.ts +5 -0
- package/dist/tools/rollback-changes.js +7 -2
- package/dist/tools/run-angular-cli.js +36 -22
- package/dist/tools/run-build.d.ts +33 -28
- package/dist/tools/run-build.js +136 -438
- package/dist/tools/run-schematic.d.ts +8 -2
- package/dist/tools/run-schematic.js +80 -50
- package/dist/tools/scan-all.d.ts +37 -15
- package/dist/tools/scan-all.js +76 -115
- package/dist/tools/scan-angular.d.ts +33 -14
- package/dist/tools/scan-angular.js +77 -94
- package/dist/tools/scan-architecture.d.ts +37 -12
- package/dist/tools/scan-architecture.js +220 -139
- package/dist/tools/scan-solid.d.ts +33 -14
- package/dist/tools/scan-solid.js +80 -91
- package/dist/tools/search-codebase.d.ts +6 -1
- package/dist/tools/search-codebase.js +13 -7
- package/dist/tools/suggest-improvements.d.ts +34 -3
- package/dist/tools/suggest-improvements.js +34 -9
- package/dist/tools/trace-output-flow.js +3 -2
- package/dist/tools/transform-code-batch.d.ts +9 -9
- package/dist/tools/transform-code.d.ts +161 -12
- package/dist/tools/transform-code.js +715 -206
- package/dist/tools/validate-before-transform.js +2 -1
- package/dist/tools/validate-project-compatibility.d.ts +28 -55
- package/dist/tools/validate-project-compatibility.js +33 -225
- package/dist/tools/validate-transformation.d.ts +40 -26
- package/dist/tools/validate-transformation.js +115 -294
- package/dist/tools/verify-citations.js +8 -2
- package/dist/types.d.ts +9 -9
- package/dist/utils/format-tool-response.d.ts +3 -1
- package/dist/utils/format-tool-response.js +8 -3
- package/package.json +14 -13
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { findTsConfig } from './helpers/find-ts-config.js';
|
|
2
|
+
import { loadConfig } from '@angular-modernizer/core';
|
|
2
3
|
import { glob } from 'glob';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { cancelledExecution, fileProgressMessage, } from './helpers/tool-context.js';
|
|
4
|
+
import { relative } from 'node:path';
|
|
5
|
+
import { describeScan, DEPRECATED_SCAN_ORCHESTRATION_SCHEMA, SCAN_EXECUTION_SCHEMA, SCAN_ORCHESTRATION_NOTICE, scanOutputSchema, } from './helpers/analysis-output.js';
|
|
6
|
+
import { cancelledExecution, fileProgressMessage, finalFileProgress, } from './helpers/tool-context.js';
|
|
7
7
|
import { runScan } from '../scan-host/scan-host.js';
|
|
8
8
|
import { openToolCache } from './helpers/tool-cache.js';
|
|
9
|
+
import { findingsInFileOrder, readCachedFindings, SCAN_CACHE_MODE_SCHEMA, scanCacheMode, SCAN_TOOL_CACHE_VERSION, scanCacheVersion, } from './helpers/scan-cache.js';
|
|
10
|
+
import { withLibraryImportWarning, } from './helpers/library-import-warning.js';
|
|
9
11
|
/**
|
|
10
12
|
* MCP tool `scan-angular`: scans for Angular-specific best practice
|
|
11
|
-
* violations. Runs only the AngularPlugin (
|
|
13
|
+
* violations. Runs only the rules of the AngularPlugin (OnPush, TrackBy,
|
|
12
14
|
* performance, RxJS and others).
|
|
13
15
|
*/
|
|
14
16
|
export class ScanAngularTool {
|
|
@@ -37,7 +39,7 @@ export class ScanAngularTool {
|
|
|
37
39
|
rules: {
|
|
38
40
|
type: 'array',
|
|
39
41
|
items: { type: 'string' },
|
|
40
|
-
description: '
|
|
42
|
+
description: 'Rule ids to run (optional, default all rules of the plugin): only these rules run and are reported in metadata.rulesExecuted; a scan with a selection has a cache of its own, separate from the scan of all rules',
|
|
41
43
|
},
|
|
42
44
|
includePatterns: {
|
|
43
45
|
type: 'array',
|
|
@@ -60,6 +62,7 @@ export class ScanAngularTool {
|
|
|
60
62
|
'**/*.test.ts',
|
|
61
63
|
],
|
|
62
64
|
},
|
|
65
|
+
cache: SCAN_CACHE_MODE_SCHEMA,
|
|
63
66
|
includeAutoFixes: {
|
|
64
67
|
type: 'boolean',
|
|
65
68
|
description: 'Whether to include auto-fix suggestions',
|
|
@@ -80,21 +83,7 @@ export class ScanAngularTool {
|
|
|
80
83
|
description: 'Offset for result pagination',
|
|
81
84
|
default: 0,
|
|
82
85
|
},
|
|
83
|
-
orchestration:
|
|
84
|
-
type: 'object',
|
|
85
|
-
description: 'Advanced orchestration options',
|
|
86
|
-
properties: {
|
|
87
|
-
parallel: {
|
|
88
|
-
type: 'boolean',
|
|
89
|
-
description: 'Enable parallel rule execution',
|
|
90
|
-
default: false,
|
|
91
|
-
},
|
|
92
|
-
maxWorkers: {
|
|
93
|
-
type: 'number',
|
|
94
|
-
description: 'Maximum concurrent workers',
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
},
|
|
86
|
+
orchestration: DEPRECATED_SCAN_ORCHESTRATION_SCHEMA,
|
|
98
87
|
},
|
|
99
88
|
required: ['rootPath'],
|
|
100
89
|
};
|
|
@@ -107,7 +96,10 @@ export class ScanAngularTool {
|
|
|
107
96
|
const params = args;
|
|
108
97
|
const config = this.loadConfig(params.rootPath);
|
|
109
98
|
const mergedParams = { ...config, ...params };
|
|
110
|
-
|
|
99
|
+
// `rules` selects the rules that run (E-19), not only the reported findings
|
|
100
|
+
const ruleSelection = mergedParams.rules?.length ? mergedParams.rules : undefined;
|
|
101
|
+
// orchestration has no effect: the scan always runs in the scan worker
|
|
102
|
+
const notices = mergedParams.orchestration === undefined ? [] : [SCAN_ORCHESTRATION_NOTICE];
|
|
111
103
|
if (!mergedParams.rootPath) {
|
|
112
104
|
throw new Error('rootPath is required');
|
|
113
105
|
}
|
|
@@ -134,6 +126,8 @@ export class ScanAngularTool {
|
|
|
134
126
|
cwd: mergedParams.rootPath,
|
|
135
127
|
absolute: true,
|
|
136
128
|
ignore: excludePatterns,
|
|
129
|
+
// A directory named like a source file (`scaleData.ts/`) is no file
|
|
130
|
+
nodir: true,
|
|
137
131
|
});
|
|
138
132
|
allFiles.push(...files);
|
|
139
133
|
}
|
|
@@ -141,12 +135,19 @@ export class ScanAngularTool {
|
|
|
141
135
|
const uniqueFiles = Array.from(new Set(allFiles)).sort();
|
|
142
136
|
const filesToAnalyze = uniqueFiles; // Analyze ALL files found (batch processing prevents memory issues)
|
|
143
137
|
const maxFiles = mergedParams.maxFiles ?? 100; // Batch size (default 100)
|
|
144
|
-
|
|
138
|
+
// Library resolution state before the cache read: it is part of the
|
|
139
|
+
// cache version, so entries of another node_modules state are not served
|
|
140
|
+
const libraryCheck = await (await import('./helpers/library-imports.js')).checkScanScope(tsConfigPath, filesToAnalyze);
|
|
141
|
+
const cache = await openToolCache(mergedParams.rootPath, 'angular', scanCacheVersion(SCAN_TOOL_CACHE_VERSION, mergedParams.rootPath, ruleSelection, {
|
|
142
|
+
includePatterns: mergedParams.includePatterns,
|
|
143
|
+
excludePatterns: mergedParams.excludePatterns,
|
|
144
|
+
unresolvedPackages: libraryCheck.packages,
|
|
145
|
+
}));
|
|
145
146
|
// ============================================================================
|
|
146
147
|
// CACHE READ SYSTEM
|
|
147
148
|
// ============================================================================
|
|
148
149
|
// Before analyzing files, check if cached results exist for unchanged files.
|
|
149
|
-
//
|
|
150
|
+
// A warm run analyzes only new and changed files.
|
|
150
151
|
//
|
|
151
152
|
// How it works:
|
|
152
153
|
// 1. For each file, check if cache entry exists via CacheManager.getAnalysisResult()
|
|
@@ -154,27 +155,29 @@ export class ScanAngularTool {
|
|
|
154
155
|
// 3. If cached AND unchanged → reuse cached results
|
|
155
156
|
// 4. If not cached OR changed → add to filesToProcess for analysis
|
|
156
157
|
//
|
|
157
|
-
// Performance results (real-world validation on 2,758 files):
|
|
158
|
-
// - First run: 161.4s (analyzes all files, writes cache)
|
|
159
|
-
// - Second run: 14.1s (11.4x speedup, 91.2% faster, reads from cache)
|
|
160
|
-
//
|
|
161
158
|
// Cache directory: .angular-modernizer-cache/angular/
|
|
162
159
|
// Cache invalidation: Automatic via mtime/content hash checking
|
|
163
160
|
// ============================================================================
|
|
164
|
-
|
|
161
|
+
// Findings per analyzed file, from the cache or the scan
|
|
162
|
+
const findingsByFile = new Map();
|
|
163
|
+
let cachedFindings = 0;
|
|
165
164
|
const filesToProcess = [];
|
|
165
|
+
// One entry per analyzed file, also without findings: findings on its
|
|
166
|
+
// template stay with the component file, the template is a dependency.
|
|
167
|
+
// refresh analyzes every file; the write below overwrites the entries
|
|
168
|
+
const cacheMode = scanCacheMode(args);
|
|
166
169
|
for (const filePath of filesToAnalyze) {
|
|
167
|
-
const cached = await
|
|
168
|
-
if (cached
|
|
169
|
-
|
|
170
|
-
|
|
170
|
+
const cached = cacheMode === 'refresh' ? null : await readCachedFindings(filePath, cache);
|
|
171
|
+
if (cached !== null) {
|
|
172
|
+
findingsByFile.set(filePath, cached);
|
|
173
|
+
cachedFindings += cached.length;
|
|
171
174
|
}
|
|
172
175
|
else {
|
|
173
176
|
// File not cached or has changed
|
|
174
177
|
filesToProcess.push(filePath);
|
|
175
178
|
}
|
|
176
179
|
}
|
|
177
|
-
console.info(`Cache: ${
|
|
180
|
+
console.info(`Cache: ${cachedFindings} results from cache, ${filesToProcess.length} files to analyze (hit rate: ${cache.getStats().hitRate.toFixed(1)}%)`);
|
|
178
181
|
// ============================================================================
|
|
179
182
|
// BATCH PROCESSING SYSTEM
|
|
180
183
|
// ============================================================================
|
|
@@ -191,14 +194,16 @@ export class ScanAngularTool {
|
|
|
191
194
|
const totalFiles = filesToProcess.length;
|
|
192
195
|
const totalBatches = Math.ceil(totalFiles / batchSize);
|
|
193
196
|
console.info(`\nProcessing ${totalFiles} files in ${totalBatches} batch(es) of ${batchSize} files each`);
|
|
194
|
-
//
|
|
195
|
-
const
|
|
196
|
-
let
|
|
197
|
+
// Per newly analyzed file its findings (also those on its template) and template files
|
|
198
|
+
const entriesForCache = new Map();
|
|
199
|
+
let newFindings = 0;
|
|
197
200
|
// Kernel, batches and rules run in a scan worker (scan-host), so the
|
|
198
201
|
// server keeps reading stdin while the type checker is built.
|
|
199
202
|
const cachedFiles = filesToAnalyze.length - totalFiles;
|
|
200
203
|
let processedFiles = 0;
|
|
204
|
+
let lastReported;
|
|
201
205
|
if (totalFiles > 0) {
|
|
206
|
+
lastReported = cachedFiles;
|
|
202
207
|
ctx.progress?.(cachedFiles, filesToAnalyze.length, `loading project, ${totalFiles} files to analyze`);
|
|
203
208
|
}
|
|
204
209
|
const engine = await runScan({
|
|
@@ -209,19 +214,28 @@ export class ScanAngularTool {
|
|
|
209
214
|
files: filesToProcess,
|
|
210
215
|
mode: 'batches',
|
|
211
216
|
batchSize,
|
|
212
|
-
|
|
217
|
+
templateDependencies: true,
|
|
218
|
+
contextFiles: filesToAnalyze,
|
|
219
|
+
...(ruleSelection === undefined ? {} : { ruleIds: ruleSelection }),
|
|
213
220
|
}, {
|
|
214
221
|
file: (event) => {
|
|
215
|
-
|
|
222
|
+
entriesForCache.set(event.filePath, {
|
|
223
|
+
results: event.findings,
|
|
224
|
+
dependencies: event.dependencies ?? [],
|
|
225
|
+
});
|
|
226
|
+
findingsByFile.set(event.filePath, event.findings);
|
|
227
|
+
newFindings += event.findings.length;
|
|
216
228
|
processedFiles++;
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
batchDone: (files) => {
|
|
220
|
-
filesAnalyzed += files;
|
|
229
|
+
lastReported = cachedFiles + processedFiles;
|
|
230
|
+
ctx.progress?.(cachedFiles + processedFiles, filesToAnalyze.length, fileProgressMessage(cachedFiles + processedFiles, filesToAnalyze.length, cachedFindings + newFindings));
|
|
221
231
|
},
|
|
222
232
|
}, { signal: ctx.signal });
|
|
223
233
|
const cancelled = engine.cancelled;
|
|
224
|
-
|
|
234
|
+
if (!cancelled) {
|
|
235
|
+
finalFileProgress(ctx.progress, filesToAnalyze.length, cachedFiles + processedFiles, cachedFindings + newFindings, lastReported);
|
|
236
|
+
}
|
|
237
|
+
const results = findingsInFileOrder(findingsByFile);
|
|
238
|
+
console.info(`\nBatch processing complete: ${totalBatches} batch(es), ${cachedFiles + processedFiles} total files analyzed, ${results.length} total violations`);
|
|
225
239
|
// ============================================================================
|
|
226
240
|
// CACHE WRITE SYSTEM
|
|
227
241
|
// ============================================================================
|
|
@@ -231,32 +245,18 @@ export class ScanAngularTool {
|
|
|
231
245
|
// Cache directory: .angular-modernizer-cache/angular/
|
|
232
246
|
// Cache entry format: Same as scan-solid (metadata + results[] + dependencies)
|
|
233
247
|
//
|
|
234
|
-
//
|
|
235
|
-
//
|
|
236
|
-
// - Second run: Reads cache (11.4x speedup - one of the best improvements!)
|
|
237
|
-
//
|
|
238
|
-
// Why Angular benefits more from caching than SOLID:
|
|
239
|
-
// - Angular rules are more computationally expensive (template parsing, decorators)
|
|
240
|
-
// - Parsing Angular templates and metadata takes significant time
|
|
241
|
-
// - Cache hit eliminates all AST parsing and decorator analysis overhead
|
|
248
|
+
// A cache hit skips the analysis of the file by every rule (template
|
|
249
|
+
// parsing, decorators).
|
|
242
250
|
// ============================================================================
|
|
243
|
-
//
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
if (!resultsByFile.has(filePath)) {
|
|
249
|
-
resultsByFile.set(filePath, []);
|
|
250
|
-
}
|
|
251
|
-
resultsByFile.get(filePath).push(result);
|
|
252
|
-
}
|
|
253
|
-
// Write each file's results to cache
|
|
254
|
-
for (const [filePath, fileResults] of resultsByFile.entries()) {
|
|
255
|
-
await cache.setAnalysisResult(filePath, fileResults);
|
|
251
|
+
// A cancelled scan writes nothing: files analyzed before the cancel saw only
|
|
252
|
+
// part of the project, so cross-file and template findings could differ from
|
|
253
|
+
// a full run and a later warm run would serve them as current.
|
|
254
|
+
for (const [filePath, entry] of cancelled ? [] : entriesForCache) {
|
|
255
|
+
await cache.setAnalysisResult(filePath, entry.results, entry.dependencies);
|
|
256
256
|
}
|
|
257
257
|
// Log cache effectiveness
|
|
258
258
|
const stats = cache.getStats();
|
|
259
|
-
console.info(`Cached ${
|
|
259
|
+
console.info(`Cached ${cancelled ? 0 : entriesForCache.size} files (hit rate: ${stats.hitRate.toFixed(1)}%)`);
|
|
260
260
|
// Filter by specific rules if requested
|
|
261
261
|
let violations = results
|
|
262
262
|
.filter((r) => r.ruleId && r.filePath)
|
|
@@ -283,7 +283,8 @@ export class ScanAngularTool {
|
|
|
283
283
|
const maxResults = mergedParams.maxResults ?? 1000;
|
|
284
284
|
const paginatedViolations = violations.slice(offset, offset + maxResults);
|
|
285
285
|
// Counts cover every violation, not only the page
|
|
286
|
-
|
|
286
|
+
// A file that failed to load sends no result and is not analyzed
|
|
287
|
+
const analyzedFiles = cachedFiles + processedFiles;
|
|
287
288
|
const counts = this.calculateSummary(violations, analyzedFiles);
|
|
288
289
|
const execution = cancelled
|
|
289
290
|
? cancelledExecution(analyzedFiles, filesToAnalyze.length - analyzedFiles)
|
|
@@ -296,7 +297,7 @@ export class ScanAngularTool {
|
|
|
296
297
|
};
|
|
297
298
|
const duration = Date.now() - startTime;
|
|
298
299
|
const ruleIds = engine.ruleIds;
|
|
299
|
-
return {
|
|
300
|
+
return withLibraryImportWarning({
|
|
300
301
|
violations: paginatedViolations,
|
|
301
302
|
counts,
|
|
302
303
|
metadata: {
|
|
@@ -304,42 +305,24 @@ export class ScanAngularTool {
|
|
|
304
305
|
duration,
|
|
305
306
|
projectRoot: mergedParams.rootPath,
|
|
306
307
|
},
|
|
307
|
-
|
|
308
|
-
? {
|
|
309
|
-
parallel: true,
|
|
310
|
-
incremental: false,
|
|
311
|
-
filesAnalyzed: filesToAnalyze.length,
|
|
312
|
-
filesSkipped: 0,
|
|
313
|
-
cacheHitRate: 0,
|
|
314
|
-
duration,
|
|
315
|
-
throughput: filesToAnalyze.length / (duration / 1000),
|
|
316
|
-
}
|
|
317
|
-
: undefined,
|
|
308
|
+
...(notices.length === 0 ? {} : { warnings: notices }),
|
|
318
309
|
pagination,
|
|
319
310
|
...(execution === undefined ? {} : { execution }),
|
|
320
|
-
summary: describeScan(counts, paginatedViolations, pagination, execution === undefined ? [] : [execution.note]),
|
|
321
|
-
};
|
|
311
|
+
summary: describeScan(counts, paginatedViolations, pagination, [...notices, ...(execution === undefined ? [] : [execution.note])]),
|
|
312
|
+
}, libraryCheck.unresolved);
|
|
322
313
|
}
|
|
323
314
|
/**
|
|
324
|
-
*
|
|
325
|
-
*
|
|
315
|
+
* The `tools['scan-angular']` section of `.angular-modernizer.json`; arguments of
|
|
316
|
+
* the call override it.
|
|
326
317
|
*/
|
|
327
318
|
loadConfig(rootPath) {
|
|
328
|
-
// Ensure rootPath is provided before loading config
|
|
329
319
|
if (!rootPath) {
|
|
330
320
|
return {};
|
|
331
321
|
}
|
|
332
|
-
const configPath = resolve(rootPath, '.angular-modernizer.json');
|
|
333
|
-
if (!existsSync(configPath)) {
|
|
334
|
-
return {};
|
|
335
|
-
}
|
|
336
322
|
try {
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
const scanAngularConfig = config['scan-angular'];
|
|
341
|
-
if (scanAngularConfig && typeof scanAngularConfig === 'object') {
|
|
342
|
-
return scanAngularConfig;
|
|
323
|
+
const toolConfig = loadConfig(rootPath).tools?.['scan-angular'];
|
|
324
|
+
if (toolConfig && typeof toolConfig === 'object') {
|
|
325
|
+
return toolConfig;
|
|
343
326
|
}
|
|
344
327
|
}
|
|
345
328
|
catch (error) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { MCPTool, ToolAnnotations, ToolContext } from '../types.js';
|
|
2
|
+
import { type UnresolvedLibraryImports } from './helpers/library-import-warning.js';
|
|
2
3
|
import { type ScanCounts } from './helpers/analysis-output.js';
|
|
3
4
|
import { type RuleTiming } from './helpers/rule-runner.js';
|
|
4
5
|
/**
|
|
@@ -46,12 +47,17 @@ export interface ResolvedScope {
|
|
|
46
47
|
export interface ScanExecution {
|
|
47
48
|
/** Time budget of the scan in milliseconds; `0` means no budget. */
|
|
48
49
|
maxDurationMs: number;
|
|
49
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* `true` when the time budget or a cancellation stopped the scan early, or
|
|
52
|
+
* `maxFiles` left files of the scope out.
|
|
53
|
+
*/
|
|
50
54
|
incomplete: boolean;
|
|
51
|
-
/** Why the scan stopped early. */
|
|
52
|
-
stopReason?: 'time-budget' | 'cancelled';
|
|
53
|
-
/** Files that were not analyzed
|
|
55
|
+
/** Why the scan stopped early or left files out. */
|
|
56
|
+
stopReason?: 'time-budget' | 'cancelled' | 'max-files';
|
|
57
|
+
/** Files of the scope that were not analyzed. */
|
|
54
58
|
skippedFiles: number;
|
|
59
|
+
/** Files in the scope before the `maxFiles` cap; set when the cap cut files. */
|
|
60
|
+
scopeFiles?: number;
|
|
55
61
|
/** Time per rule, slowest first. */
|
|
56
62
|
ruleTimings: RuleTiming[];
|
|
57
63
|
/** Human-readable note on an incomplete scan. */
|
|
@@ -65,6 +71,13 @@ export interface ScanArchitectureResult {
|
|
|
65
71
|
* Operation ID for streaming mode (when streaming=true).
|
|
66
72
|
*/
|
|
67
73
|
operationId?: string;
|
|
74
|
+
/** The warning about library imports that do not resolve. */
|
|
75
|
+
warnings?: string[];
|
|
76
|
+
/**
|
|
77
|
+
* Library imports of the scope that do not resolve (sequential and fluent
|
|
78
|
+
* path); absent when all resolve.
|
|
79
|
+
*/
|
|
80
|
+
unresolvedLibraryImports?: UnresolvedLibraryImports;
|
|
68
81
|
/**
|
|
69
82
|
* All violations found.
|
|
70
83
|
*/
|
|
@@ -77,7 +90,7 @@ export interface ScanArchitectureResult {
|
|
|
77
90
|
severity: 'error' | 'warning' | 'info';
|
|
78
91
|
/** Rule message. */
|
|
79
92
|
message: string;
|
|
80
|
-
/** File the violation was reported on
|
|
93
|
+
/** File the violation was reported on, relative to `rootPath`. */
|
|
81
94
|
filePath: string;
|
|
82
95
|
/** 1-based line of the finding, when the rule reports one. */
|
|
83
96
|
line?: number;
|
|
@@ -206,8 +219,8 @@ export interface ScanArchitectureResult {
|
|
|
206
219
|
}
|
|
207
220
|
/**
|
|
208
221
|
* MCP tool `scan-architecture`: scans for architectural issues. Runs only the
|
|
209
|
-
* ArchitecturePlugin (
|
|
210
|
-
* and others).
|
|
222
|
+
* rules of the ArchitecturePlugin (import cycles, layer violations, god
|
|
223
|
+
* objects and others).
|
|
211
224
|
*/
|
|
212
225
|
export declare class ScanArchitectureTool implements MCPTool {
|
|
213
226
|
readonly name = "scan-architecture";
|
|
@@ -275,10 +288,16 @@ export declare class ScanArchitectureTool implements MCPTool {
|
|
|
275
288
|
description: string;
|
|
276
289
|
default: string[];
|
|
277
290
|
};
|
|
291
|
+
cache: {
|
|
292
|
+
description: string;
|
|
293
|
+
type: "string";
|
|
294
|
+
enum: readonly ["use", "refresh"];
|
|
295
|
+
default: "use";
|
|
296
|
+
};
|
|
278
297
|
includeAutoFixes: {
|
|
279
298
|
type: string;
|
|
280
299
|
description: string;
|
|
281
|
-
|
|
300
|
+
deprecated: boolean;
|
|
282
301
|
};
|
|
283
302
|
maxFiles: {
|
|
284
303
|
type: string;
|
|
@@ -422,15 +441,21 @@ export declare class ScanArchitectureTool implements MCPTool {
|
|
|
422
441
|
*/
|
|
423
442
|
private calculateSummary;
|
|
424
443
|
/**
|
|
425
|
-
*
|
|
426
|
-
* Only loads from the provided root path
|
|
444
|
+
* The `tools['scan-architecture']` section of `.angular-modernizer.json`.
|
|
445
|
+
* Only loads from the provided root path, never from the server's cwd.
|
|
427
446
|
*/
|
|
428
447
|
private loadConfig;
|
|
429
448
|
/**
|
|
430
|
-
* Resolve scope configuration to actual file paths.
|
|
431
|
-
*
|
|
449
|
+
* Resolve scope configuration to actual file paths. A scope other than
|
|
450
|
+
* `all` that resolves to no path is an error: the file filter treats an
|
|
451
|
+
* empty path list as "everything", so such a scope used to scan the whole
|
|
452
|
+
* project (its first `maxFiles` files) instead of nothing.
|
|
432
453
|
*/
|
|
433
454
|
private resolveScope;
|
|
455
|
+
/**
|
|
456
|
+
* Paths a scope stands for. Reads angular.json to find project paths.
|
|
457
|
+
*/
|
|
458
|
+
private resolveScopePaths;
|
|
434
459
|
/**
|
|
435
460
|
* Filter files based on resolved scope paths.
|
|
436
461
|
*/
|