@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,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @angular-modernizer/adapter-mcp - Transform Code Tool
|
|
3
|
-
*
|
|
4
|
-
* MCP tool for performing surgical code transformations to fix
|
|
5
|
-
* architectural issues, including standalone component migration.
|
|
6
|
-
*/
|
|
7
1
|
import { type MCPTool, type ToolAnnotations, type ToolContext } from '../types.js';
|
|
8
2
|
/**
|
|
9
3
|
* Plugin config of a transformation: the plugins read `transformationType`
|
|
@@ -13,7 +7,7 @@ export declare function pluginConfigFor(transformation: string | undefined, opti
|
|
|
13
7
|
/**
|
|
14
8
|
* Transformation result.
|
|
15
9
|
*/
|
|
16
|
-
interface TransformationResult {
|
|
10
|
+
export interface TransformationResult {
|
|
17
11
|
/**
|
|
18
12
|
* Operation ID for streaming mode (when streaming=true).
|
|
19
13
|
*/
|
|
@@ -30,8 +24,11 @@ interface TransformationResult {
|
|
|
30
24
|
* Batch transformation results (batch mode).
|
|
31
25
|
*/
|
|
32
26
|
files?: {
|
|
27
|
+
/** File path. */
|
|
33
28
|
path: string;
|
|
29
|
+
/** Whether the file was transformed. */
|
|
34
30
|
success: boolean;
|
|
31
|
+
/** Error message of a failed file. */
|
|
35
32
|
error?: string;
|
|
36
33
|
}[];
|
|
37
34
|
/**
|
|
@@ -42,21 +39,32 @@ interface TransformationResult {
|
|
|
42
39
|
* Summary of changes made.
|
|
43
40
|
*/
|
|
44
41
|
changes: {
|
|
42
|
+
/** Changed lines. */
|
|
45
43
|
linesChanged: number;
|
|
44
|
+
/** Added lines. */
|
|
46
45
|
additions: number;
|
|
46
|
+
/** Removed lines. */
|
|
47
47
|
deletions: number;
|
|
48
48
|
};
|
|
49
49
|
/**
|
|
50
50
|
* Pre-validation results (if performed).
|
|
51
51
|
*/
|
|
52
52
|
preValidation?: {
|
|
53
|
+
/** `true` when the file may be transformed. */
|
|
53
54
|
valid: boolean;
|
|
55
|
+
/** Issues found by the pre-transformation validator. */
|
|
54
56
|
issues: {
|
|
57
|
+
/** Validation type. */
|
|
55
58
|
type: string;
|
|
59
|
+
/** Issue severity. */
|
|
56
60
|
severity: string;
|
|
61
|
+
/** Issue message. */
|
|
57
62
|
message: string;
|
|
63
|
+
/** File of the issue. */
|
|
58
64
|
filePath?: string;
|
|
65
|
+
/** Line of the issue. */
|
|
59
66
|
line?: number;
|
|
67
|
+
/** Column of the issue. */
|
|
60
68
|
column?: number;
|
|
61
69
|
}[];
|
|
62
70
|
};
|
|
@@ -64,8 +72,11 @@ interface TransformationResult {
|
|
|
64
72
|
* Validation results.
|
|
65
73
|
*/
|
|
66
74
|
validation: {
|
|
75
|
+
/** `true` when the transformation introduced no syntax error. */
|
|
67
76
|
syntaxValid: boolean;
|
|
77
|
+
/** `true` when the transformation introduced no type error. */
|
|
68
78
|
typeCheckPassed: boolean;
|
|
79
|
+
/** Test outcome, when tests ran. */
|
|
69
80
|
testsPass?: boolean;
|
|
70
81
|
/**
|
|
71
82
|
* Type errors the transformation introduced into the file.
|
|
@@ -76,8 +87,11 @@ interface TransformationResult {
|
|
|
76
87
|
* Backup information (if backup was created).
|
|
77
88
|
*/
|
|
78
89
|
backup?: {
|
|
90
|
+
/** `true` when a backup was written. */
|
|
79
91
|
created: boolean;
|
|
92
|
+
/** Path of the backup copy. */
|
|
80
93
|
backupPath?: string;
|
|
94
|
+
/** Backup strategy. */
|
|
81
95
|
strategy: 'git-stash' | 'file-backup';
|
|
82
96
|
/**
|
|
83
97
|
* Git snapshot commit recorded with the backup (inside a git repository).
|
|
@@ -88,8 +102,11 @@ interface TransformationResult {
|
|
|
88
102
|
* Rollback information (if rollback was performed).
|
|
89
103
|
*/
|
|
90
104
|
rollback?: {
|
|
105
|
+
/** `true` when the backup was restored. */
|
|
91
106
|
performed: boolean;
|
|
107
|
+
/** Why the rollback ran. */
|
|
92
108
|
reason?: string;
|
|
109
|
+
/** `true` when the restore succeeded. */
|
|
93
110
|
success?: boolean;
|
|
94
111
|
};
|
|
95
112
|
/**
|
|
@@ -97,25 +114,37 @@ interface TransformationResult {
|
|
|
97
114
|
*/
|
|
98
115
|
warnings?: string[];
|
|
99
116
|
/**
|
|
100
|
-
* Orchestration metrics
|
|
117
|
+
* Orchestration metrics.
|
|
101
118
|
*/
|
|
102
119
|
orchestration?: {
|
|
120
|
+
/** Files were transformed in parallel. */
|
|
103
121
|
parallel: boolean;
|
|
122
|
+
/** Batch mode (`files`) was used. */
|
|
104
123
|
batchMode: boolean;
|
|
124
|
+
/** Files processed. */
|
|
105
125
|
filesProcessed: number;
|
|
126
|
+
/** Files transformed successfully. */
|
|
106
127
|
filesSucceeded: number;
|
|
128
|
+
/** Files that failed. */
|
|
107
129
|
filesFailed: number;
|
|
130
|
+
/** Duration in milliseconds. */
|
|
108
131
|
duration: number;
|
|
132
|
+
/** Files per second. */
|
|
109
133
|
throughput: number;
|
|
110
134
|
};
|
|
111
135
|
/**
|
|
112
136
|
* Progress state (if enableProgress was true).
|
|
113
137
|
*/
|
|
114
138
|
progress?: {
|
|
139
|
+
/** Processed items. */
|
|
115
140
|
current: number;
|
|
141
|
+
/** Items in total. */
|
|
116
142
|
total: number;
|
|
143
|
+
/** Progress in percent. */
|
|
117
144
|
percentage: number;
|
|
145
|
+
/** Estimated time to completion. */
|
|
118
146
|
eta: number;
|
|
147
|
+
/** Current step. */
|
|
119
148
|
phase: string;
|
|
120
149
|
};
|
|
121
150
|
/**
|
|
@@ -128,9 +157,13 @@ interface TransformationResult {
|
|
|
128
157
|
*/
|
|
129
158
|
intermediateResults?: {
|
|
130
159
|
[stageName: string]: {
|
|
160
|
+
/** Whether the stage succeeded. */
|
|
131
161
|
success: boolean;
|
|
162
|
+
/** Violations found by the stage. */
|
|
132
163
|
violations?: number;
|
|
164
|
+
/** Files processed by the stage. */
|
|
133
165
|
filesProcessed?: number;
|
|
166
|
+
/** Stage message. */
|
|
134
167
|
message?: string;
|
|
135
168
|
};
|
|
136
169
|
};
|
|
@@ -138,14 +171,23 @@ interface TransformationResult {
|
|
|
138
171
|
* Build validation result (if buildCheck or validateBuild was enabled).
|
|
139
172
|
*/
|
|
140
173
|
buildValidation?: {
|
|
174
|
+
/** `true` when the build reported no error. */
|
|
141
175
|
passed: boolean;
|
|
176
|
+
/** Same as `passed`. */
|
|
142
177
|
success: boolean;
|
|
178
|
+
/** Exit code of the build. */
|
|
143
179
|
exitCode?: number;
|
|
180
|
+
/** Build errors. */
|
|
144
181
|
errors?: string[];
|
|
182
|
+
/** Build warnings. */
|
|
145
183
|
warnings?: string[];
|
|
184
|
+
/** Build duration in milliseconds. */
|
|
146
185
|
duration?: number;
|
|
186
|
+
/** Build command that ran. */
|
|
147
187
|
buildCommand?: string;
|
|
188
|
+
/** Detected build system. */
|
|
148
189
|
buildSystem?: string;
|
|
190
|
+
/** `true` when the build hit its timeout. */
|
|
149
191
|
timedOut?: boolean;
|
|
150
192
|
};
|
|
151
193
|
/**
|
|
@@ -165,11 +207,27 @@ interface TransformationResult {
|
|
|
165
207
|
*/
|
|
166
208
|
summary: string;
|
|
167
209
|
}
|
|
210
|
+
/**
|
|
211
|
+
* MCP tool `transform-code`: applies one of the transformation types to a
|
|
212
|
+
* file (or, with `files`, to a batch) to fix architectural issues, including
|
|
213
|
+
* standalone component migration.
|
|
214
|
+
*
|
|
215
|
+
* @remarks
|
|
216
|
+
* Runs inside a safety envelope: pre-validation, a backup in the project
|
|
217
|
+
* (file copy plus git snapshot inside a repository) that rollback-changes can
|
|
218
|
+
* restore, a type check of the transformed file that rolls back on newly
|
|
219
|
+
* introduced errors (`autoRollback`, default true), and an optional build or
|
|
220
|
+
* lint check. A cancelled call restores the backup.
|
|
221
|
+
*/
|
|
168
222
|
export declare class TransformCodeTool implements MCPTool {
|
|
169
223
|
name: string;
|
|
170
224
|
title: string;
|
|
171
225
|
annotations: ToolAnnotations;
|
|
172
226
|
description: string;
|
|
227
|
+
/**
|
|
228
|
+
* JSON Schema of the tool arguments.
|
|
229
|
+
* @hidden
|
|
230
|
+
*/
|
|
173
231
|
inputSchema: {
|
|
174
232
|
type: string;
|
|
175
233
|
additionalProperties: boolean;
|
|
@@ -327,6 +385,10 @@ export declare class TransformCodeTool implements MCPTool {
|
|
|
327
385
|
};
|
|
328
386
|
required: string[];
|
|
329
387
|
};
|
|
388
|
+
/**
|
|
389
|
+
* JSON Schema of the tool result (`structuredContent`).
|
|
390
|
+
* @hidden
|
|
391
|
+
*/
|
|
330
392
|
outputSchema: {
|
|
331
393
|
type: string;
|
|
332
394
|
properties: {
|
|
@@ -643,7 +705,7 @@ export declare class TransformCodeTool implements MCPTool {
|
|
|
643
705
|
*/
|
|
644
706
|
private executeStreaming;
|
|
645
707
|
/**
|
|
646
|
-
* Execute batch transformation
|
|
708
|
+
* Execute batch transformation.
|
|
647
709
|
*/
|
|
648
710
|
private executeBatch;
|
|
649
711
|
/**
|
|
@@ -671,5 +733,4 @@ export declare class TransformCodeTool implements MCPTool {
|
|
|
671
733
|
*/
|
|
672
734
|
private validateTransformationType;
|
|
673
735
|
}
|
|
674
|
-
export {};
|
|
675
736
|
//# sourceMappingURL=transform-code.d.ts.map
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @angular-modernizer/adapter-mcp - Transform Code Tool
|
|
3
|
-
*
|
|
4
|
-
* MCP tool for performing surgical code transformations to fix
|
|
5
|
-
* architectural issues, including standalone component migration.
|
|
6
|
-
*/
|
|
7
1
|
import { yieldIfCancellable } from './helpers/tool-context.js';
|
|
8
2
|
import { findTsConfig } from './helpers/find-ts-config.js';
|
|
3
|
+
import { createBatchKernel } from './helpers/batch-kernel.js';
|
|
9
4
|
import { Kernel, FluentKernel, PreTransformValidator, PostTransformValidator, ValidationSeverity, ValidationType, loadConfig, } from '@angular-modernizer/core';
|
|
10
5
|
import { AngularPlugin } from '@angular-modernizer/plugin-angular';
|
|
11
6
|
import { readFileSync } from 'node:fs';
|
|
@@ -91,20 +86,26 @@ function describeTransformation(result) {
|
|
|
91
86
|
}
|
|
92
87
|
const outcome = result.success ? 'succeeded' : 'failed';
|
|
93
88
|
const lines = [];
|
|
89
|
+
const introduced = result.validation.introducedTypeErrors ?? [];
|
|
94
90
|
if (result.files !== undefined) {
|
|
95
91
|
const failed = result.files.filter((f) => !f.success);
|
|
96
92
|
const duration = result.orchestration?.duration;
|
|
97
93
|
lines.push(`${result.transformation} ${outcome} on ${result.files.length} file(s): ` +
|
|
98
94
|
`${result.files.length - failed.length} succeeded, ${failed.length} failed` +
|
|
99
|
-
(duration === undefined ? '
|
|
95
|
+
(duration === undefined ? '' : ` in ${duration} ms`) +
|
|
96
|
+
`; type check ${result.validation.typeCheckPassed ? 'passed' : 'failed'}` +
|
|
97
|
+
(introduced.length > 0
|
|
98
|
+
? ` (${introduced.length} introduced type error(s))`
|
|
99
|
+
: '') +
|
|
100
|
+
'.');
|
|
100
101
|
lines.push(...describeSafety(result));
|
|
102
|
+
lines.push(...(result.warnings ?? []).map((w) => `- ${w}`));
|
|
101
103
|
lines.push(...failed
|
|
102
104
|
.slice(0, SUMMARY_FAILED_FILES)
|
|
103
105
|
.map((f) => `- ${f.path}${f.error === undefined ? '' : `: ${f.error}`}`));
|
|
104
106
|
return lines.join('\n');
|
|
105
107
|
}
|
|
106
108
|
const c = result.changes;
|
|
107
|
-
const introduced = result.validation.introducedTypeErrors ?? [];
|
|
108
109
|
lines.push(`${result.transformation} ${outcome} on ${result.filePath ?? 'unknown file'}: ` +
|
|
109
110
|
`${c.linesChanged} line(s) changed (+${c.additions}/-${c.deletions}); ` +
|
|
110
111
|
`type check ${result.validation.typeCheckPassed ? 'passed' : 'failed'}` +
|
|
@@ -127,6 +128,71 @@ function describeTransformation(result) {
|
|
|
127
128
|
/**
|
|
128
129
|
* MCP tool for code transformations.
|
|
129
130
|
*/
|
|
131
|
+
/** Loads the kernel a batch shares: the project's tsconfig program with the Angular plugin. */
|
|
132
|
+
async function loadBatchKernel(projectRoot) {
|
|
133
|
+
const tsConfigPath = findTsConfig(projectRoot);
|
|
134
|
+
if (!tsConfigPath) {
|
|
135
|
+
throw new Error('Could not find tsconfig.json');
|
|
136
|
+
}
|
|
137
|
+
const kernel = new Kernel({
|
|
138
|
+
tsConfigPath,
|
|
139
|
+
plugins: [new AngularPlugin()],
|
|
140
|
+
});
|
|
141
|
+
await kernel.initialize();
|
|
142
|
+
return kernel;
|
|
143
|
+
}
|
|
144
|
+
/** Transforms one batch file on the shared kernel and saves it. */
|
|
145
|
+
async function transformWithKernel(kernel, filePath, params) {
|
|
146
|
+
const project = kernel.getProject();
|
|
147
|
+
const sourceFile = project.getSourceFile(filePath) ?? project.addSourceFileAtPath(filePath);
|
|
148
|
+
const linesBefore = sourceFile.getFullText().split('\n').length;
|
|
149
|
+
const result = (await kernel.transformFile(sourceFile, {
|
|
150
|
+
dryRun: false,
|
|
151
|
+
autoSave: true,
|
|
152
|
+
pluginConfig: pluginConfigFor(params.transformation, params.options),
|
|
153
|
+
}));
|
|
154
|
+
await sourceFile.save();
|
|
155
|
+
const linesAfter = sourceFile.getFullText().split('\n').length;
|
|
156
|
+
return {
|
|
157
|
+
success: result.success,
|
|
158
|
+
changes: {
|
|
159
|
+
linesChanged: result.ruleResults.reduce((sum, r) => sum + (r.changeCount ?? 0), 0),
|
|
160
|
+
additions: Math.max(0, linesAfter - linesBefore),
|
|
161
|
+
deletions: Math.max(0, linesBefore - linesAfter),
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Type errors of the batch files on the shared kernel, keyed by path. Files
|
|
167
|
+
* that do not exist are left out (their transformation fails on its own).
|
|
168
|
+
*/
|
|
169
|
+
function batchTypeErrors(kernel, files) {
|
|
170
|
+
const project = kernel.getProject();
|
|
171
|
+
const errors = new Map();
|
|
172
|
+
for (const filePath of files) {
|
|
173
|
+
const sourceFile = project.getSourceFile(filePath) ??
|
|
174
|
+
project.addSourceFileAtPathIfExists(filePath);
|
|
175
|
+
if (sourceFile !== undefined) {
|
|
176
|
+
errors.set(filePath, fileTypeErrors(sourceFile));
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return errors;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Type errors the batch introduced, per file with at least one. `before` is
|
|
183
|
+
* taken before the first transformation, so an error a later file's
|
|
184
|
+
* transformation causes in an earlier batch file counts too.
|
|
185
|
+
*/
|
|
186
|
+
function introducedBatchTypeErrors(kernel, files, before) {
|
|
187
|
+
const introduced = new Map();
|
|
188
|
+
for (const [filePath, after] of batchTypeErrors(kernel, files)) {
|
|
189
|
+
const errors = introducedTypeErrors(before.get(filePath) ?? [], after);
|
|
190
|
+
if (errors.length > 0) {
|
|
191
|
+
introduced.set(filePath, errors);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return introduced;
|
|
195
|
+
}
|
|
130
196
|
/**
|
|
131
197
|
* Files a batch restores after a failure: all-or-nothing every file,
|
|
132
198
|
* selective only the failed ones, none nothing.
|
|
@@ -147,6 +213,18 @@ class TransformCancelledError extends Error {
|
|
|
147
213
|
super('Transformation cancelled by the client');
|
|
148
214
|
}
|
|
149
215
|
}
|
|
216
|
+
/**
|
|
217
|
+
* MCP tool `transform-code`: applies one of the transformation types to a
|
|
218
|
+
* file (or, with `files`, to a batch) to fix architectural issues, including
|
|
219
|
+
* standalone component migration.
|
|
220
|
+
*
|
|
221
|
+
* @remarks
|
|
222
|
+
* Runs inside a safety envelope: pre-validation, a backup in the project
|
|
223
|
+
* (file copy plus git snapshot inside a repository) that rollback-changes can
|
|
224
|
+
* restore, a type check of the transformed file that rolls back on newly
|
|
225
|
+
* introduced errors (`autoRollback`, default true), and an optional build or
|
|
226
|
+
* lint check. A cancelled call restores the backup.
|
|
227
|
+
*/
|
|
150
228
|
export class TransformCodeTool {
|
|
151
229
|
name = 'transform-code';
|
|
152
230
|
title = 'Transform Code';
|
|
@@ -158,6 +236,10 @@ export class TransformCodeTool {
|
|
|
158
236
|
};
|
|
159
237
|
description = 'Apply surgical code transformations to fix architectural issues. ' +
|
|
160
238
|
'summary is a short text with the outcome, the changes, the type check, backup and rollback.';
|
|
239
|
+
/**
|
|
240
|
+
* JSON Schema of the tool arguments.
|
|
241
|
+
* @hidden
|
|
242
|
+
*/
|
|
161
243
|
inputSchema = {
|
|
162
244
|
type: 'object',
|
|
163
245
|
additionalProperties: false,
|
|
@@ -219,7 +301,7 @@ export class TransformCodeTool {
|
|
|
219
301
|
},
|
|
220
302
|
validateTransformation: {
|
|
221
303
|
type: 'boolean',
|
|
222
|
-
description: 'Whether to validate transformation results (default: true): type check of the transformed file (new errors only), plus build and lint when enabled',
|
|
304
|
+
description: 'Whether to validate transformation results (default: true): type check of the transformed file (new errors only; in a batch every batch file, a file with a new error fails and rollbackStrategy applies), plus build and lint when enabled',
|
|
223
305
|
default: true,
|
|
224
306
|
},
|
|
225
307
|
autoRollback: {
|
|
@@ -233,7 +315,7 @@ export class TransformCodeTool {
|
|
|
233
315
|
},
|
|
234
316
|
rollbackStrategy: {
|
|
235
317
|
type: 'string',
|
|
236
|
-
description: 'Rollback strategy for batch operations',
|
|
318
|
+
description: 'Rollback strategy for batch operations, applied when a file fails (transformation error or introduced type error): all-or-nothing restores every file, selective the failed ones, none nothing',
|
|
237
319
|
enum: ['all-or-nothing', 'selective', 'none'],
|
|
238
320
|
default: 'all-or-nothing',
|
|
239
321
|
},
|
|
@@ -338,6 +420,10 @@ export class TransformCodeTool {
|
|
|
338
420
|
},
|
|
339
421
|
required: ['transformation'],
|
|
340
422
|
};
|
|
423
|
+
/**
|
|
424
|
+
* JSON Schema of the tool result (`structuredContent`).
|
|
425
|
+
* @hidden
|
|
426
|
+
*/
|
|
341
427
|
outputSchema = {
|
|
342
428
|
type: 'object',
|
|
343
429
|
properties: {
|
|
@@ -889,7 +975,7 @@ export class TransformCodeTool {
|
|
|
889
975
|
};
|
|
890
976
|
}
|
|
891
977
|
/**
|
|
892
|
-
* Execute batch transformation
|
|
978
|
+
* Execute batch transformation.
|
|
893
979
|
*/
|
|
894
980
|
async executeBatch(params, orchestration, ctx) {
|
|
895
981
|
if (!params.files || params.files.length === 0) {
|
|
@@ -955,12 +1041,43 @@ export class TransformCodeTool {
|
|
|
955
1041
|
gitSnapshot: backupResult.metadata?.gitStashRef,
|
|
956
1042
|
};
|
|
957
1043
|
}
|
|
1044
|
+
// Type errors of every batch file before the first transformation, on
|
|
1045
|
+
// the kernel the batch shares
|
|
1046
|
+
const validateTransformation = mergedParams.validateTransformation ?? true;
|
|
1047
|
+
let typeErrorsBefore = new Map();
|
|
1048
|
+
const batchKernel = createBatchKernel(async () => {
|
|
1049
|
+
const kernel = await loadBatchKernel(projectRoot);
|
|
1050
|
+
if (validateTransformation) {
|
|
1051
|
+
typeErrorsBefore = batchTypeErrors(kernel, batchOptions.files);
|
|
1052
|
+
}
|
|
1053
|
+
return kernel;
|
|
1054
|
+
});
|
|
958
1055
|
const result = await executeBatchTransformation(batchOptions, async (filePath) => {
|
|
959
|
-
return this.transformSingleFile(filePath, params,
|
|
1056
|
+
return this.transformSingleFile(filePath, params, batchKernel);
|
|
960
1057
|
});
|
|
961
|
-
|
|
962
|
-
|
|
1058
|
+
// Files whose transformation introduced a type error fail like files
|
|
1059
|
+
// whose transformation failed, and are restored by the same strategy
|
|
1060
|
+
const transformedFiles = result.files
|
|
1061
|
+
.filter((f) => f.success)
|
|
963
1062
|
.map((f) => f.path);
|
|
1063
|
+
const typeChecked = validateTransformation &&
|
|
1064
|
+
ctx.signal?.aborted !== true &&
|
|
1065
|
+
transformedFiles.length > 0;
|
|
1066
|
+
const introduced = typeChecked
|
|
1067
|
+
? await batchKernel.run((kernel) => Promise.resolve(introducedBatchTypeErrors(kernel, transformedFiles, typeErrorsBefore)))
|
|
1068
|
+
: new Map();
|
|
1069
|
+
const files = result.files.map((f) => {
|
|
1070
|
+
const errors = introduced.get(f.path);
|
|
1071
|
+
return errors === undefined
|
|
1072
|
+
? f
|
|
1073
|
+
: {
|
|
1074
|
+
...f,
|
|
1075
|
+
success: false,
|
|
1076
|
+
error: `Type error introduced: ${errors[0]}` +
|
|
1077
|
+
(errors.length > 1 ? ` (+${errors.length - 1} more)` : ''),
|
|
1078
|
+
};
|
|
1079
|
+
});
|
|
1080
|
+
const failedFiles = files.filter((f) => !f.success).map((f) => f.path);
|
|
964
1081
|
const cancelled = ctx.signal?.aborted === true;
|
|
965
1082
|
// A cancelled batch restores every file, whatever the strategy
|
|
966
1083
|
const filesToRestore = cancelled
|
|
@@ -983,12 +1100,13 @@ export class TransformCodeTool {
|
|
|
983
1100
|
success: attempt.success,
|
|
984
1101
|
};
|
|
985
1102
|
}
|
|
986
|
-
|
|
1103
|
+
const introducedErrors = [...introduced.values()].flat();
|
|
1104
|
+
const introducedList = [...introduced].flatMap(([path, errors]) => errors.map((e) => `${path}: ${e}`));
|
|
987
1105
|
return {
|
|
988
|
-
success:
|
|
1106
|
+
success: failedFiles.length === 0 && !cancelled,
|
|
989
1107
|
backup,
|
|
990
1108
|
rollback,
|
|
991
|
-
files
|
|
1109
|
+
files,
|
|
992
1110
|
transformation: params.transformation,
|
|
993
1111
|
changes: {
|
|
994
1112
|
linesChanged: 0, // Aggregated in batch handler
|
|
@@ -996,51 +1114,27 @@ export class TransformCodeTool {
|
|
|
996
1114
|
deletions: 0,
|
|
997
1115
|
},
|
|
998
1116
|
validation: {
|
|
999
|
-
syntaxValid:
|
|
1000
|
-
typeCheckPassed:
|
|
1117
|
+
syntaxValid: !introducedErrors.some((e) => /^TS1\d{3}:/.test(e)),
|
|
1118
|
+
typeCheckPassed: introducedErrors.length === 0,
|
|
1119
|
+
introducedTypeErrors: introducedList.length > 0 ? introducedList : undefined,
|
|
1120
|
+
},
|
|
1121
|
+
warnings: validateTransformation
|
|
1122
|
+
? undefined
|
|
1123
|
+
: ['Type check skipped (validateTransformation: false).'],
|
|
1124
|
+
orchestration: {
|
|
1125
|
+
...result.orchestration,
|
|
1126
|
+
filesSucceeded: files.length - failedFiles.length,
|
|
1127
|
+
filesFailed: failedFiles.length,
|
|
1001
1128
|
},
|
|
1002
|
-
orchestration: result.orchestration,
|
|
1003
1129
|
progress: result.progress,
|
|
1004
1130
|
};
|
|
1005
1131
|
}
|
|
1006
1132
|
/**
|
|
1007
1133
|
* Transform a single file (internal helper for batch mode).
|
|
1008
1134
|
*/
|
|
1009
|
-
async transformSingleFile(filePath, params,
|
|
1135
|
+
async transformSingleFile(filePath, params, batchKernel) {
|
|
1010
1136
|
try {
|
|
1011
|
-
|
|
1012
|
-
if (!tsConfigPath) {
|
|
1013
|
-
return {
|
|
1014
|
-
success: false,
|
|
1015
|
-
error: 'Could not find tsconfig.json',
|
|
1016
|
-
changes: { linesChanged: 0, additions: 0, deletions: 0 },
|
|
1017
|
-
};
|
|
1018
|
-
}
|
|
1019
|
-
const kernel = new Kernel({
|
|
1020
|
-
tsConfigPath,
|
|
1021
|
-
plugins: [new AngularPlugin()],
|
|
1022
|
-
});
|
|
1023
|
-
await kernel.initialize();
|
|
1024
|
-
const project = kernel.getProject();
|
|
1025
|
-
const sourceFile = project.addSourceFileAtPath(filePath);
|
|
1026
|
-
const linesBefore = sourceFile.getFullText().split('\n').length;
|
|
1027
|
-
const transformConfig = {
|
|
1028
|
-
dryRun: false,
|
|
1029
|
-
autoSave: true,
|
|
1030
|
-
pluginConfig: pluginConfigFor(params.transformation, params.options),
|
|
1031
|
-
};
|
|
1032
|
-
const result = (await kernel.transformFile(sourceFile, transformConfig));
|
|
1033
|
-
if (!transformConfig.dryRun && transformConfig.autoSave) {
|
|
1034
|
-
await sourceFile.save();
|
|
1035
|
-
}
|
|
1036
|
-
const linesAfter = sourceFile.getFullText().split('\n').length;
|
|
1037
|
-
const additions = Math.max(0, linesAfter - linesBefore);
|
|
1038
|
-
const deletions = Math.max(0, linesBefore - linesAfter);
|
|
1039
|
-
const linesChanged = result.ruleResults.reduce((sum, r) => sum + (r.changeCount ?? 0), 0);
|
|
1040
|
-
return {
|
|
1041
|
-
success: result.success,
|
|
1042
|
-
changes: { linesChanged, additions, deletions },
|
|
1043
|
-
};
|
|
1137
|
+
return await batchKernel.run((kernel) => transformWithKernel(kernel, filePath, params));
|
|
1044
1138
|
}
|
|
1045
1139
|
catch (error) {
|
|
1046
1140
|
return {
|
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @angular-modernizer/adapter-mcp - Validate Before Transform Tool
|
|
3
|
-
*
|
|
4
|
-
* MCP tool for validating code BEFORE transformation to ensure it's safe
|
|
5
|
-
* to modify. Performs syntax, dependency, type, and schema validation.
|
|
6
|
-
*/
|
|
7
1
|
import { type MCPTool, type ToolAnnotations } from '../types.js';
|
|
8
2
|
/**
|
|
9
3
|
* Validation result.
|
|
10
4
|
*/
|
|
11
|
-
interface ValidationResult {
|
|
5
|
+
export interface ValidationResult {
|
|
12
6
|
/**
|
|
13
7
|
* Whether validation passed (no errors).
|
|
14
8
|
*/
|
|
@@ -17,12 +11,19 @@ interface ValidationResult {
|
|
|
17
11
|
* Validation issues found.
|
|
18
12
|
*/
|
|
19
13
|
issues: {
|
|
14
|
+
/** Check that reported the issue. */
|
|
20
15
|
type: 'syntax' | 'dependency' | 'type' | 'schema';
|
|
16
|
+
/** Severity; only errors make the file not valid. */
|
|
21
17
|
severity: 'error' | 'warning' | 'info';
|
|
18
|
+
/** Issue description. */
|
|
22
19
|
message: string;
|
|
20
|
+
/** File the issue was found in. */
|
|
23
21
|
filePath?: string;
|
|
22
|
+
/** Line of the issue (1-based). */
|
|
24
23
|
line?: number;
|
|
24
|
+
/** Column of the issue. */
|
|
25
25
|
column?: number;
|
|
26
|
+
/** Additional details of the issue. */
|
|
26
27
|
details?: string;
|
|
27
28
|
}[];
|
|
28
29
|
/**
|
|
@@ -33,11 +34,17 @@ interface ValidationResult {
|
|
|
33
34
|
* Metadata about validation.
|
|
34
35
|
*/
|
|
35
36
|
metadata: {
|
|
37
|
+
/** Validated file. */
|
|
36
38
|
filePath: string;
|
|
39
|
+
/** Whether syntax validation ran. */
|
|
37
40
|
syntaxValidation: boolean;
|
|
41
|
+
/** Whether dependency validation ran. */
|
|
38
42
|
dependencyValidation: boolean;
|
|
43
|
+
/** Whether type validation ran. */
|
|
39
44
|
typeValidation: boolean;
|
|
45
|
+
/** Whether schema validation ran. */
|
|
40
46
|
schemaValidation: boolean;
|
|
47
|
+
/** Schema used for schema validation. */
|
|
41
48
|
schema?: Record<string, unknown>;
|
|
42
49
|
};
|
|
43
50
|
/**
|
|
@@ -46,13 +53,18 @@ interface ValidationResult {
|
|
|
46
53
|
summary: string;
|
|
47
54
|
}
|
|
48
55
|
/**
|
|
49
|
-
* MCP tool for
|
|
56
|
+
* MCP tool for validating code before a transformation to make sure it is
|
|
57
|
+
* safe to modify. Performs syntax, dependency, type, and schema validation.
|
|
50
58
|
*/
|
|
51
59
|
export declare class ValidateBeforeTransformTool implements MCPTool {
|
|
52
60
|
name: string;
|
|
53
61
|
title: string;
|
|
54
62
|
annotations: ToolAnnotations;
|
|
55
63
|
description: string;
|
|
64
|
+
/**
|
|
65
|
+
* JSON Schema of the tool arguments.
|
|
66
|
+
* @hidden
|
|
67
|
+
*/
|
|
56
68
|
inputSchema: {
|
|
57
69
|
type: string;
|
|
58
70
|
additionalProperties: boolean;
|
|
@@ -88,6 +100,10 @@ export declare class ValidateBeforeTransformTool implements MCPTool {
|
|
|
88
100
|
};
|
|
89
101
|
required: string[];
|
|
90
102
|
};
|
|
103
|
+
/**
|
|
104
|
+
* JSON Schema of the tool result (`structuredContent`).
|
|
105
|
+
* @hidden
|
|
106
|
+
*/
|
|
91
107
|
outputSchema: {
|
|
92
108
|
type: string;
|
|
93
109
|
properties: {
|
|
@@ -164,5 +180,4 @@ export declare class ValidateBeforeTransformTool implements MCPTool {
|
|
|
164
180
|
*/
|
|
165
181
|
private findProjectRoot;
|
|
166
182
|
}
|
|
167
|
-
export {};
|
|
168
183
|
//# sourceMappingURL=validate-before-transform.d.ts.map
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @angular-modernizer/adapter-mcp - Validate Before Transform Tool
|
|
3
|
-
*
|
|
4
|
-
* MCP tool for validating code BEFORE transformation to ensure it's safe
|
|
5
|
-
* to modify. Performs syntax, dependency, type, and schema validation.
|
|
6
|
-
*/
|
|
7
1
|
import { findTsConfig } from './helpers/find-ts-config.js';
|
|
8
2
|
import { PreTransformValidator, Kernel, } from '@angular-modernizer/core';
|
|
9
3
|
import { AngularPlugin } from '@angular-modernizer/plugin-angular';
|
|
@@ -26,7 +20,8 @@ function describeValidation(result) {
|
|
|
26
20
|
].join('\n');
|
|
27
21
|
}
|
|
28
22
|
/**
|
|
29
|
-
* MCP tool for
|
|
23
|
+
* MCP tool for validating code before a transformation to make sure it is
|
|
24
|
+
* safe to modify. Performs syntax, dependency, type, and schema validation.
|
|
30
25
|
*/
|
|
31
26
|
export class ValidateBeforeTransformTool {
|
|
32
27
|
name = 'validate-before-transform';
|
|
@@ -39,6 +34,10 @@ export class ValidateBeforeTransformTool {
|
|
|
39
34
|
};
|
|
40
35
|
description = 'Validate code before transformation to ensure it is safe to modify. Performs syntax, dependency, type, and schema validation. ' +
|
|
41
36
|
'summary is a short text with the verdict, the issue counts and the first issues.';
|
|
37
|
+
/**
|
|
38
|
+
* JSON Schema of the tool arguments.
|
|
39
|
+
* @hidden
|
|
40
|
+
*/
|
|
42
41
|
inputSchema = {
|
|
43
42
|
type: 'object',
|
|
44
43
|
additionalProperties: false,
|
|
@@ -74,6 +73,10 @@ export class ValidateBeforeTransformTool {
|
|
|
74
73
|
},
|
|
75
74
|
required: ['filePath'],
|
|
76
75
|
};
|
|
76
|
+
/**
|
|
77
|
+
* JSON Schema of the tool result (`structuredContent`).
|
|
78
|
+
* @hidden
|
|
79
|
+
*/
|
|
77
80
|
outputSchema = {
|
|
78
81
|
type: 'object',
|
|
79
82
|
properties: {
|