@angular-modernizer/adapter-mcp 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +81 -65
- package/dist/cli.js +8 -0
- package/dist/core/project-analyzer.d.ts +3 -12
- package/dist/core/project-analyzer.js +3 -12
- package/dist/index.d.ts +118 -3
- package/dist/index.js +46 -3
- package/dist/mcp-watcher.d.ts +28 -8
- package/dist/mcp-watcher.js +7 -7
- package/dist/scan-host/scan-host.d.ts +119 -0
- package/dist/scan-host/scan-host.js +376 -0
- package/dist/scan-host/scan-protocol.d.ts +35 -0
- package/dist/scan-host/scan-protocol.js +6 -0
- package/dist/scan-host/scan-worker.d.ts +14 -0
- package/dist/scan-host/scan-worker.js +48 -0
- package/dist/server/limited-stdio-transport.d.ts +7 -0
- package/dist/server/mcp-server.d.ts +11 -7
- package/dist/server/mcp-server.js +4 -7
- package/dist/server/sdk-server.d.ts +1 -0
- package/dist/server/tool-registry.d.ts +3 -7
- package/dist/server/tool-registry.js +1 -7
- package/dist/streaming/progress-store.d.ts +22 -5
- package/dist/streaming/progress-store.js +9 -5
- package/dist/tools/analyze-build-impact.d.ts +58 -36
- package/dist/tools/analyze-build-impact.js +36 -29
- package/dist/tools/analyze-core-to-shared.d.ts +42 -12
- package/dist/tools/analyze-core-to-shared.js +11 -10
- package/dist/tools/analyze-parser-performance.d.ts +23 -22
- package/dist/tools/analyze-parser-performance.js +20 -18
- package/dist/tools/analyze-project.d.ts +87 -14
- package/dist/tools/analyze-project.js +140 -122
- package/dist/tools/check-incremental-compatibility.d.ts +13 -11
- package/dist/tools/check-incremental-compatibility.js +11 -8
- package/dist/tools/collect-feedback.d.ts +41 -26
- package/dist/tools/collect-feedback.js +32 -23
- package/dist/tools/compare-health.d.ts +76 -19
- package/dist/tools/compare-health.js +26 -19
- package/dist/tools/extract-libraries.d.ts +44 -20
- package/dist/tools/extract-libraries.js +16 -17
- package/dist/tools/find-angular-symbol.d.ts +27 -25
- package/dist/tools/find-angular-symbol.js +19 -16
- package/dist/tools/find-component-hosts.d.ts +33 -27
- package/dist/tools/find-component-hosts.js +27 -24
- package/dist/tools/find-usages.d.ts +25 -23
- package/dist/tools/find-usages.js +21 -18
- package/dist/tools/get-bootstrap-execution.d.ts +35 -27
- package/dist/tools/get-bootstrap-execution.js +28 -25
- package/dist/tools/get-call-graph.d.ts +19 -14
- package/dist/tools/get-call-graph.js +26 -23
- package/dist/tools/get-operation-progress-tool.d.ts +12 -6
- package/dist/tools/get-operation-progress-tool.js +11 -6
- package/dist/tools/get-operation-progress.d.ts +26 -0
- package/dist/tools/helpers/analysis-output.d.ts +5 -0
- package/dist/tools/helpers/batch-kernel.d.ts +14 -0
- package/dist/tools/helpers/batch-kernel.js +12 -0
- package/dist/tools/helpers/compact-output.d.ts +2 -1
- package/dist/tools/helpers/compact-output.js +2 -1
- package/dist/tools/helpers/health-delta.d.ts +27 -14
- package/dist/tools/helpers/health-delta.js +11 -14
- package/dist/tools/helpers/project-cache.d.ts +123 -36
- package/dist/tools/helpers/project-cache.js +227 -43
- package/dist/tools/helpers/rule-runner.d.ts +23 -16
- package/dist/tools/helpers/rule-runner.js +24 -17
- package/dist/tools/helpers/scan-engine.d.ts +107 -0
- package/dist/tools/helpers/scan-engine.js +197 -0
- package/dist/tools/helpers/scan-plan.d.ts +1 -1
- package/dist/tools/helpers/scan-plan.js +1 -1
- package/dist/tools/helpers/suggestion-generator.d.ts +9 -13
- package/dist/tools/helpers/suggestion-generator.js +0 -12
- package/dist/tools/helpers/tool-cache.d.ts +11 -0
- package/dist/tools/helpers/tool-cache.js +15 -0
- package/dist/tools/helpers/tool-context.d.ts +11 -8
- package/dist/tools/helpers/tool-context.js +5 -8
- package/dist/tools/inspect-form-group.d.ts +34 -27
- package/dist/tools/inspect-form-group.js +27 -24
- package/dist/tools/inspect-i18n.d.ts +31 -25
- package/dist/tools/inspect-i18n.js +23 -20
- package/dist/tools/inspect-template.d.ts +32 -25
- package/dist/tools/inspect-template.js +26 -23
- package/dist/tools/learn-patterns.d.ts +88 -12
- package/dist/tools/learn-patterns.js +17 -11
- package/dist/tools/list-imports.d.ts +45 -28
- package/dist/tools/list-imports.js +26 -23
- package/dist/tools/orchestrate-migration.d.ts +31 -9
- package/dist/tools/orchestrate-migration.js +12 -7
- package/dist/tools/parse-stack-trace.d.ts +23 -21
- package/dist/tools/parse-stack-trace.js +10 -7
- package/dist/tools/plan-migration.d.ts +67 -27
- package/dist/tools/plan-migration.js +22 -21
- package/dist/tools/resolve-type.d.ts +20 -10
- package/dist/tools/resolve-type.js +21 -13
- package/dist/tools/review-feedback.d.ts +27 -24
- package/dist/tools/review-feedback.js +24 -20
- package/dist/tools/rollback-changes.d.ts +13 -9
- package/dist/tools/rollback-changes.js +10 -7
- package/dist/tools/run-angular-cli.d.ts +12 -10
- package/dist/tools/run-angular-cli.js +11 -8
- package/dist/tools/run-build.d.ts +13 -11
- package/dist/tools/run-build.js +11 -8
- package/dist/tools/run-schematic.d.ts +12 -10
- package/dist/tools/run-schematic.js +11 -8
- package/dist/tools/scan-all.d.ts +69 -12
- package/dist/tools/scan-all.js +55 -122
- package/dist/tools/scan-angular.d.ts +41 -9
- package/dist/tools/scan-angular.js +66 -135
- package/dist/tools/scan-architecture.d.ts +75 -14
- package/dist/tools/scan-architecture.js +180 -185
- package/dist/tools/scan-solid.d.ts +40 -9
- package/dist/tools/scan-solid.js +64 -133
- package/dist/tools/search-codebase.d.ts +32 -26
- package/dist/tools/search-codebase.js +15 -12
- package/dist/tools/server-status.d.ts +116 -24
- package/dist/tools/server-status.js +85 -26
- package/dist/tools/suggest-improvements.d.ts +22 -19
- package/dist/tools/suggest-improvements.js +21 -17
- package/dist/tools/trace-output-flow.d.ts +34 -27
- package/dist/tools/trace-output-flow.js +27 -24
- package/dist/tools/transform-code.d.ts +71 -10
- package/dist/tools/transform-code.js +148 -54
- package/dist/tools/validate-before-transform.d.ts +24 -9
- package/dist/tools/validate-before-transform.js +10 -7
- package/dist/tools/validate-project-compatibility.d.ts +18 -13
- package/dist/tools/validate-project-compatibility.js +17 -11
- package/dist/tools/validate-transformation.d.ts +28 -11
- package/dist/tools/validate-transformation.js +14 -8
- package/dist/tools/verify-citations.d.ts +37 -16
- package/dist/tools/verify-citations.js +19 -16
- package/dist/types.d.ts +40 -10
- package/dist/types.js +0 -5
- package/package.json +12 -18
- package/dist/tools/shared/scan-types.d.ts +0 -200
- package/dist/tools/shared/scan-types.js +0 -7
|
@@ -1,18 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @angular-modernizer/adapter-mcp - Rule runner for scan tools
|
|
3
|
-
*
|
|
4
|
-
* Runs analysis rules over a file list with a time budget:
|
|
5
|
-
* - all files are added to the project first, so project-wide rules
|
|
6
|
-
* (library extraction, circular dependencies, type resolution) see the same,
|
|
7
|
-
* complete project for every file instead of a prefix that grows per file;
|
|
8
|
-
* the load yields and checks the signal per file as well
|
|
9
|
-
* - the budget and the abort signal are checked between files; a rule that
|
|
10
|
-
* is running cannot be interrupted (analysis is synchronous CPU work), so
|
|
11
|
-
* the overrun is at most one file. With a signal the loop yields to the
|
|
12
|
-
* event loop once per file, otherwise `notifications/cancelled` is not read
|
|
13
|
-
* before the scan ends
|
|
14
|
-
* - time per rule is recorded so slow rules show up in the result
|
|
15
|
-
*/
|
|
16
1
|
import { ContextFactory, } from '@angular-modernizer/plugin-system';
|
|
17
2
|
import { yieldIfCancellable } from './tool-context.js';
|
|
18
3
|
import { loadSourceFiles } from './load-source-files.js';
|
|
@@ -30,6 +15,21 @@ export function parseMaxDurationMs(value) {
|
|
|
30
15
|
}
|
|
31
16
|
return value;
|
|
32
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Runs analysis rules over a file list with a time budget.
|
|
20
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
* - All files are added to the project first, so project-wide rules
|
|
23
|
+
* (library extraction, circular dependencies, type resolution) see the same,
|
|
24
|
+
* complete project for every file instead of a prefix that grows per file;
|
|
25
|
+
* the load yields and checks the signal per file as well.
|
|
26
|
+
* - The budget and the abort signal are checked between files; a rule that
|
|
27
|
+
* is running cannot be interrupted (analysis is synchronous CPU work), so
|
|
28
|
+
* the overrun is at most one file. With a signal the loop yields to the
|
|
29
|
+
* event loop once per file, otherwise `notifications/cancelled` is not read
|
|
30
|
+
* before the scan ends.
|
|
31
|
+
* - Time per rule is recorded so slow rules show up in the result.
|
|
32
|
+
*/
|
|
33
33
|
export async function runRulesOverFiles(options) {
|
|
34
34
|
const startTime = options.startTime ?? Date.now();
|
|
35
35
|
const budget = options.maxDurationMs ?? DEFAULT_MAX_DURATION_MS;
|
|
@@ -55,6 +55,7 @@ export async function runRulesOverFiles(options) {
|
|
|
55
55
|
const violations = [];
|
|
56
56
|
const timings = new Map();
|
|
57
57
|
let filesAnalyzed = 0;
|
|
58
|
+
let violationCount = 0;
|
|
58
59
|
let stopReason;
|
|
59
60
|
for (const sourceFile of sourceFiles) {
|
|
60
61
|
await yieldIfCancellable(options.signal);
|
|
@@ -66,6 +67,7 @@ export async function runRulesOverFiles(options) {
|
|
|
66
67
|
stopReason = 'time-budget';
|
|
67
68
|
break;
|
|
68
69
|
}
|
|
70
|
+
const fileViolations = [];
|
|
69
71
|
try {
|
|
70
72
|
for (const rule of rules) {
|
|
71
73
|
const ruleStart = Date.now();
|
|
@@ -77,15 +79,20 @@ export async function runRulesOverFiles(options) {
|
|
|
77
79
|
}));
|
|
78
80
|
timings.set(rule.id, (timings.get(rule.id) ?? 0) + Date.now() - ruleStart);
|
|
79
81
|
for (const result of results) {
|
|
80
|
-
|
|
82
|
+
fileViolations.push(toViolation(rule, result));
|
|
81
83
|
}
|
|
82
84
|
}
|
|
83
85
|
}
|
|
84
86
|
catch (error) {
|
|
85
87
|
console.warn(`Error analyzing ${sourceFile.getFilePath()}:`, error);
|
|
86
88
|
}
|
|
89
|
+
if (options.collect !== false) {
|
|
90
|
+
violations.push(...fileViolations);
|
|
91
|
+
}
|
|
92
|
+
violationCount += fileViolations.length;
|
|
87
93
|
filesAnalyzed++;
|
|
88
|
-
options.
|
|
94
|
+
options.onFileResults?.(sourceFile.getFilePath(), fileViolations);
|
|
95
|
+
options.onFileAnalyzed?.(filesAnalyzed, sourceFiles.length, violationCount);
|
|
89
96
|
}
|
|
90
97
|
return {
|
|
91
98
|
violations,
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/adapter-mcp - Analysis part of the scan tools
|
|
3
|
+
*
|
|
4
|
+
* The part of a scan between "build the kernel" and "all files analyzed":
|
|
5
|
+
* kernel, project, rules, file loading and rule runs. It runs in a scan worker
|
|
6
|
+
* (`scan-host/`) or, as fallback and under Jest, in the calling thread; both
|
|
7
|
+
* paths run this function, so they produce the same findings in the same
|
|
8
|
+
* order. Glob, scan cache, result window, progress and the MCP protocol stay
|
|
9
|
+
* with the tool on the main thread.
|
|
10
|
+
*
|
|
11
|
+
* The engine does not write to disk (the kernel gets no cache config), so a
|
|
12
|
+
* worker killed in the middle leaves nothing half written.
|
|
13
|
+
*/
|
|
14
|
+
import { type RuleRunResult, type RuleRunnerViolation } from './rule-runner.js';
|
|
15
|
+
/** Plugins a scan runs. */
|
|
16
|
+
export type ScanPluginSet = 'all' | 'solid' | 'angular' | 'architecture' | 'analyzer';
|
|
17
|
+
/**
|
|
18
|
+
* What to analyze and how. Plain data: it is the `workerData` of a scan
|
|
19
|
+
* worker.
|
|
20
|
+
*/
|
|
21
|
+
export interface ScanSpec {
|
|
22
|
+
/** Tool name, for logs and server-status. */
|
|
23
|
+
tool: string;
|
|
24
|
+
plugins: ScanPluginSet;
|
|
25
|
+
tsConfigPath: string;
|
|
26
|
+
/** Root whose `.angular-modernizer.json` supplies the rule configuration. */
|
|
27
|
+
rootPath: string;
|
|
28
|
+
/** Files to analyze, absolute, in analysis order. */
|
|
29
|
+
files: string[];
|
|
30
|
+
/**
|
|
31
|
+
* - `batches`: per batch remove all files, add the batch, analyze it
|
|
32
|
+
* (scan-all, scan-solid, scan-angular).
|
|
33
|
+
* - `runner`: add all files, then run the rules with the time budget
|
|
34
|
+
* (scan-architecture).
|
|
35
|
+
* - `sequential`: project from the tsconfig, files added one by one
|
|
36
|
+
* (analyze-project).
|
|
37
|
+
*/
|
|
38
|
+
mode: 'batches' | 'runner' | 'sequential';
|
|
39
|
+
/** Batch size of `batches`. */
|
|
40
|
+
batchSize?: number;
|
|
41
|
+
/**
|
|
42
|
+
* `batches`: analyze every file the project holds after the load
|
|
43
|
+
* (scan-solid, scan-angular) instead of the loaded ones (scan-all).
|
|
44
|
+
*/
|
|
45
|
+
analyzeProjectFiles?: boolean;
|
|
46
|
+
/** Record the template dependencies of each analyzed file (scan-all cache). */
|
|
47
|
+
templateDependencies?: boolean;
|
|
48
|
+
/** `runner`: run only these rules; none left is an error. */
|
|
49
|
+
ruleIds?: string[];
|
|
50
|
+
/** `runner`: time budget in ms, `0` disables it. */
|
|
51
|
+
maxDurationMs?: number;
|
|
52
|
+
/** `runner`: start of the budget (epoch ms). */
|
|
53
|
+
startTime?: number;
|
|
54
|
+
}
|
|
55
|
+
/** A finding as the scans collect it. */
|
|
56
|
+
export interface ScanFinding {
|
|
57
|
+
/** Set by the `runner` mode only. */
|
|
58
|
+
id?: string;
|
|
59
|
+
ruleId: string;
|
|
60
|
+
severity: RuleRunnerViolation['severity'];
|
|
61
|
+
message: string;
|
|
62
|
+
filePath: string;
|
|
63
|
+
line?: number;
|
|
64
|
+
column?: number;
|
|
65
|
+
category: string;
|
|
66
|
+
suggestedFix?: string;
|
|
67
|
+
metadata?: Record<string, unknown>;
|
|
68
|
+
}
|
|
69
|
+
/** Findings of one analyzed file. */
|
|
70
|
+
export interface ScanFileEvent {
|
|
71
|
+
/** The analyzed file. */
|
|
72
|
+
filePath: string;
|
|
73
|
+
/** Its findings, in rule order; they may point at other files (templates). */
|
|
74
|
+
findings: ScanFinding[];
|
|
75
|
+
/** Template dependencies, only with {@link ScanSpec.templateDependencies}. */
|
|
76
|
+
dependencies?: string[];
|
|
77
|
+
}
|
|
78
|
+
/** Receives the engine's output as it is produced. */
|
|
79
|
+
export interface ScanSink {
|
|
80
|
+
/** Rules are known (after `kernel.initialize()`). */
|
|
81
|
+
ready?(ruleIds: string[]): void;
|
|
82
|
+
/** One file is analyzed. */
|
|
83
|
+
file(event: ScanFileEvent): void;
|
|
84
|
+
/** `batches`: a batch of `files` files is done, failed loads included. */
|
|
85
|
+
batchDone?(files: number): void;
|
|
86
|
+
}
|
|
87
|
+
/** How the `runner` mode ended: the rule runner result without findings. */
|
|
88
|
+
export type ScanRunSummary = Omit<RuleRunResult, 'violations'>;
|
|
89
|
+
/** End of a scan run. */
|
|
90
|
+
export interface ScanEngineResult {
|
|
91
|
+
/** `true` when a cancel stopped the run. */
|
|
92
|
+
cancelled: boolean;
|
|
93
|
+
/** Ids of the rules that ran; empty when the run stopped before they were known. */
|
|
94
|
+
ruleIds: string[];
|
|
95
|
+
/** `runner` mode only. */
|
|
96
|
+
run?: ScanRunSummary;
|
|
97
|
+
}
|
|
98
|
+
/** Cancellation of an in-thread run; a worker is terminated instead. */
|
|
99
|
+
export interface ScanControl {
|
|
100
|
+
/** Yields once per file and stops when aborted. */
|
|
101
|
+
signal?: AbortSignal;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Runs the analysis part of a scan and reports each analyzed file to `sink`.
|
|
105
|
+
*/
|
|
106
|
+
export declare function runScanEngine(spec: ScanSpec, sink: ScanSink, control?: ScanControl): Promise<ScanEngineResult>;
|
|
107
|
+
//# sourceMappingURL=scan-engine.d.ts.map
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/adapter-mcp - Analysis part of the scan tools
|
|
3
|
+
*
|
|
4
|
+
* The part of a scan between "build the kernel" and "all files analyzed":
|
|
5
|
+
* kernel, project, rules, file loading and rule runs. It runs in a scan worker
|
|
6
|
+
* (`scan-host/`) or, as fallback and under Jest, in the calling thread; both
|
|
7
|
+
* paths run this function, so they produce the same findings in the same
|
|
8
|
+
* order. Glob, scan cache, result window, progress and the MCP protocol stay
|
|
9
|
+
* with the tool on the main thread.
|
|
10
|
+
*
|
|
11
|
+
* The engine does not write to disk (the kernel gets no cache config), so a
|
|
12
|
+
* worker killed in the middle leaves nothing half written.
|
|
13
|
+
*/
|
|
14
|
+
import { existsSync } from 'node:fs';
|
|
15
|
+
import { Kernel, loadConfig } from '@angular-modernizer/core';
|
|
16
|
+
import { createPublicApi } from '@angular-modernizer/api';
|
|
17
|
+
import { ContextFactory, } from '@angular-modernizer/plugin-system';
|
|
18
|
+
import { loadSourceFiles } from './load-source-files.js';
|
|
19
|
+
import { runRulesOverFiles, } from './rule-runner.js';
|
|
20
|
+
import { templateDependencies } from './scan-cache.js';
|
|
21
|
+
import { yieldIfCancellable } from './tool-context.js';
|
|
22
|
+
/**
|
|
23
|
+
* Plugins of a scan, loaded on demand: a worker loads only the plugins its
|
|
24
|
+
* scan runs (plugin-angular brings `@angular/compiler`).
|
|
25
|
+
*/
|
|
26
|
+
async function createPlugins(set) {
|
|
27
|
+
switch (set) {
|
|
28
|
+
case 'all': {
|
|
29
|
+
const [solid, angular, architecture] = await Promise.all([
|
|
30
|
+
import('@angular-modernizer/plugin-solid'),
|
|
31
|
+
import('@angular-modernizer/plugin-angular'),
|
|
32
|
+
import('@angular-modernizer/plugin-architecture'),
|
|
33
|
+
]);
|
|
34
|
+
return [
|
|
35
|
+
new solid.SolidPlugin(),
|
|
36
|
+
new angular.AngularPlugin(),
|
|
37
|
+
new architecture.ArchitecturePlugin(),
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
case 'solid':
|
|
41
|
+
return [new (await import('@angular-modernizer/plugin-solid')).SolidPlugin()];
|
|
42
|
+
case 'angular':
|
|
43
|
+
return [new (await import('@angular-modernizer/plugin-angular')).AngularPlugin()];
|
|
44
|
+
case 'architecture':
|
|
45
|
+
return [new (await import('@angular-modernizer/plugin-architecture')).ArchitecturePlugin()];
|
|
46
|
+
case 'analyzer':
|
|
47
|
+
return [new (await import('@angular-modernizer/plugin-analyzer')).AnalyzerPlugin()];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Runs the analysis part of a scan and reports each analyzed file to `sink`.
|
|
52
|
+
*/
|
|
53
|
+
export async function runScanEngine(spec, sink, control = {}) {
|
|
54
|
+
// analyze-project analyzes against the whole tsconfig program; the other
|
|
55
|
+
// scans add their files themselves (keeps dist/, e2e/ and the like out).
|
|
56
|
+
const kernel = new Kernel({
|
|
57
|
+
tsConfigPath: spec.tsConfigPath,
|
|
58
|
+
plugins: await createPlugins(spec.plugins),
|
|
59
|
+
fileSystem: undefined,
|
|
60
|
+
projectOptions: { skipAddingFilesFromTsConfig: spec.mode !== 'sequential' },
|
|
61
|
+
});
|
|
62
|
+
await kernel.initialize();
|
|
63
|
+
// The kernel's plugin instances carry the ruleConfigs of .angular-modernizer.json
|
|
64
|
+
const allRules = kernel
|
|
65
|
+
.getAllPlugins()
|
|
66
|
+
.flatMap((p) => p.getAnalysisRules());
|
|
67
|
+
const rules = spec.ruleIds === undefined
|
|
68
|
+
? allRules
|
|
69
|
+
: allRules.filter((rule) => spec.ruleIds.includes(rule.id));
|
|
70
|
+
if (rules.length === 0 && spec.mode === 'runner') {
|
|
71
|
+
throw new Error('No matching rules found');
|
|
72
|
+
}
|
|
73
|
+
const ruleIds = rules.map((r) => r.id);
|
|
74
|
+
sink.ready?.(ruleIds);
|
|
75
|
+
// Per-rule overrides of .angular-modernizer.json (BUG-3)
|
|
76
|
+
const config = (loadConfig(spec.rootPath).rules ?? {});
|
|
77
|
+
switch (spec.mode) {
|
|
78
|
+
case 'batches':
|
|
79
|
+
return runBatches(kernel, rules, config, spec, sink, control, ruleIds);
|
|
80
|
+
case 'runner':
|
|
81
|
+
return runRunner(kernel, rules, config, spec, sink, control, ruleIds);
|
|
82
|
+
case 'sequential':
|
|
83
|
+
return runSequential(kernel, rules, config, spec, sink, control, ruleIds);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async function runBatches(kernel, rules, config, spec, sink, control, ruleIds) {
|
|
87
|
+
const { signal } = control;
|
|
88
|
+
const batchSize = spec.batchSize ?? 100;
|
|
89
|
+
const totalBatches = Math.ceil(spec.files.length / batchSize);
|
|
90
|
+
const project = kernel.getProject();
|
|
91
|
+
for (let batchNum = 0; batchNum < totalBatches; batchNum++) {
|
|
92
|
+
const batchFiles = spec.files.slice(batchNum * batchSize, (batchNum + 1) * batchSize);
|
|
93
|
+
console.info(`\n${spec.tool} batch ${batchNum + 1}/${totalBatches}: ${batchFiles.length} files`);
|
|
94
|
+
// A new batch replaces the files of the previous one
|
|
95
|
+
for (const file of project.getSourceFiles()) {
|
|
96
|
+
project.removeSourceFile(file);
|
|
97
|
+
}
|
|
98
|
+
// Sorted order kept: findings must come out in the order a warm run
|
|
99
|
+
// reads them from the cache. A cancel during the load stops the scan.
|
|
100
|
+
const loaded = await loadSourceFiles(project, batchFiles, { signal });
|
|
101
|
+
if (loaded.cancelled) {
|
|
102
|
+
return { cancelled: true, ruleIds };
|
|
103
|
+
}
|
|
104
|
+
const api = createPublicApi(project);
|
|
105
|
+
const sourceFiles = spec.analyzeProjectFiles === true ? project.getSourceFiles() : loaded.sourceFiles;
|
|
106
|
+
for (const sourceFile of sourceFiles) {
|
|
107
|
+
await yieldIfCancellable(signal);
|
|
108
|
+
if (signal?.aborted === true) {
|
|
109
|
+
return { cancelled: true, ruleIds };
|
|
110
|
+
}
|
|
111
|
+
const findings = [];
|
|
112
|
+
for (const rule of rules) {
|
|
113
|
+
try {
|
|
114
|
+
const results = await rule.analyze(ContextFactory.createAnalysisContext({ sourceFile, project, api: api, config }));
|
|
115
|
+
for (const result of results) {
|
|
116
|
+
findings.push(toFinding(rule, result));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
console.warn(`Failed to analyze with rule ${rule.id}:`, error);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
sink.file(fileEvent(sourceFile, findings, spec));
|
|
124
|
+
}
|
|
125
|
+
sink.batchDone?.(batchFiles.length);
|
|
126
|
+
}
|
|
127
|
+
return { cancelled: false, ruleIds };
|
|
128
|
+
}
|
|
129
|
+
async function runRunner(kernel, rules, config, spec, sink, control, ruleIds) {
|
|
130
|
+
const project = kernel.getProject();
|
|
131
|
+
const run = await runRulesOverFiles({
|
|
132
|
+
project,
|
|
133
|
+
files: spec.files,
|
|
134
|
+
rules,
|
|
135
|
+
api: createPublicApi(project),
|
|
136
|
+
config,
|
|
137
|
+
maxDurationMs: spec.maxDurationMs,
|
|
138
|
+
startTime: spec.startTime,
|
|
139
|
+
signal: control.signal,
|
|
140
|
+
collect: false,
|
|
141
|
+
onFileResults: (filePath, violations) => sink.file({ filePath, findings: violations }),
|
|
142
|
+
});
|
|
143
|
+
const { violations: _collected, ...summary } = run;
|
|
144
|
+
return { cancelled: run.stopReason === 'cancelled', ruleIds, run: summary };
|
|
145
|
+
}
|
|
146
|
+
async function runSequential(kernel, rules, config, spec, sink, control, ruleIds) {
|
|
147
|
+
const { signal } = control;
|
|
148
|
+
const project = kernel.getProject();
|
|
149
|
+
const api = createPublicApi(project);
|
|
150
|
+
for (const filePath of spec.files) {
|
|
151
|
+
await yieldIfCancellable(signal);
|
|
152
|
+
if (signal?.aborted === true) {
|
|
153
|
+
return { cancelled: true, ruleIds };
|
|
154
|
+
}
|
|
155
|
+
// A file that fails counts as analyzed with the findings it got so far
|
|
156
|
+
const findings = [];
|
|
157
|
+
try {
|
|
158
|
+
const sourceFile = project.addSourceFileAtPath(filePath);
|
|
159
|
+
for (const rule of rules) {
|
|
160
|
+
const results = await rule.analyze(ContextFactory.createAnalysisContext({ sourceFile, project, api: api, config }));
|
|
161
|
+
for (const result of results) {
|
|
162
|
+
findings.push(toFinding(rule, result));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
console.warn(`Error analyzing ${filePath}:`, error);
|
|
168
|
+
}
|
|
169
|
+
sink.file({ filePath, findings });
|
|
170
|
+
}
|
|
171
|
+
return { cancelled: false, ruleIds };
|
|
172
|
+
}
|
|
173
|
+
function toFinding(rule, result) {
|
|
174
|
+
return {
|
|
175
|
+
ruleId: result.ruleId,
|
|
176
|
+
severity: result.severity ?? rule.severity,
|
|
177
|
+
message: result.message,
|
|
178
|
+
filePath: result.filePath,
|
|
179
|
+
line: result.line,
|
|
180
|
+
column: result.column,
|
|
181
|
+
category: rule.category,
|
|
182
|
+
suggestedFix: result.suggestedFix,
|
|
183
|
+
metadata: result.metadata,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
function fileEvent(sourceFile, findings, spec) {
|
|
187
|
+
const filePath = sourceFile.getFilePath();
|
|
188
|
+
if (spec.templateDependencies !== true) {
|
|
189
|
+
return { filePath, findings };
|
|
190
|
+
}
|
|
191
|
+
return {
|
|
192
|
+
filePath,
|
|
193
|
+
findings,
|
|
194
|
+
dependencies: templateDependencies(filePath, sourceFile.getFullText(), findings.map((f) => f.filePath), existsSync),
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
//# sourceMappingURL=scan-engine.js.map
|
|
@@ -43,6 +43,6 @@ export declare function buildScanPlan(options: {
|
|
|
43
43
|
violations: readonly ScanViolationInput[];
|
|
44
44
|
maxPhases?: number;
|
|
45
45
|
/** Project for a tsconfig, e.g. from the shared ProjectCache; a fresh Project otherwise. */
|
|
46
|
-
loadProject?: (tsConfigPath: string) => Project
|
|
46
|
+
loadProject?: (tsConfigPath: string) => Promise<Project>;
|
|
47
47
|
}): Promise<ScanPlanResult>;
|
|
48
48
|
//# sourceMappingURL=scan-plan.d.ts.map
|
|
@@ -81,7 +81,7 @@ export async function buildScanPlan(options) {
|
|
|
81
81
|
if (!tsConfigPath) {
|
|
82
82
|
throw new Error(`tsconfig.json not found in project: ${projectRoot}`);
|
|
83
83
|
}
|
|
84
|
-
const project = options.loadProject?.(tsConfigPath) ?? new Project({ tsConfigFilePath: tsConfigPath });
|
|
84
|
+
const project = (await options.loadProject?.(tsConfigPath)) ?? new Project({ tsConfigFilePath: tsConfigPath });
|
|
85
85
|
const graph = new DependencyGraphBuilder(project, { templateEdges: true });
|
|
86
86
|
await graph.buildGraph();
|
|
87
87
|
const { layers, source } = await loadLayers(projectRoot, warnings);
|
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @angular-modernizer/adapter-mcp - Suggestion Generator Helper
|
|
3
|
-
*
|
|
4
|
-
* Generates actionable rule improvement suggestions based on feedback analysis.
|
|
5
|
-
*
|
|
6
|
-
* Suggestion Logic:
|
|
7
|
-
* - Parameter adjustment: ≥3 high-confidence failures → lower threshold
|
|
8
|
-
* - Prerequisite check: ≥40% failures share common pattern → add validation
|
|
9
|
-
* - Approach change: Alternative approach has >90% success rate → switch
|
|
10
|
-
*
|
|
11
|
-
* All suggestions require human approval before implementation.
|
|
12
|
-
*/
|
|
13
1
|
import type { TransformationFeedback } from '@angular-modernizer/core';
|
|
14
2
|
/**
|
|
15
3
|
* Performance metrics for a transformation rule
|
|
@@ -23,7 +11,15 @@ export interface Performance {
|
|
|
23
11
|
qualityImprovement: number;
|
|
24
12
|
}
|
|
25
13
|
/**
|
|
26
|
-
*
|
|
14
|
+
* Rule improvement suggestion generated from feedback analysis.
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* Suggestion logic:
|
|
18
|
+
* - Parameter adjustment: ≥3 high-confidence failures → lower threshold
|
|
19
|
+
* - Prerequisite check: ≥40% failures share common pattern → add validation
|
|
20
|
+
* - Approach change: Alternative approach has >90% success rate → switch
|
|
21
|
+
*
|
|
22
|
+
* All suggestions require human approval before implementation.
|
|
27
23
|
*/
|
|
28
24
|
export interface Suggestion {
|
|
29
25
|
/** Type of suggestion */
|
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @angular-modernizer/adapter-mcp - Suggestion Generator Helper
|
|
3
|
-
*
|
|
4
|
-
* Generates actionable rule improvement suggestions based on feedback analysis.
|
|
5
|
-
*
|
|
6
|
-
* Suggestion Logic:
|
|
7
|
-
* - Parameter adjustment: ≥3 high-confidence failures → lower threshold
|
|
8
|
-
* - Prerequisite check: ≥40% failures share common pattern → add validation
|
|
9
|
-
* - Approach change: Alternative approach has >90% success rate → switch
|
|
10
|
-
*
|
|
11
|
-
* All suggestions require human approval before implementation.
|
|
12
|
-
*/
|
|
13
1
|
/**
|
|
14
2
|
* Calculate current performance metrics for a rule
|
|
15
3
|
*
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/adapter-mcp - Scan cache of the single-plugin scans
|
|
3
|
+
*
|
|
4
|
+
* scan-solid, scan-angular and scan-architecture read and write their cache
|
|
5
|
+
* on the main thread; the kernel that used to own it runs in the scan worker
|
|
6
|
+
* now and gets no cache config there.
|
|
7
|
+
*/
|
|
8
|
+
import { CacheManager } from '@angular-modernizer/core';
|
|
9
|
+
/** Opens `.angular-modernizer-cache/<tool>/` of `rootPath`. */
|
|
10
|
+
export declare function openToolCache(rootPath: string, tool: 'solid' | 'angular' | 'architecture'): Promise<CacheManager>;
|
|
11
|
+
//# sourceMappingURL=tool-cache.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/adapter-mcp - Scan cache of the single-plugin scans
|
|
3
|
+
*
|
|
4
|
+
* scan-solid, scan-angular and scan-architecture read and write their cache
|
|
5
|
+
* on the main thread; the kernel that used to own it runs in the scan worker
|
|
6
|
+
* now and gets no cache config there.
|
|
7
|
+
*/
|
|
8
|
+
import { CacheManager, RealFileSystemAdapter, createToolCacheConfig, } from '@angular-modernizer/core';
|
|
9
|
+
/** Opens `.angular-modernizer-cache/<tool>/` of `rootPath`. */
|
|
10
|
+
export async function openToolCache(rootPath, tool) {
|
|
11
|
+
const cache = new CacheManager(new RealFileSystemAdapter(), createToolCacheConfig(rootPath, tool));
|
|
12
|
+
await cache.initialize();
|
|
13
|
+
return cache;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=tool-cache.js.map
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @angular-modernizer/adapter-mcp - Helpers for the per-call tool context
|
|
3
|
-
*
|
|
4
|
-
* Analysis is synchronous CPU work: while a loop runs, the server does not
|
|
5
|
-
* read stdin, so `notifications/cancelled` only arrives once the loop gives
|
|
6
|
-
* the event loop a turn. Long loops therefore yield once per file when the
|
|
7
|
-
* call can be cancelled ({@link yieldIfCancellable}).
|
|
8
|
-
*/
|
|
9
1
|
import { type ProgressFn } from '../../types.js';
|
|
10
2
|
/** Minimum gap between two progress notifications. */
|
|
11
3
|
export declare const PROGRESS_INTERVAL_MS = 250;
|
|
@@ -18,6 +10,11 @@ export declare function throttleProgress(send: ProgressFn, intervalMs?: number,
|
|
|
18
10
|
* Gives the event loop one turn when the call can be cancelled, so a pending
|
|
19
11
|
* `notifications/cancelled` is read and `signal` aborts. Without a signal
|
|
20
12
|
* (direct calls, tests) it returns at once.
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* Analysis is synchronous CPU work: while a loop runs, the server does not
|
|
16
|
+
* read stdin, so `notifications/cancelled` only arrives once the loop gives
|
|
17
|
+
* the event loop a turn. Long loops therefore call this once per file.
|
|
21
18
|
*/
|
|
22
19
|
export declare function yieldIfCancellable(signal: AbortSignal | undefined): Promise<void>;
|
|
23
20
|
/** Progress message of a file loop: `12/40 files, 3 violations`. */
|
|
@@ -29,11 +26,17 @@ export declare function fileProgressMessage(analyzed: number, total: number, vio
|
|
|
29
26
|
export declare function fileProgress(progress: ProgressFn | undefined): ((analyzed: number, total: number, violations: number) => void) | undefined;
|
|
30
27
|
/** Execution details of a scan the client cancelled. */
|
|
31
28
|
export interface CancelledExecution {
|
|
29
|
+
/** Time budget of the scan in milliseconds, when the tool has one. */
|
|
32
30
|
maxDurationMs?: number;
|
|
31
|
+
/** Always `true`: the scan stopped early. */
|
|
33
32
|
incomplete: true;
|
|
33
|
+
/** Why the scan stopped. */
|
|
34
34
|
stopReason: 'cancelled';
|
|
35
|
+
/** Files that were not analyzed. */
|
|
35
36
|
skippedFiles: number;
|
|
37
|
+
/** Always empty for a cancelled scan. */
|
|
36
38
|
ruleTimings: [];
|
|
39
|
+
/** Human-readable note: files analyzed and skipped. */
|
|
37
40
|
note: string;
|
|
38
41
|
}
|
|
39
42
|
/**
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @angular-modernizer/adapter-mcp - Helpers for the per-call tool context
|
|
3
|
-
*
|
|
4
|
-
* Analysis is synchronous CPU work: while a loop runs, the server does not
|
|
5
|
-
* read stdin, so `notifications/cancelled` only arrives once the loop gives
|
|
6
|
-
* the event loop a turn. Long loops therefore yield once per file when the
|
|
7
|
-
* call can be cancelled ({@link yieldIfCancellable}).
|
|
8
|
-
*/
|
|
9
1
|
/** Minimum gap between two progress notifications. */
|
|
10
2
|
export const PROGRESS_INTERVAL_MS = 250;
|
|
11
3
|
/**
|
|
@@ -28,6 +20,11 @@ export function throttleProgress(send, intervalMs = PROGRESS_INTERVAL_MS, now =
|
|
|
28
20
|
* Gives the event loop one turn when the call can be cancelled, so a pending
|
|
29
21
|
* `notifications/cancelled` is read and `signal` aborts. Without a signal
|
|
30
22
|
* (direct calls, tests) it returns at once.
|
|
23
|
+
*
|
|
24
|
+
* @remarks
|
|
25
|
+
* Analysis is synchronous CPU work: while a loop runs, the server does not
|
|
26
|
+
* read stdin, so `notifications/cancelled` only arrives once the loop gives
|
|
27
|
+
* the event loop a turn. Long loops therefore call this once per file.
|
|
31
28
|
*/
|
|
32
29
|
export async function yieldIfCancellable(signal) {
|
|
33
30
|
if (signal === undefined) {
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
* @angular-modernizer/adapter-mcp - Inspect Form Group Tool
|
|
3
|
-
*
|
|
4
|
-
* MCP tool that returns the Reactive Forms of a component or service file
|
|
5
|
-
* as structure: controls with validators and initial state, and every
|
|
6
|
-
* enable/disable/validator change per control, including what an ancestor
|
|
7
|
-
* group's enable()/disable() switches with it.
|
|
8
|
-
*
|
|
9
|
-
* @remarks
|
|
10
|
-
* Logic lives in `FormGroupInspector` (`@angular-modernizer/api`); this tool
|
|
11
|
-
* resolves the project, validates arguments and applies the compact output
|
|
12
|
-
* contract (`maxResults` caps the control list per form).
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* // Via MCP:
|
|
17
|
-
* // tool: inspect-form-group
|
|
18
|
-
* // args: { file: 'src/app/edit/edit.component.ts', projectRoot: '/project' }
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
import { type MCPTool, type ToolAnnotations } from '../types.js';
|
|
1
|
+
import { type MCPTool, type ToolAnnotations, type ToolContext } from '../types.js';
|
|
22
2
|
import { type InspectedForm, type InspectedFormControl } from '@angular-modernizer/api';
|
|
23
3
|
import { ProjectCache } from './helpers/project-cache.js';
|
|
24
4
|
/** A control with the cascade optionally dropped. */
|
|
25
|
-
type ControlOutput = Omit<InspectedFormControl, 'cascade'> & Partial<Pick<InspectedFormControl, 'cascade'>>;
|
|
5
|
+
export type ControlOutput = Omit<InspectedFormControl, 'cascade'> & Partial<Pick<InspectedFormControl, 'cascade'>>;
|
|
26
6
|
/** A form shaped by the compact options. */
|
|
27
|
-
type FormOutput = Omit<InspectedForm, 'controls'> & {
|
|
7
|
+
export type FormOutput = Omit<InspectedForm, 'controls'> & {
|
|
8
|
+
/** Controls, cut to `maxResults`; omitted with `summaryOnly`. */
|
|
28
9
|
controls?: ControlOutput[];
|
|
10
|
+
/** `true` when `maxResults` cut the control list. */
|
|
29
11
|
truncated: boolean;
|
|
30
12
|
};
|
|
31
13
|
/**
|
|
32
14
|
* Output of the inspect-form-group tool.
|
|
33
15
|
*/
|
|
34
|
-
interface InspectFormGroupOutput {
|
|
16
|
+
export interface InspectFormGroupOutput {
|
|
17
|
+
/** Reactive forms found in the file. */
|
|
35
18
|
forms: FormOutput[];
|
|
19
|
+
/** Short text summary of the forms and their controls. */
|
|
36
20
|
summary: string;
|
|
21
|
+
/** The tsconfig whose program was used. */
|
|
37
22
|
tsConfigPath: string;
|
|
38
23
|
/** Conditions that can make the result incomplete (unresolved library imports). */
|
|
39
24
|
warnings?: string[];
|
|
40
25
|
}
|
|
41
26
|
/**
|
|
42
|
-
* MCP tool that
|
|
27
|
+
* MCP tool that returns the Reactive Forms of a component or service file
|
|
28
|
+
* as structure: controls with validators and initial state, and every
|
|
29
|
+
* enable/disable/validator change per control, including what an ancestor
|
|
30
|
+
* group's enable()/disable() switches with it.
|
|
31
|
+
*
|
|
32
|
+
* @remarks
|
|
33
|
+
* Logic lives in `FormGroupInspector` (`@angular-modernizer/api`); this tool
|
|
34
|
+
* resolves the project, validates arguments and applies the compact output
|
|
35
|
+
* contract (`maxResults` caps the control list per form).
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* // Via MCP:
|
|
40
|
+
* // tool: inspect-form-group
|
|
41
|
+
* // args: { file: 'src/app/edit/edit.component.ts', projectRoot: '/project' }
|
|
42
|
+
* ```
|
|
43
43
|
*/
|
|
44
44
|
export declare class InspectFormGroupTool implements MCPTool {
|
|
45
45
|
private readonly projects;
|
|
@@ -48,6 +48,10 @@ export declare class InspectFormGroupTool implements MCPTool {
|
|
|
48
48
|
readonly annotations: ToolAnnotations;
|
|
49
49
|
constructor(projects?: ProjectCache);
|
|
50
50
|
readonly description: string;
|
|
51
|
+
/**
|
|
52
|
+
* JSON Schema of the tool arguments.
|
|
53
|
+
* @hidden
|
|
54
|
+
*/
|
|
51
55
|
readonly inputSchema: {
|
|
52
56
|
type: string;
|
|
53
57
|
additionalProperties: boolean;
|
|
@@ -90,6 +94,10 @@ export declare class InspectFormGroupTool implements MCPTool {
|
|
|
90
94
|
};
|
|
91
95
|
required: string[];
|
|
92
96
|
};
|
|
97
|
+
/**
|
|
98
|
+
* JSON Schema of the tool result (`structuredContent`).
|
|
99
|
+
* @hidden
|
|
100
|
+
*/
|
|
93
101
|
readonly outputSchema: {
|
|
94
102
|
type: string;
|
|
95
103
|
properties: {
|
|
@@ -316,9 +324,8 @@ export declare class InspectFormGroupTool implements MCPTool {
|
|
|
316
324
|
};
|
|
317
325
|
required: string[];
|
|
318
326
|
};
|
|
319
|
-
execute(args: Record<string, unknown
|
|
327
|
+
execute(args: Record<string, unknown>, ctx?: ToolContext): Promise<InspectFormGroupOutput>;
|
|
320
328
|
private shape;
|
|
321
329
|
private buildSummary;
|
|
322
330
|
}
|
|
323
|
-
export {};
|
|
324
331
|
//# sourceMappingURL=inspect-form-group.d.ts.map
|