@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
package/dist/tools/scan-all.js
CHANGED
|
@@ -2,26 +2,20 @@ import { findTsConfig } from './helpers/find-ts-config.js';
|
|
|
2
2
|
import { MultiCacheFallbackManager, RealFileSystemAdapter, createMultiCacheConfig, loadConfig, } from '@angular-modernizer/core';
|
|
3
3
|
import { glob } from 'glob';
|
|
4
4
|
import { relative } from 'node:path';
|
|
5
|
-
import { statSync } from 'node:fs';
|
|
6
5
|
import { FindingWindow } from './helpers/finding-window.js';
|
|
7
|
-
import { cancelledExecution, fileProgressMessage, } from './helpers/tool-context.js';
|
|
6
|
+
import { cancelledExecution, fileProgressMessage, finalFileProgress, } from './helpers/tool-context.js';
|
|
8
7
|
import { runScan } from '../scan-host/scan-host.js';
|
|
9
|
-
import { describeScan, SCAN_EXECUTION_SCHEMA, scanOutputSchema, } from './helpers/analysis-output.js';
|
|
10
|
-
import {
|
|
8
|
+
import { describeScan, DEPRECATED_SCAN_ORCHESTRATION_SCHEMA, SCAN_EXECUTION_SCHEMA, SCAN_ORCHESTRATION_NOTICE, scanOutputSchema, } from './helpers/analysis-output.js';
|
|
9
|
+
import { findingsInFileOrder, readCachedFindings, SCAN_CACHE_MODE_SCHEMA, scanCacheMode, scanCacheVersion, SCAN_ALL_CACHE_VERSION, } from './helpers/scan-cache.js';
|
|
10
|
+
import { withLibraryImportWarning, } from './helpers/library-import-warning.js';
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
13
|
-
* per-analyzed-file layout (findings filed under their template, files without
|
|
14
|
-
* findings missing) would read as complete; the version invalidates them.
|
|
15
|
-
*/
|
|
16
|
-
const SCAN_ALL_CACHE_VERSION = 'scan-all-2';
|
|
17
|
-
/**
|
|
18
|
-
* MCP tool `scan-all`: one scan with all analysis plugins (52 rules total).
|
|
12
|
+
* MCP tool `scan-all`: one scan with the rules of all analysis plugins.
|
|
19
13
|
*
|
|
20
14
|
* @remarks
|
|
21
15
|
* Plugins and rules:
|
|
22
|
-
* - SolidPlugin
|
|
23
|
-
* - AngularPlugin
|
|
24
|
-
* - ArchitecturePlugin
|
|
16
|
+
* - SolidPlugin: SOLID principles
|
|
17
|
+
* - AngularPlugin: Angular best practices
|
|
18
|
+
* - ArchitecturePlugin: architectural issues
|
|
25
19
|
*/
|
|
26
20
|
export class ScanAllTool {
|
|
27
21
|
name = 'scan-all';
|
|
@@ -32,7 +26,7 @@ export class ScanAllTool {
|
|
|
32
26
|
idempotentHint: true,
|
|
33
27
|
openWorldHint: false,
|
|
34
28
|
};
|
|
35
|
-
description = 'Comprehensive code quality scan with all plugins (SOLID
|
|
29
|
+
description = 'Comprehensive code quality scan with the rules of all analysis plugins (SOLID, Angular, Architecture). ' +
|
|
36
30
|
'maxResults (default 1000) and resultOffset page the violations; counts cover all of them, summary is a short text.';
|
|
37
31
|
/**
|
|
38
32
|
* JSON Schema of the tool arguments.
|
|
@@ -49,7 +43,7 @@ export class ScanAllTool {
|
|
|
49
43
|
rules: {
|
|
50
44
|
type: 'array',
|
|
51
45
|
items: { type: 'string' },
|
|
52
|
-
description: '
|
|
46
|
+
description: 'Rule ids to run (optional, default all rules): 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',
|
|
53
47
|
},
|
|
54
48
|
includePatterns: {
|
|
55
49
|
type: 'array',
|
|
@@ -72,6 +66,7 @@ export class ScanAllTool {
|
|
|
72
66
|
'**/*.test.ts',
|
|
73
67
|
],
|
|
74
68
|
},
|
|
69
|
+
cache: SCAN_CACHE_MODE_SCHEMA,
|
|
75
70
|
includeAutoFixes: {
|
|
76
71
|
type: 'boolean',
|
|
77
72
|
description: 'Whether to include auto-fix suggestions',
|
|
@@ -92,21 +87,7 @@ export class ScanAllTool {
|
|
|
92
87
|
description: 'Offset for result pagination',
|
|
93
88
|
default: 0,
|
|
94
89
|
},
|
|
95
|
-
orchestration:
|
|
96
|
-
type: 'object',
|
|
97
|
-
description: 'Advanced orchestration options',
|
|
98
|
-
properties: {
|
|
99
|
-
parallel: {
|
|
100
|
-
type: 'boolean',
|
|
101
|
-
description: 'Enable parallel rule execution',
|
|
102
|
-
default: false,
|
|
103
|
-
},
|
|
104
|
-
maxWorkers: {
|
|
105
|
-
type: 'number',
|
|
106
|
-
description: 'Maximum concurrent workers',
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
},
|
|
90
|
+
orchestration: DEPRECATED_SCAN_ORCHESTRATION_SCHEMA,
|
|
110
91
|
},
|
|
111
92
|
required: ['rootPath'],
|
|
112
93
|
};
|
|
@@ -122,7 +103,10 @@ export class ScanAllTool {
|
|
|
122
103
|
const params = args;
|
|
123
104
|
const config = this.loadConfig(params.rootPath);
|
|
124
105
|
const mergedParams = { ...config, ...params };
|
|
125
|
-
|
|
106
|
+
// `rules` selects the rules that run (E-19), not only the reported findings
|
|
107
|
+
const ruleSelection = mergedParams.rules?.length ? mergedParams.rules : undefined;
|
|
108
|
+
// orchestration has no effect: the scan always runs in the scan worker
|
|
109
|
+
const notices = mergedParams.orchestration === undefined ? [] : [SCAN_ORCHESTRATION_NOTICE];
|
|
126
110
|
if (!mergedParams.rootPath) {
|
|
127
111
|
throw new Error('rootPath is required');
|
|
128
112
|
}
|
|
@@ -149,6 +133,8 @@ export class ScanAllTool {
|
|
|
149
133
|
cwd: mergedParams.rootPath,
|
|
150
134
|
absolute: true,
|
|
151
135
|
ignore: excludePatterns,
|
|
136
|
+
// A directory named like a source file (`scaleData.ts/`) is no file
|
|
137
|
+
nodir: true,
|
|
152
138
|
});
|
|
153
139
|
allFiles.push(...files);
|
|
154
140
|
}
|
|
@@ -167,25 +153,34 @@ export class ScanAllTool {
|
|
|
167
153
|
// returned no hits and invalidated (deleted) their entries.
|
|
168
154
|
// ============================================================================
|
|
169
155
|
const fileSystem = new RealFileSystemAdapter();
|
|
156
|
+
// Library resolution state before the cache read: it is part of the
|
|
157
|
+
// cache version, so entries of another node_modules state are not served
|
|
158
|
+
const libraryCheck = await (await import('./helpers/library-imports.js')).checkScanScope(tsConfigPath, filesToAnalyze);
|
|
170
159
|
const multiCacheManager = new MultiCacheFallbackManager(fileSystem, ['all'], {
|
|
171
160
|
...createMultiCacheConfig(mergedParams.rootPath),
|
|
172
|
-
version: SCAN_ALL_CACHE_VERSION,
|
|
161
|
+
version: scanCacheVersion(SCAN_ALL_CACHE_VERSION, mergedParams.rootPath, ruleSelection, {
|
|
162
|
+
includePatterns: mergedParams.includePatterns,
|
|
163
|
+
excludePatterns: mergedParams.excludePatterns,
|
|
164
|
+
unresolvedPackages: libraryCheck.packages,
|
|
165
|
+
}),
|
|
173
166
|
});
|
|
174
167
|
await multiCacheManager.initialize();
|
|
175
|
-
|
|
168
|
+
// Findings per analyzed file, from the cache or the scan
|
|
169
|
+
const findingsByFile = new Map();
|
|
170
|
+
let cachedFindings = 0;
|
|
176
171
|
const filesToProcess = [];
|
|
177
172
|
const cacheHitsBySource = {};
|
|
178
173
|
// The cache holds every rule's findings per analyzed file, so an entry
|
|
179
174
|
// without findings is a hit as well.
|
|
180
175
|
const ownCache = multiCacheManager.getAllCaches()[0].manager;
|
|
176
|
+
// refresh analyzes every file; the write below overwrites the entries
|
|
177
|
+
const cacheMode = scanCacheMode(args);
|
|
181
178
|
for (const filePath of filesToAnalyze) {
|
|
182
|
-
const cached = await readCachedFindings(filePath, ownCache);
|
|
179
|
+
const cached = cacheMode === 'refresh' ? null : await readCachedFindings(filePath, ownCache);
|
|
183
180
|
if (cached !== null) {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
const source = cached.source;
|
|
188
|
-
cacheHitsBySource[source] = (cacheHitsBySource[source] ?? 0) + 1;
|
|
181
|
+
findingsByFile.set(filePath, cached);
|
|
182
|
+
cachedFindings += cached.length;
|
|
183
|
+
cacheHitsBySource['all'] = (cacheHitsBySource['all'] ?? 0) + 1;
|
|
189
184
|
}
|
|
190
185
|
else {
|
|
191
186
|
// File not cached in any directory or has changed
|
|
@@ -193,7 +188,7 @@ export class ScanAllTool {
|
|
|
193
188
|
}
|
|
194
189
|
}
|
|
195
190
|
const stats = multiCacheManager.getStats();
|
|
196
|
-
console.info(`Cache: ${
|
|
191
|
+
console.info(`Cache: ${cachedFindings} results from cache, ${filesToProcess.length} files to analyze (hit rate: ${stats.hitRate.toFixed(1)}%)`);
|
|
197
192
|
// Show cache hit breakdown by source (Phase 3 feature)
|
|
198
193
|
if (Object.keys(cacheHitsBySource).length > 0) {
|
|
199
194
|
console.info(`Cache hits by source:`);
|
|
@@ -211,32 +206,29 @@ export class ScanAllTool {
|
|
|
211
206
|
// - Runs 35 total rules (SOLID + Angular + Architecture combined)
|
|
212
207
|
// - Highest memory pressure of all scan tools
|
|
213
208
|
// - Batch size of 100 is critical for stability
|
|
214
|
-
// - Longest analysis time
|
|
209
|
+
// - Longest analysis time of the scan tools
|
|
215
210
|
// ============================================================================
|
|
216
211
|
const batchSize = maxFiles;
|
|
217
212
|
const totalFiles = filesToProcess.length;
|
|
218
213
|
const totalBatches = Math.ceil(totalFiles / batchSize);
|
|
219
214
|
console.info(`\nProcessing ${totalFiles} files in ${totalBatches} batch(es) of ${batchSize} files each`);
|
|
220
|
-
// Separate arrays for two concerns:
|
|
221
215
|
// - entriesForCache: per newly-analyzed file its violations (also those on its template) and template files
|
|
216
|
+
// - findingsByFile: the findings of every file, so they enter the window in file order
|
|
222
217
|
// - window: rule filter, totals and the requested page of cached and new violations
|
|
223
|
-
// PERF-1: heap is bounded because the page holds at most maxResults entries.
|
|
224
218
|
const paginationOffset = mergedParams.resultOffset ?? 0;
|
|
225
219
|
const paginationLimit = mergedParams.maxResults ?? 1000;
|
|
226
220
|
const entriesForCache = new Map();
|
|
227
|
-
|
|
228
|
-
//
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
let
|
|
234
|
-
const progressTotal = cachedResults.length + totalFiles;
|
|
221
|
+
let newFindings = 0;
|
|
222
|
+
// Files served from the cache plus files the scan reported; a file that
|
|
223
|
+
// failed to load (unreadable, removed meanwhile) is not analyzed.
|
|
224
|
+
const cacheHits = filesToAnalyze.length - totalFiles;
|
|
225
|
+
let filesAnalyzed = cacheHits;
|
|
226
|
+
const progressTotal = filesToAnalyze.length;
|
|
227
|
+
let lastReported;
|
|
235
228
|
// Kernel, batches and rules run in a scan worker (scan-host), so the
|
|
236
|
-
// server keeps reading stdin while the type checker is built.
|
|
237
|
-
// failed to load count as analyzed once their batch is done, as before.
|
|
238
|
-
let batchFilesAnalyzed = 0;
|
|
229
|
+
// server keeps reading stdin while the type checker is built.
|
|
239
230
|
if (totalFiles > 0) {
|
|
231
|
+
lastReported = filesAnalyzed;
|
|
240
232
|
ctx.progress?.(filesAnalyzed, progressTotal, `loading project, ${totalFiles} files to analyze`);
|
|
241
233
|
}
|
|
242
234
|
const engine = await runScan({
|
|
@@ -245,9 +237,11 @@ export class ScanAllTool {
|
|
|
245
237
|
tsConfigPath,
|
|
246
238
|
rootPath: mergedParams.rootPath,
|
|
247
239
|
files: filesToProcess,
|
|
240
|
+
contextFiles: filesToAnalyze,
|
|
248
241
|
mode: 'batches',
|
|
249
242
|
batchSize,
|
|
250
243
|
templateDependencies: true,
|
|
244
|
+
...(ruleSelection === undefined ? {} : { ruleIds: ruleSelection }),
|
|
251
245
|
}, {
|
|
252
246
|
file: (event) => {
|
|
253
247
|
// Always accumulate for cache writes, also files without findings
|
|
@@ -255,20 +249,22 @@ export class ScanAllTool {
|
|
|
255
249
|
results: event.findings,
|
|
256
250
|
dependencies: event.dependencies ?? [],
|
|
257
251
|
});
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
ctx.progress?.(filesAnalyzed
|
|
263
|
-
},
|
|
264
|
-
batchDone: (files) => {
|
|
265
|
-
filesAnalyzed += files;
|
|
266
|
-
batchFilesAnalyzed = 0;
|
|
252
|
+
findingsByFile.set(event.filePath, event.findings);
|
|
253
|
+
newFindings += event.findings.length;
|
|
254
|
+
filesAnalyzed++;
|
|
255
|
+
lastReported = filesAnalyzed;
|
|
256
|
+
ctx.progress?.(filesAnalyzed, progressTotal, fileProgressMessage(filesAnalyzed, progressTotal, cachedFindings + newFindings));
|
|
267
257
|
},
|
|
268
258
|
}, { signal: ctx.signal });
|
|
269
259
|
const cancelled = engine.cancelled;
|
|
270
|
-
if (cancelled) {
|
|
271
|
-
filesAnalyzed
|
|
260
|
+
if (!cancelled) {
|
|
261
|
+
finalFileProgress(ctx.progress, progressTotal, filesAnalyzed, cachedFindings + newFindings, lastReported);
|
|
262
|
+
}
|
|
263
|
+
// Cached and newly analyzed findings go through the same window in file
|
|
264
|
+
// order: rule filter, summary totals, then the requested page.
|
|
265
|
+
const window = new FindingWindow(mergedParams.rules, paginationOffset, paginationLimit);
|
|
266
|
+
for (const finding of findingsInFileOrder(findingsByFile)) {
|
|
267
|
+
window.add(finding);
|
|
272
268
|
}
|
|
273
269
|
console.info(`\nBatch processing complete: ${totalBatches} batch(es), ${filesAnalyzed} total files analyzed, ${window.getTotals().totalViolations} total violations`);
|
|
274
270
|
// ============================================================================
|
|
@@ -284,26 +280,21 @@ export class ScanAllTool {
|
|
|
284
280
|
//
|
|
285
281
|
// Cache entry format: Same as scan-solid (metadata + results[] + dependencies)
|
|
286
282
|
//
|
|
287
|
-
//
|
|
288
|
-
// - First run: Writes cache (adds ~1-2% overhead)
|
|
289
|
-
// - Second run: Reads cache (14.9x speedup - best overall improvement!)
|
|
290
|
-
//
|
|
291
|
-
// Why scan-all benefits most from caching:
|
|
292
|
-
// - Runs 35 total rules (SOLID + Angular + Architecture)
|
|
293
|
-
// - Each file analyzed with ALL rules = most expensive analysis
|
|
294
|
-
// - Cache hit eliminates analysis for ALL 35 rules per file
|
|
295
|
-
// - 93.3% time saved on second run (359.8s → 24.2s)
|
|
283
|
+
// A cache hit skips the analysis of the file by the rules of all plugins.
|
|
296
284
|
// ============================================================================
|
|
297
285
|
// One entry per analyzed file, also without findings, so a warm run does not
|
|
298
286
|
// analyze it again in a different batch. Findings on a template stay with the
|
|
299
287
|
// component file that produced them; the template is a dependency.
|
|
300
288
|
// Writes go to the PRIMARY cache only (multiCacheManager writes to first cache).
|
|
301
|
-
|
|
289
|
+
// A cancelled scan writes nothing: files analyzed before the cancel saw only
|
|
290
|
+
// part of the project, so cross-file and template findings could differ from
|
|
291
|
+
// a full run and a later warm run would serve them as current.
|
|
292
|
+
for (const [filePath, entry] of cancelled ? [] : entriesForCache) {
|
|
302
293
|
await multiCacheManager.setAnalysisResult(filePath, entry.results, entry.dependencies);
|
|
303
294
|
}
|
|
304
295
|
// Log cache effectiveness
|
|
305
296
|
const writeStats = multiCacheManager.getStats();
|
|
306
|
-
console.info(`Cached ${entriesForCache.size} files to primary cache (hit rate: ${writeStats.hitRate.toFixed(1)}%)`);
|
|
297
|
+
console.info(`Cached ${cancelled ? 0 : entriesForCache.size} files to primary cache (hit rate: ${writeStats.hitRate.toFixed(1)}%)`);
|
|
307
298
|
// The window holds only the requested page of the filtered findings.
|
|
308
299
|
const paginatedViolations = window
|
|
309
300
|
.getPage()
|
|
@@ -325,7 +316,7 @@ export class ScanAllTool {
|
|
|
325
316
|
const totals = window.getTotals();
|
|
326
317
|
const counts = {
|
|
327
318
|
...totals,
|
|
328
|
-
analyzedFiles:
|
|
319
|
+
analyzedFiles: filesAnalyzed,
|
|
329
320
|
};
|
|
330
321
|
const execution = cancelled
|
|
331
322
|
? cancelledExecution(filesAnalyzed, filesToAnalyze.length - filesAnalyzed)
|
|
@@ -340,7 +331,7 @@ export class ScanAllTool {
|
|
|
340
331
|
const allRuleIds = engine.ruleIds;
|
|
341
332
|
// Get final cache statistics (Phase 3)
|
|
342
333
|
const finalStats = multiCacheManager.getStats();
|
|
343
|
-
return {
|
|
334
|
+
return withLibraryImportWarning({
|
|
344
335
|
violations: paginatedViolations,
|
|
345
336
|
counts,
|
|
346
337
|
metadata: {
|
|
@@ -350,7 +341,7 @@ export class ScanAllTool {
|
|
|
350
341
|
// Add cache stats to metadata for visibility
|
|
351
342
|
cacheStats: {
|
|
352
343
|
totalFilesChecked: filesToAnalyze.length,
|
|
353
|
-
filesFromCache:
|
|
344
|
+
filesFromCache: cacheHits,
|
|
354
345
|
filesToProcess: filesToProcess.length,
|
|
355
346
|
hitRate: finalStats.hitRate,
|
|
356
347
|
hitsBySource: cacheHitsBySource,
|
|
@@ -359,28 +350,19 @@ export class ScanAllTool {
|
|
|
359
350
|
// Cache statistics with source breakdown
|
|
360
351
|
// hitRate and hitsBySource refer to the own cache (/all/) only.
|
|
361
352
|
cache: {
|
|
353
|
+
mode: cacheMode,
|
|
362
354
|
totalFilesChecked: filesToAnalyze.length,
|
|
363
|
-
filesFromCache:
|
|
355
|
+
filesFromCache: cacheHits,
|
|
364
356
|
filesToProcess: filesToProcess.length,
|
|
365
357
|
hitRate: finalStats.hitRate,
|
|
366
358
|
hitsBySource: cacheHitsBySource,
|
|
367
359
|
stats: finalStats,
|
|
368
360
|
},
|
|
369
|
-
|
|
370
|
-
? {
|
|
371
|
-
parallel: true,
|
|
372
|
-
incremental: false,
|
|
373
|
-
filesAnalyzed: filesToAnalyze.length,
|
|
374
|
-
filesSkipped: 0,
|
|
375
|
-
cacheHitRate: finalStats.hitRate,
|
|
376
|
-
duration,
|
|
377
|
-
throughput: filesToAnalyze.length / (duration / 1000),
|
|
378
|
-
}
|
|
379
|
-
: undefined,
|
|
361
|
+
...(notices.length === 0 ? {} : { warnings: notices }),
|
|
380
362
|
pagination,
|
|
381
363
|
...(execution === undefined ? {} : { execution }),
|
|
382
|
-
summary: describeScan(counts, paginatedViolations, pagination, execution === undefined ? [] : [execution.note]),
|
|
383
|
-
};
|
|
364
|
+
summary: describeScan(counts, paginatedViolations, pagination, [...notices, ...(execution === undefined ? [] : [execution.note])]),
|
|
365
|
+
}, libraryCheck.unresolved);
|
|
384
366
|
}
|
|
385
367
|
/**
|
|
386
368
|
* Load scan-all tool configuration from .angular-modernizer.json file.
|
|
@@ -403,25 +385,4 @@ export class ScanAllTool {
|
|
|
403
385
|
return {};
|
|
404
386
|
}
|
|
405
387
|
}
|
|
406
|
-
/**
|
|
407
|
-
* Cached findings of one file, or `null` when it must be analyzed. An own
|
|
408
|
-
* entry is authoritative even without findings, but stale once one of its
|
|
409
|
-
* template dependencies changed.
|
|
410
|
-
*/
|
|
411
|
-
async function readCachedFindings(filePath, ownCache) {
|
|
412
|
-
const own = await ownCache.getAnalysisResult(filePath);
|
|
413
|
-
if (own === null) {
|
|
414
|
-
return null;
|
|
415
|
-
}
|
|
416
|
-
const fresh = dependenciesUnchanged(own.dependencies, own.metadata.cachedAt, modifiedAt);
|
|
417
|
-
return fresh ? { results: own.results, source: 'all' } : null;
|
|
418
|
-
}
|
|
419
|
-
function modifiedAt(path) {
|
|
420
|
-
try {
|
|
421
|
-
return statSync(path).mtimeMs;
|
|
422
|
-
}
|
|
423
|
-
catch {
|
|
424
|
-
return undefined;
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
388
|
//# sourceMappingURL=scan-all.js.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { MCPTool, ToolAnnotations, ToolContext } from '../types.js';
|
|
2
2
|
import { type ScanCounts } from './helpers/analysis-output.js';
|
|
3
3
|
import { type CancelledExecution } from './helpers/tool-context.js';
|
|
4
|
+
import { type UnresolvedLibraryImports } from './helpers/library-import-warning.js';
|
|
4
5
|
/** Result of the scan-angular tool. */
|
|
5
6
|
export interface ScanAngularResult {
|
|
6
7
|
/** The requested page of violations (`maxResults`, `resultOffset`). */
|
|
@@ -41,7 +42,17 @@ export interface ScanAngularResult {
|
|
|
41
42
|
/** Root path of the scanned project. */
|
|
42
43
|
projectRoot: string;
|
|
43
44
|
};
|
|
44
|
-
/**
|
|
45
|
+
/**
|
|
46
|
+
* Deprecation notices of the call (`orchestration` has no effect) and the
|
|
47
|
+
* warning about library imports that do not resolve.
|
|
48
|
+
*/
|
|
49
|
+
warnings?: string[];
|
|
50
|
+
/** Library imports of the scope that do not resolve; absent when all resolve. */
|
|
51
|
+
unresolvedLibraryImports?: UnresolvedLibraryImports;
|
|
52
|
+
/**
|
|
53
|
+
* @deprecated No longer set: the block claimed a parallel run that never
|
|
54
|
+
* happened. The scan always runs in the scan worker.
|
|
55
|
+
*/
|
|
45
56
|
orchestration?: {
|
|
46
57
|
/** Whether the scan ran in parallel. */
|
|
47
58
|
parallel: boolean;
|
|
@@ -72,7 +83,7 @@ export interface ScanAngularResult {
|
|
|
72
83
|
}
|
|
73
84
|
/**
|
|
74
85
|
* MCP tool `scan-angular`: scans for Angular-specific best practice
|
|
75
|
-
* violations. Runs only the AngularPlugin (
|
|
86
|
+
* violations. Runs only the rules of the AngularPlugin (OnPush, TrackBy,
|
|
76
87
|
* performance, RxJS and others).
|
|
77
88
|
*/
|
|
78
89
|
export declare class ScanAngularTool implements MCPTool {
|
|
@@ -115,6 +126,12 @@ export declare class ScanAngularTool implements MCPTool {
|
|
|
115
126
|
description: string;
|
|
116
127
|
default: string[];
|
|
117
128
|
};
|
|
129
|
+
cache: {
|
|
130
|
+
readonly type: "string";
|
|
131
|
+
readonly enum: readonly ["use", "refresh"];
|
|
132
|
+
readonly default: "use";
|
|
133
|
+
readonly description: "use: serve unchanged files from the scan cache (default); refresh: ignore the existing entries, analyze every file and overwrite them. Read from the call only, never from the tools section of .angular-modernizer.json";
|
|
134
|
+
};
|
|
118
135
|
includeAutoFixes: {
|
|
119
136
|
type: string;
|
|
120
137
|
description: string;
|
|
@@ -136,17 +153,19 @@ export declare class ScanAngularTool implements MCPTool {
|
|
|
136
153
|
default: number;
|
|
137
154
|
};
|
|
138
155
|
orchestration: {
|
|
139
|
-
type:
|
|
140
|
-
description:
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
156
|
+
readonly type: "object";
|
|
157
|
+
readonly description: "Deprecated, no effect, kept in 2.x: the scan always runs in the scan worker and answers with a notice in warnings. Leave unset.";
|
|
158
|
+
readonly deprecated: true;
|
|
159
|
+
readonly properties: {
|
|
160
|
+
readonly parallel: {
|
|
161
|
+
readonly type: "boolean";
|
|
162
|
+
readonly description: "Deprecated, no effect.";
|
|
163
|
+
readonly deprecated: true;
|
|
146
164
|
};
|
|
147
|
-
maxWorkers: {
|
|
148
|
-
type:
|
|
149
|
-
description:
|
|
165
|
+
readonly maxWorkers: {
|
|
166
|
+
readonly type: "number";
|
|
167
|
+
readonly description: "Deprecated, no effect.";
|
|
168
|
+
readonly deprecated: true;
|
|
150
169
|
};
|
|
151
170
|
};
|
|
152
171
|
};
|
|
@@ -164,8 +183,8 @@ export declare class ScanAngularTool implements MCPTool {
|
|
|
164
183
|
};
|
|
165
184
|
execute(args: Record<string, unknown>, ctx?: ToolContext): Promise<ScanAngularResult>;
|
|
166
185
|
/**
|
|
167
|
-
*
|
|
168
|
-
*
|
|
186
|
+
* The `tools['scan-angular']` section of `.angular-modernizer.json`; arguments of
|
|
187
|
+
* the call override it.
|
|
169
188
|
*/
|
|
170
189
|
private loadConfig;
|
|
171
190
|
private calculateSummary;
|