@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,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-solid tool. */
|
|
5
6
|
export interface ScanSolidResult {
|
|
6
7
|
/** The requested page of violations (`maxResults`, `resultOffset`). */
|
|
@@ -41,7 +42,17 @@ export interface ScanSolidResult {
|
|
|
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 ScanSolidResult {
|
|
|
72
83
|
}
|
|
73
84
|
/**
|
|
74
85
|
* MCP tool `scan-solid`: scans for SOLID principle violations. Runs only the
|
|
75
|
-
* SolidPlugin (
|
|
86
|
+
* rules of the SolidPlugin (DIP, SRP, LSP, OCP, ISP).
|
|
76
87
|
*/
|
|
77
88
|
export declare class ScanSolidTool implements MCPTool {
|
|
78
89
|
readonly name = "scan-solid";
|
|
@@ -114,6 +125,12 @@ export declare class ScanSolidTool implements MCPTool {
|
|
|
114
125
|
description: string;
|
|
115
126
|
default: string[];
|
|
116
127
|
};
|
|
128
|
+
cache: {
|
|
129
|
+
readonly type: "string";
|
|
130
|
+
readonly enum: readonly ["use", "refresh"];
|
|
131
|
+
readonly default: "use";
|
|
132
|
+
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";
|
|
133
|
+
};
|
|
117
134
|
includeAutoFixes: {
|
|
118
135
|
type: string;
|
|
119
136
|
description: string;
|
|
@@ -135,17 +152,19 @@ export declare class ScanSolidTool implements MCPTool {
|
|
|
135
152
|
default: number;
|
|
136
153
|
};
|
|
137
154
|
orchestration: {
|
|
138
|
-
type:
|
|
139
|
-
description:
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
155
|
+
readonly type: "object";
|
|
156
|
+
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.";
|
|
157
|
+
readonly deprecated: true;
|
|
158
|
+
readonly properties: {
|
|
159
|
+
readonly parallel: {
|
|
160
|
+
readonly type: "boolean";
|
|
161
|
+
readonly description: "Deprecated, no effect.";
|
|
162
|
+
readonly deprecated: true;
|
|
145
163
|
};
|
|
146
|
-
maxWorkers: {
|
|
147
|
-
type:
|
|
148
|
-
description:
|
|
164
|
+
readonly maxWorkers: {
|
|
165
|
+
readonly type: "number";
|
|
166
|
+
readonly description: "Deprecated, no effect.";
|
|
167
|
+
readonly deprecated: true;
|
|
149
168
|
};
|
|
150
169
|
};
|
|
151
170
|
};
|
|
@@ -163,8 +182,8 @@ export declare class ScanSolidTool implements MCPTool {
|
|
|
163
182
|
};
|
|
164
183
|
execute(args: Record<string, unknown>, ctx?: ToolContext): Promise<ScanSolidResult>;
|
|
165
184
|
/**
|
|
166
|
-
*
|
|
167
|
-
*
|
|
185
|
+
* The `tools['scan-solid']` section of `.angular-modernizer.json`; arguments of
|
|
186
|
+
* the call override it.
|
|
168
187
|
*/
|
|
169
188
|
private loadConfig;
|
|
170
189
|
private calculateSummary;
|
package/dist/tools/scan-solid.js
CHANGED
|
@@ -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-solid`: scans for SOLID principle violations. Runs only the
|
|
11
|
-
* SolidPlugin (
|
|
13
|
+
* rules of the SolidPlugin (DIP, SRP, LSP, OCP, ISP).
|
|
12
14
|
*/
|
|
13
15
|
export class ScanSolidTool {
|
|
14
16
|
name = 'scan-solid';
|
|
@@ -36,7 +38,7 @@ export class ScanSolidTool {
|
|
|
36
38
|
rules: {
|
|
37
39
|
type: 'array',
|
|
38
40
|
items: { type: 'string' },
|
|
39
|
-
description: '
|
|
41
|
+
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',
|
|
40
42
|
},
|
|
41
43
|
includePatterns: {
|
|
42
44
|
type: 'array',
|
|
@@ -59,6 +61,7 @@ export class ScanSolidTool {
|
|
|
59
61
|
'**/*.test.ts',
|
|
60
62
|
],
|
|
61
63
|
},
|
|
64
|
+
cache: SCAN_CACHE_MODE_SCHEMA,
|
|
62
65
|
includeAutoFixes: {
|
|
63
66
|
type: 'boolean',
|
|
64
67
|
description: 'Whether to include auto-fix suggestions',
|
|
@@ -79,21 +82,7 @@ export class ScanSolidTool {
|
|
|
79
82
|
description: 'Offset for result pagination',
|
|
80
83
|
default: 0,
|
|
81
84
|
},
|
|
82
|
-
orchestration:
|
|
83
|
-
type: 'object',
|
|
84
|
-
description: 'Advanced orchestration options',
|
|
85
|
-
properties: {
|
|
86
|
-
parallel: {
|
|
87
|
-
type: 'boolean',
|
|
88
|
-
description: 'Enable parallel rule execution',
|
|
89
|
-
default: false,
|
|
90
|
-
},
|
|
91
|
-
maxWorkers: {
|
|
92
|
-
type: 'number',
|
|
93
|
-
description: 'Maximum concurrent workers',
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
},
|
|
85
|
+
orchestration: DEPRECATED_SCAN_ORCHESTRATION_SCHEMA,
|
|
97
86
|
},
|
|
98
87
|
required: ['rootPath'],
|
|
99
88
|
};
|
|
@@ -106,7 +95,10 @@ export class ScanSolidTool {
|
|
|
106
95
|
const params = args;
|
|
107
96
|
const config = this.loadConfig(params.rootPath);
|
|
108
97
|
const mergedParams = { ...config, ...params };
|
|
109
|
-
|
|
98
|
+
// `rules` selects the rules that run (E-19), not only the reported findings
|
|
99
|
+
const ruleSelection = mergedParams.rules?.length ? mergedParams.rules : undefined;
|
|
100
|
+
// orchestration has no effect: the scan always runs in the scan worker
|
|
101
|
+
const notices = mergedParams.orchestration === undefined ? [] : [SCAN_ORCHESTRATION_NOTICE];
|
|
110
102
|
if (!mergedParams.rootPath) {
|
|
111
103
|
throw new Error('rootPath is required');
|
|
112
104
|
}
|
|
@@ -133,6 +125,8 @@ export class ScanSolidTool {
|
|
|
133
125
|
cwd: mergedParams.rootPath,
|
|
134
126
|
absolute: true,
|
|
135
127
|
ignore: excludePatterns,
|
|
128
|
+
// A directory named like a source file (`scaleData.ts/`) is no file
|
|
129
|
+
nodir: true,
|
|
136
130
|
});
|
|
137
131
|
allFiles.push(...files);
|
|
138
132
|
}
|
|
@@ -140,12 +134,19 @@ export class ScanSolidTool {
|
|
|
140
134
|
const uniqueFiles = Array.from(new Set(allFiles)).sort();
|
|
141
135
|
const filesToAnalyze = uniqueFiles; // Analyze ALL files found (batch processing prevents memory issues)
|
|
142
136
|
const maxFiles = mergedParams.maxFiles ?? 100; // Batch size (default 100)
|
|
143
|
-
|
|
137
|
+
// Library resolution state before the cache read: it is part of the
|
|
138
|
+
// cache version, so entries of another node_modules state are not served
|
|
139
|
+
const libraryCheck = await (await import('./helpers/library-imports.js')).checkScanScope(tsConfigPath, filesToAnalyze);
|
|
140
|
+
const cache = await openToolCache(mergedParams.rootPath, 'solid', scanCacheVersion(SCAN_TOOL_CACHE_VERSION, mergedParams.rootPath, ruleSelection, {
|
|
141
|
+
includePatterns: mergedParams.includePatterns,
|
|
142
|
+
excludePatterns: mergedParams.excludePatterns,
|
|
143
|
+
unresolvedPackages: libraryCheck.packages,
|
|
144
|
+
}));
|
|
144
145
|
// ============================================================================
|
|
145
146
|
// CACHE READ SYSTEM
|
|
146
147
|
// ============================================================================
|
|
147
148
|
// Before analyzing files, check if cached results exist for unchanged files.
|
|
148
|
-
//
|
|
149
|
+
// A warm run analyzes only new and changed files.
|
|
149
150
|
//
|
|
150
151
|
// How it works:
|
|
151
152
|
// 1. For each file, check if cache entry exists via CacheManager.getAnalysisResult()
|
|
@@ -153,27 +154,29 @@ export class ScanSolidTool {
|
|
|
153
154
|
// 3. If cached AND unchanged → reuse cached results
|
|
154
155
|
// 4. If not cached OR changed → add to filesToProcess for analysis
|
|
155
156
|
//
|
|
156
|
-
// Performance results (real-world validation on 2,758 files):
|
|
157
|
-
// - First run: 62.7s (analyzes all files, writes cache)
|
|
158
|
-
// - Second run: 42.4s (1.5x speedup, 32% faster, reads from cache)
|
|
159
|
-
//
|
|
160
157
|
// Cache directory: .angular-modernizer-cache/solid/
|
|
161
158
|
// Cache invalidation: Automatic via mtime/content hash checking
|
|
162
159
|
// ============================================================================
|
|
163
|
-
|
|
160
|
+
// Findings per analyzed file, from the cache or the scan
|
|
161
|
+
const findingsByFile = new Map();
|
|
162
|
+
let cachedFindings = 0;
|
|
164
163
|
const filesToProcess = [];
|
|
164
|
+
// One entry per analyzed file, also without findings: findings on its
|
|
165
|
+
// template stay with the component file, the template is a dependency.
|
|
166
|
+
// refresh analyzes every file; the write below overwrites the entries
|
|
167
|
+
const cacheMode = scanCacheMode(args);
|
|
165
168
|
for (const filePath of filesToAnalyze) {
|
|
166
|
-
const cached = await
|
|
167
|
-
if (cached
|
|
168
|
-
|
|
169
|
-
|
|
169
|
+
const cached = cacheMode === 'refresh' ? null : await readCachedFindings(filePath, cache);
|
|
170
|
+
if (cached !== null) {
|
|
171
|
+
findingsByFile.set(filePath, cached);
|
|
172
|
+
cachedFindings += cached.length;
|
|
170
173
|
}
|
|
171
174
|
else {
|
|
172
175
|
// File not cached or has changed
|
|
173
176
|
filesToProcess.push(filePath);
|
|
174
177
|
}
|
|
175
178
|
}
|
|
176
|
-
console.info(`Cache: ${
|
|
179
|
+
console.info(`Cache: ${cachedFindings} results from cache, ${filesToProcess.length} files to analyze (hit rate: ${cache.getStats().hitRate.toFixed(1)}%)`);
|
|
177
180
|
// ============================================================================
|
|
178
181
|
// BATCH PROCESSING SYSTEM
|
|
179
182
|
// ============================================================================
|
|
@@ -205,14 +208,16 @@ export class ScanSolidTool {
|
|
|
205
208
|
const totalFiles = filesToProcess.length;
|
|
206
209
|
const totalBatches = Math.ceil(totalFiles / batchSize);
|
|
207
210
|
console.info(`\nProcessing ${totalFiles} files in ${totalBatches} batch(es) of ${batchSize} files each`);
|
|
208
|
-
//
|
|
209
|
-
const
|
|
210
|
-
let
|
|
211
|
+
// Per newly analyzed file its findings (also those on its template) and template files
|
|
212
|
+
const entriesForCache = new Map();
|
|
213
|
+
let newFindings = 0;
|
|
211
214
|
// Kernel, batches and rules run in a scan worker (scan-host), so the
|
|
212
215
|
// server keeps reading stdin while the type checker is built.
|
|
213
216
|
const cachedFiles = filesToAnalyze.length - totalFiles;
|
|
214
217
|
let processedFiles = 0;
|
|
218
|
+
let lastReported;
|
|
215
219
|
if (totalFiles > 0) {
|
|
220
|
+
lastReported = cachedFiles;
|
|
216
221
|
ctx.progress?.(cachedFiles, filesToAnalyze.length, `loading project, ${totalFiles} files to analyze`);
|
|
217
222
|
}
|
|
218
223
|
const engine = await runScan({
|
|
@@ -223,19 +228,28 @@ export class ScanSolidTool {
|
|
|
223
228
|
files: filesToProcess,
|
|
224
229
|
mode: 'batches',
|
|
225
230
|
batchSize,
|
|
226
|
-
|
|
231
|
+
templateDependencies: true,
|
|
232
|
+
contextFiles: filesToAnalyze,
|
|
233
|
+
...(ruleSelection === undefined ? {} : { ruleIds: ruleSelection }),
|
|
227
234
|
}, {
|
|
228
235
|
file: (event) => {
|
|
229
|
-
|
|
236
|
+
entriesForCache.set(event.filePath, {
|
|
237
|
+
results: event.findings,
|
|
238
|
+
dependencies: event.dependencies ?? [],
|
|
239
|
+
});
|
|
240
|
+
findingsByFile.set(event.filePath, event.findings);
|
|
241
|
+
newFindings += event.findings.length;
|
|
230
242
|
processedFiles++;
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
batchDone: (files) => {
|
|
234
|
-
filesAnalyzed += files;
|
|
243
|
+
lastReported = cachedFiles + processedFiles;
|
|
244
|
+
ctx.progress?.(cachedFiles + processedFiles, filesToAnalyze.length, fileProgressMessage(cachedFiles + processedFiles, filesToAnalyze.length, cachedFindings + newFindings));
|
|
235
245
|
},
|
|
236
246
|
}, { signal: ctx.signal });
|
|
237
247
|
const cancelled = engine.cancelled;
|
|
238
|
-
|
|
248
|
+
if (!cancelled) {
|
|
249
|
+
finalFileProgress(ctx.progress, filesToAnalyze.length, cachedFiles + processedFiles, cachedFindings + newFindings, lastReported);
|
|
250
|
+
}
|
|
251
|
+
const results = findingsInFileOrder(findingsByFile);
|
|
252
|
+
console.info(`\nBatch processing complete: ${totalBatches} batch(es), ${cachedFiles + processedFiles} total files analyzed, ${results.length} total violations`);
|
|
239
253
|
// ============================================================================
|
|
240
254
|
// CACHE WRITE SYSTEM
|
|
241
255
|
// ============================================================================
|
|
@@ -243,9 +257,11 @@ export class ScanSolidTool {
|
|
|
243
257
|
// This enables cache reads to skip unchanged files on subsequent runs.
|
|
244
258
|
//
|
|
245
259
|
// How it works:
|
|
246
|
-
// 1.
|
|
247
|
-
//
|
|
260
|
+
// 1. One cache entry per analyzed file, also without findings, holding all
|
|
261
|
+
// of its findings (also those reported on its template)
|
|
262
|
+
// 2. Write each entry via CacheManager.setAnalysisResult()
|
|
248
263
|
// 3. CacheManager stores: results[], metadata (mtime, hash, size), dependencies
|
|
264
|
+
// (the template files)
|
|
249
265
|
//
|
|
250
266
|
// Why plugin-specific cache directories?
|
|
251
267
|
// - Each scan tool (scan-solid, scan-angular, scan-architecture, scan-all) uses
|
|
@@ -260,27 +276,17 @@ export class ScanSolidTool {
|
|
|
260
276
|
// dependencies: []
|
|
261
277
|
// }
|
|
262
278
|
//
|
|
263
|
-
//
|
|
264
|
-
// - First run: Writes cache (adds ~1-2% overhead)
|
|
265
|
-
// - Second run: Reads cache (1.5x-39x speedup depending on scan type)
|
|
279
|
+
// A cache hit skips the analysis of the file by every rule.
|
|
266
280
|
// ============================================================================
|
|
267
|
-
//
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
if (!resultsByFile.has(filePath)) {
|
|
273
|
-
resultsByFile.set(filePath, []);
|
|
274
|
-
}
|
|
275
|
-
resultsByFile.get(filePath).push(result);
|
|
276
|
-
}
|
|
277
|
-
// Write each file's results to cache
|
|
278
|
-
for (const [filePath, fileResults] of resultsByFile.entries()) {
|
|
279
|
-
await cache.setAnalysisResult(filePath, fileResults);
|
|
281
|
+
// A cancelled scan writes nothing: files analyzed before the cancel saw only
|
|
282
|
+
// part of the project, so cross-file and template findings could differ from
|
|
283
|
+
// a full run and a later warm run would serve them as current.
|
|
284
|
+
for (const [filePath, entry] of cancelled ? [] : entriesForCache) {
|
|
285
|
+
await cache.setAnalysisResult(filePath, entry.results, entry.dependencies);
|
|
280
286
|
}
|
|
281
287
|
// Log cache effectiveness
|
|
282
288
|
const stats = cache.getStats();
|
|
283
|
-
console.info(`Cached ${
|
|
289
|
+
console.info(`Cached ${cancelled ? 0 : entriesForCache.size} files (hit rate: ${stats.hitRate.toFixed(1)}%)`);
|
|
284
290
|
// Filter by specific rules if requested
|
|
285
291
|
let violations = results
|
|
286
292
|
.filter((r) => r.ruleId && r.filePath)
|
|
@@ -307,7 +313,8 @@ export class ScanSolidTool {
|
|
|
307
313
|
const maxResults = mergedParams.maxResults ?? 1000;
|
|
308
314
|
const paginatedViolations = violations.slice(offset, offset + maxResults);
|
|
309
315
|
// Counts cover every violation, not only the page
|
|
310
|
-
|
|
316
|
+
// A file that failed to load sends no result and is not analyzed
|
|
317
|
+
const analyzedFiles = cachedFiles + processedFiles;
|
|
311
318
|
const counts = this.calculateSummary(violations, analyzedFiles);
|
|
312
319
|
const execution = cancelled
|
|
313
320
|
? cancelledExecution(analyzedFiles, filesToAnalyze.length - analyzedFiles)
|
|
@@ -320,7 +327,7 @@ export class ScanSolidTool {
|
|
|
320
327
|
};
|
|
321
328
|
const duration = Date.now() - startTime;
|
|
322
329
|
const ruleIds = engine.ruleIds;
|
|
323
|
-
return {
|
|
330
|
+
return withLibraryImportWarning({
|
|
324
331
|
violations: paginatedViolations,
|
|
325
332
|
counts,
|
|
326
333
|
metadata: {
|
|
@@ -328,42 +335,24 @@ export class ScanSolidTool {
|
|
|
328
335
|
duration,
|
|
329
336
|
projectRoot: mergedParams.rootPath,
|
|
330
337
|
},
|
|
331
|
-
|
|
332
|
-
? {
|
|
333
|
-
parallel: true,
|
|
334
|
-
incremental: false,
|
|
335
|
-
filesAnalyzed: filesToAnalyze.length,
|
|
336
|
-
filesSkipped: 0,
|
|
337
|
-
cacheHitRate: 0,
|
|
338
|
-
duration,
|
|
339
|
-
throughput: filesToAnalyze.length / (duration / 1000),
|
|
340
|
-
}
|
|
341
|
-
: undefined,
|
|
338
|
+
...(notices.length === 0 ? {} : { warnings: notices }),
|
|
342
339
|
pagination,
|
|
343
340
|
...(execution === undefined ? {} : { execution }),
|
|
344
|
-
summary: describeScan(counts, paginatedViolations, pagination, execution === undefined ? [] : [execution.note]),
|
|
345
|
-
};
|
|
341
|
+
summary: describeScan(counts, paginatedViolations, pagination, [...notices, ...(execution === undefined ? [] : [execution.note])]),
|
|
342
|
+
}, libraryCheck.unresolved);
|
|
346
343
|
}
|
|
347
344
|
/**
|
|
348
|
-
*
|
|
349
|
-
*
|
|
345
|
+
* The `tools['scan-solid']` section of `.angular-modernizer.json`; arguments of
|
|
346
|
+
* the call override it.
|
|
350
347
|
*/
|
|
351
348
|
loadConfig(rootPath) {
|
|
352
|
-
// Ensure rootPath is provided before loading config
|
|
353
349
|
if (!rootPath) {
|
|
354
350
|
return {};
|
|
355
351
|
}
|
|
356
|
-
const configPath = resolve(rootPath, '.angular-modernizer.json');
|
|
357
|
-
if (!existsSync(configPath)) {
|
|
358
|
-
return {};
|
|
359
|
-
}
|
|
360
352
|
try {
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
const scanSolidConfig = config['scan-solid'];
|
|
365
|
-
if (scanSolidConfig && typeof scanSolidConfig === 'object') {
|
|
366
|
-
return scanSolidConfig;
|
|
353
|
+
const toolConfig = loadConfig(rootPath).tools?.['scan-solid'];
|
|
354
|
+
if (toolConfig && typeof toolConfig === 'object') {
|
|
355
|
+
return toolConfig;
|
|
367
356
|
}
|
|
368
357
|
}
|
|
369
358
|
catch (error) {
|
|
@@ -7,8 +7,10 @@ import { ProjectCache } from './helpers/project-cache.js';
|
|
|
7
7
|
export interface SearchCodebaseOutput {
|
|
8
8
|
/** Matches, at most `maxResults` (default 100). */
|
|
9
9
|
results: SearchResult[];
|
|
10
|
-
/** Number of
|
|
10
|
+
/** Number of all matches, also those `maxResults` left out of `results`. */
|
|
11
11
|
totalCount: number;
|
|
12
|
+
/** True when `maxResults` cut matches from `results`. */
|
|
13
|
+
truncated: boolean;
|
|
12
14
|
/** Short text summary of the matches. */
|
|
13
15
|
summary: string;
|
|
14
16
|
/** Which files the search covered, including the tsconfig used. */
|
|
@@ -131,6 +133,9 @@ export declare class SearchCodebaseTool implements MCPTool {
|
|
|
131
133
|
totalCount: {
|
|
132
134
|
type: string;
|
|
133
135
|
};
|
|
136
|
+
truncated: {
|
|
137
|
+
type: string;
|
|
138
|
+
};
|
|
134
139
|
summary: {
|
|
135
140
|
type: string;
|
|
136
141
|
};
|
|
@@ -74,7 +74,8 @@ export class SearchCodebaseTool {
|
|
|
74
74
|
},
|
|
75
75
|
maxResults: {
|
|
76
76
|
type: 'number',
|
|
77
|
-
description: 'Maximum number of results to return. Defaults to 100.'
|
|
77
|
+
description: 'Maximum number of results to return. Defaults to 100. totalCount still counts every match and ' +
|
|
78
|
+
'truncated is true when the list was cut.',
|
|
78
79
|
},
|
|
79
80
|
includeTemplates: {
|
|
80
81
|
type: 'boolean',
|
|
@@ -111,6 +112,7 @@ export class SearchCodebaseTool {
|
|
|
111
112
|
},
|
|
112
113
|
},
|
|
113
114
|
totalCount: { type: 'integer' },
|
|
115
|
+
truncated: { type: 'boolean' },
|
|
114
116
|
summary: { type: 'string' },
|
|
115
117
|
coverage: {
|
|
116
118
|
type: 'object',
|
|
@@ -134,7 +136,7 @@ export class SearchCodebaseTool {
|
|
|
134
136
|
},
|
|
135
137
|
...WARNINGS_OUTPUT_SCHEMA,
|
|
136
138
|
},
|
|
137
|
-
required: ['results', 'totalCount', 'summary', 'coverage'],
|
|
139
|
+
required: ['results', 'totalCount', 'truncated', 'summary', 'coverage'],
|
|
138
140
|
};
|
|
139
141
|
async execute(args, ctx = {}) {
|
|
140
142
|
const params = args;
|
|
@@ -156,7 +158,7 @@ export class SearchCodebaseTool {
|
|
|
156
158
|
}
|
|
157
159
|
const project = await acquireProject(this.projects, tsConfigPath, ctx);
|
|
158
160
|
const searcher = new CodebaseSearcher(project);
|
|
159
|
-
const { results, coverage } = searcher.searchWithCoverage(params.query, {
|
|
161
|
+
const { results, totalCount, coverage } = searcher.searchWithCoverage(params.query, {
|
|
160
162
|
mode: params.mode,
|
|
161
163
|
include: params.include,
|
|
162
164
|
maxResults: params.maxResults ?? 100,
|
|
@@ -167,8 +169,9 @@ export class SearchCodebaseTool {
|
|
|
167
169
|
const hint = results.length === 0 ? this.buildZeroHitHint(params.mode, coverage) : undefined;
|
|
168
170
|
return withWarnings({
|
|
169
171
|
results,
|
|
170
|
-
totalCount
|
|
171
|
-
|
|
172
|
+
totalCount,
|
|
173
|
+
truncated: totalCount > results.length,
|
|
174
|
+
summary: this.buildSummary(params.query, params.mode, results, totalCount, hint),
|
|
172
175
|
coverage: {
|
|
173
176
|
...coverage,
|
|
174
177
|
tsConfigPath,
|
|
@@ -196,11 +199,14 @@ export class SearchCodebaseTool {
|
|
|
196
199
|
`and ${coverage.extraFileCount} non-program file(s); excluded ${excluded.join('; ')}. ` +
|
|
197
200
|
'Verify with a raw grep if the result matters.');
|
|
198
201
|
}
|
|
199
|
-
buildSummary(query, mode, results, hint) {
|
|
202
|
+
buildSummary(query, mode, results, totalCount, hint) {
|
|
200
203
|
if (results.length === 0) {
|
|
201
204
|
return `No ${mode} matches found for '${query}'. ${hint ?? ''}`.trim();
|
|
202
205
|
}
|
|
203
|
-
|
|
206
|
+
const shown = totalCount > results.length
|
|
207
|
+
? `${results.length} of ${totalCount} ${mode} matches (cut by maxResults)`
|
|
208
|
+
: `${results.length} ${mode} match${results.length === 1 ? '' : 'es'}`;
|
|
209
|
+
return (`Found ${shown} for '${query}':\n` +
|
|
204
210
|
results
|
|
205
211
|
.slice(0, 5)
|
|
206
212
|
.map((r) => ` ${r.file}:${r.line}:${r.col} - ${r.snippet}`)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type MCPTool, type ToolAnnotations } from '../types.js';
|
|
2
2
|
import { type Performance, type Suggestion } from './helpers/suggestion-generator.js';
|
|
3
|
+
import { type SkippedRecords } from './helpers/feedback-sidecar.js';
|
|
3
4
|
/**
|
|
4
5
|
* Output from suggest-improvements tool
|
|
5
6
|
*/
|
|
@@ -16,6 +17,10 @@ export interface SuggestImprovementsOutput {
|
|
|
16
17
|
analysisFeedbackCount: number;
|
|
17
18
|
/** Locations where feedback was read from */
|
|
18
19
|
sourcesRead: string[];
|
|
20
|
+
/** Records of this rule or tool skipped because the feedback sidecar marks them (0 with `includeOutdated`) */
|
|
21
|
+
skippedRecords: SkippedRecords;
|
|
22
|
+
/** Unusable sidecar, or session files changed since refresh-state marked them */
|
|
23
|
+
sidecarWarnings?: string[];
|
|
19
24
|
/** Short text: data points, current performance and the top suggestions */
|
|
20
25
|
summary: string;
|
|
21
26
|
}
|
|
@@ -47,6 +52,11 @@ export declare class SuggestImprovementsTool implements MCPTool {
|
|
|
47
52
|
readonly type: "object";
|
|
48
53
|
readonly additionalProperties: false;
|
|
49
54
|
readonly properties: {
|
|
55
|
+
readonly includeOutdated: {
|
|
56
|
+
readonly type: "boolean";
|
|
57
|
+
readonly default: false;
|
|
58
|
+
readonly description: "Also read the records that .claude-feedback/index/consolidated.json marks as duplicate or outdated (written by refresh-state apply, part 'feedback'); default false skips them and counts them in skippedRecords";
|
|
59
|
+
};
|
|
50
60
|
readonly projectRoot: {
|
|
51
61
|
readonly type: "string";
|
|
52
62
|
readonly description: "Project root path (defaults to process.cwd() if not provided)";
|
|
@@ -77,6 +87,30 @@ export declare class SuggestImprovementsTool implements MCPTool {
|
|
|
77
87
|
outputSchema: {
|
|
78
88
|
type: string;
|
|
79
89
|
properties: {
|
|
90
|
+
summary: {
|
|
91
|
+
type: string;
|
|
92
|
+
};
|
|
93
|
+
skippedRecords: {
|
|
94
|
+
readonly type: "object";
|
|
95
|
+
readonly properties: {
|
|
96
|
+
readonly total: {
|
|
97
|
+
readonly type: "integer";
|
|
98
|
+
};
|
|
99
|
+
readonly byReason: {
|
|
100
|
+
readonly type: "object";
|
|
101
|
+
readonly additionalProperties: {
|
|
102
|
+
readonly type: "integer";
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
readonly required: readonly ["total", "byReason"];
|
|
107
|
+
};
|
|
108
|
+
sidecarWarnings: {
|
|
109
|
+
readonly type: "array";
|
|
110
|
+
readonly items: {
|
|
111
|
+
readonly type: "string";
|
|
112
|
+
};
|
|
113
|
+
};
|
|
80
114
|
ruleId: {
|
|
81
115
|
type: string;
|
|
82
116
|
};
|
|
@@ -137,9 +171,6 @@ export declare class SuggestImprovementsTool implements MCPTool {
|
|
|
137
171
|
readonly type: "string";
|
|
138
172
|
};
|
|
139
173
|
};
|
|
140
|
-
summary: {
|
|
141
|
-
type: string;
|
|
142
|
-
};
|
|
143
174
|
};
|
|
144
175
|
required: string[];
|
|
145
176
|
};
|
|
@@ -2,6 +2,7 @@ import { FeedbackStorage, loadConfig, findRepeatedToolMisses, fromLegacyAnalysis
|
|
|
2
2
|
import { calculatePerformance, generateSuggestions, } from './helpers/suggestion-generator.js';
|
|
3
3
|
import { feedbackSessionDirs, feedbackStorageConfig, resolveFeedbackRoots, } from './helpers/platform-root-resolver.js';
|
|
4
4
|
import { STRING_ARRAY } from './helpers/investigation-schemas.js';
|
|
5
|
+
import { INCLUDE_OUTDATED_SCHEMA, SKIPPED_RECORDS_OUTPUT_SCHEMA, describeSkipped, skipMarkedRecords, } from './helpers/feedback-sidecar.js';
|
|
5
6
|
/** Suggestions spelled out in the summary; the rest is in `suggestions`. */
|
|
6
7
|
const SUMMARY_SUGGESTIONS = 5;
|
|
7
8
|
/** Text summary: data points, current performance and the top suggestions. */
|
|
@@ -15,6 +16,7 @@ function describeSuggestions(output) {
|
|
|
15
16
|
for (const suggestion of output.suggestions.slice(0, SUMMARY_SUGGESTIONS)) {
|
|
16
17
|
lines.push(`- ${suggestion.type} (confidence ${suggestion.confidence.toFixed(2)}): ${suggestion.description}`);
|
|
17
18
|
}
|
|
19
|
+
lines.push(...describeSkipped(output.skippedRecords, output.sidecarWarnings ?? []));
|
|
18
20
|
return lines.join('\n');
|
|
19
21
|
}
|
|
20
22
|
/**
|
|
@@ -76,6 +78,7 @@ export class SuggestImprovementsTool {
|
|
|
76
78
|
"plus the platform store when ANGULAR_MODERNIZER_PLATFORM_ROOT is set; " +
|
|
77
79
|
"'platform' requires that variable.",
|
|
78
80
|
},
|
|
81
|
+
...INCLUDE_OUTDATED_SCHEMA,
|
|
79
82
|
},
|
|
80
83
|
required: ['ruleId'],
|
|
81
84
|
};
|
|
@@ -115,6 +118,7 @@ export class SuggestImprovementsTool {
|
|
|
115
118
|
feedbackCount: { type: 'integer' },
|
|
116
119
|
analysisFeedbackCount: { type: 'integer' },
|
|
117
120
|
sourcesRead: STRING_ARRAY,
|
|
121
|
+
...SKIPPED_RECORDS_OUTPUT_SCHEMA,
|
|
118
122
|
summary: { type: 'string' },
|
|
119
123
|
},
|
|
120
124
|
required: [
|
|
@@ -196,23 +200,42 @@ export class SuggestImprovementsTool {
|
|
|
196
200
|
const sessionIds = await feedbackStorage.listSessions();
|
|
197
201
|
// Track which locations we read from
|
|
198
202
|
const sourcesRead = feedbackSessionDirs(roots);
|
|
199
|
-
//
|
|
200
|
-
|
|
201
|
-
const
|
|
203
|
+
// Records of this rule (or analysis tool); old analysis records keep their transformation record
|
|
204
|
+
// until the sidecar marks are applied, so their stored id decides
|
|
205
|
+
const matching = new Map();
|
|
202
206
|
for (const sessionId of sessionIds) {
|
|
203
207
|
try {
|
|
204
208
|
const session = await feedbackStorage.loadSession(sessionId);
|
|
205
|
-
|
|
206
|
-
.
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
209
|
+
matching.set(sessionId, {
|
|
210
|
+
transformations: session.transformations.filter((f) => {
|
|
211
|
+
const legacy = fromLegacyAnalysisRecord(f);
|
|
212
|
+
return legacy === null
|
|
213
|
+
? f.rule.ruleId === input.ruleId
|
|
214
|
+
: legacy.tool === input.ruleId;
|
|
215
|
+
}),
|
|
216
|
+
analyses: (session.analyses ?? []).filter((a) => a.tool === input.ruleId),
|
|
217
|
+
});
|
|
211
218
|
}
|
|
212
219
|
catch {
|
|
213
220
|
// Session not found or load error, skip
|
|
214
221
|
}
|
|
215
222
|
}
|
|
223
|
+
// Records the sidecar marks (duplicates, outdated) stay out unless includeOutdated
|
|
224
|
+
const marked = skipMarkedRecords(projectRoot, matching, input.includeOutdated === true);
|
|
225
|
+
const ruleFeedback = [];
|
|
226
|
+
const toolAnalyses = [];
|
|
227
|
+
for (const session of marked.sessions) {
|
|
228
|
+
for (const record of session.transformations) {
|
|
229
|
+
const legacy = fromLegacyAnalysisRecord(record);
|
|
230
|
+
if (legacy === null) {
|
|
231
|
+
ruleFeedback.push(record);
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
toolAnalyses.push(legacy);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
toolAnalyses.push(...session.analyses);
|
|
238
|
+
}
|
|
216
239
|
// Calculate current performance
|
|
217
240
|
const currentPerformance = calculatePerformance(ruleFeedback);
|
|
218
241
|
// Generate suggestions (transformation outcomes + repeated tool misses)
|
|
@@ -228,6 +251,8 @@ export class SuggestImprovementsTool {
|
|
|
228
251
|
feedbackCount: ruleFeedback.length,
|
|
229
252
|
analysisFeedbackCount: toolAnalyses.length,
|
|
230
253
|
sourcesRead,
|
|
254
|
+
skippedRecords: marked.skipped,
|
|
255
|
+
...(marked.warnings.length === 0 ? {} : { sidecarWarnings: marked.warnings }),
|
|
231
256
|
};
|
|
232
257
|
return { ...output, summary: describeSuggestions(output) };
|
|
233
258
|
}
|