@angular-modernizer/adapter-mcp 1.1.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.
Files changed (38) hide show
  1. package/README.md +4 -2
  2. package/dist/index.d.ts +1 -1
  3. package/dist/tools/analyze-build-impact.d.ts +2 -2
  4. package/dist/tools/analyze-build-impact.js +6 -4
  5. package/dist/tools/analyze-project.d.ts +5 -2
  6. package/dist/tools/analyze-project.js +42 -21
  7. package/dist/tools/find-angular-symbol.d.ts +2 -2
  8. package/dist/tools/find-angular-symbol.js +3 -3
  9. package/dist/tools/find-component-hosts.d.ts +2 -2
  10. package/dist/tools/find-component-hosts.js +3 -3
  11. package/dist/tools/find-usages.d.ts +2 -2
  12. package/dist/tools/find-usages.js +3 -3
  13. package/dist/tools/get-bootstrap-execution.d.ts +2 -2
  14. package/dist/tools/get-bootstrap-execution.js +3 -3
  15. package/dist/tools/get-call-graph.d.ts +2 -2
  16. package/dist/tools/get-call-graph.js +3 -3
  17. package/dist/tools/helpers/project-cache.d.ts +73 -2
  18. package/dist/tools/helpers/project-cache.js +194 -9
  19. package/dist/tools/helpers/scan-plan.d.ts +1 -1
  20. package/dist/tools/helpers/scan-plan.js +1 -1
  21. package/dist/tools/inspect-form-group.d.ts +2 -2
  22. package/dist/tools/inspect-form-group.js +3 -3
  23. package/dist/tools/inspect-i18n.d.ts +3 -3
  24. package/dist/tools/inspect-i18n.js +3 -3
  25. package/dist/tools/inspect-template.d.ts +2 -2
  26. package/dist/tools/inspect-template.js +3 -3
  27. package/dist/tools/list-imports.d.ts +3 -3
  28. package/dist/tools/list-imports.js +3 -3
  29. package/dist/tools/plan-migration.d.ts +2 -2
  30. package/dist/tools/plan-migration.js +3 -2
  31. package/dist/tools/resolve-type.d.ts +2 -2
  32. package/dist/tools/resolve-type.js +3 -3
  33. package/dist/tools/search-codebase.d.ts +2 -2
  34. package/dist/tools/search-codebase.js +3 -3
  35. package/dist/tools/trace-output-flow.d.ts +2 -2
  36. package/dist/tools/trace-output-flow.js +3 -3
  37. package/dist/tools/transform-code.js +89 -13
  38. package/package.json +11 -11
@@ -86,20 +86,26 @@ function describeTransformation(result) {
86
86
  }
87
87
  const outcome = result.success ? 'succeeded' : 'failed';
88
88
  const lines = [];
89
+ const introduced = result.validation.introducedTypeErrors ?? [];
89
90
  if (result.files !== undefined) {
90
91
  const failed = result.files.filter((f) => !f.success);
91
92
  const duration = result.orchestration?.duration;
92
93
  lines.push(`${result.transformation} ${outcome} on ${result.files.length} file(s): ` +
93
94
  `${result.files.length - failed.length} succeeded, ${failed.length} failed` +
94
- (duration === undefined ? '.' : ` in ${duration} ms.`));
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
+ '.');
95
101
  lines.push(...describeSafety(result));
102
+ lines.push(...(result.warnings ?? []).map((w) => `- ${w}`));
96
103
  lines.push(...failed
97
104
  .slice(0, SUMMARY_FAILED_FILES)
98
105
  .map((f) => `- ${f.path}${f.error === undefined ? '' : `: ${f.error}`}`));
99
106
  return lines.join('\n');
100
107
  }
101
108
  const c = result.changes;
102
- const introduced = result.validation.introducedTypeErrors ?? [];
103
109
  lines.push(`${result.transformation} ${outcome} on ${result.filePath ?? 'unknown file'}: ` +
104
110
  `${c.linesChanged} line(s) changed (+${c.additions}/-${c.deletions}); ` +
105
111
  `type check ${result.validation.typeCheckPassed ? 'passed' : 'failed'}` +
@@ -156,6 +162,37 @@ async function transformWithKernel(kernel, filePath, params) {
156
162
  },
157
163
  };
158
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
+ }
159
196
  /**
160
197
  * Files a batch restores after a failure: all-or-nothing every file,
161
198
  * selective only the failed ones, none nothing.
@@ -264,7 +301,7 @@ export class TransformCodeTool {
264
301
  },
265
302
  validateTransformation: {
266
303
  type: 'boolean',
267
- 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',
268
305
  default: true,
269
306
  },
270
307
  autoRollback: {
@@ -278,7 +315,7 @@ export class TransformCodeTool {
278
315
  },
279
316
  rollbackStrategy: {
280
317
  type: 'string',
281
- 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',
282
319
  enum: ['all-or-nothing', 'selective', 'none'],
283
320
  default: 'all-or-nothing',
284
321
  },
@@ -1004,13 +1041,43 @@ export class TransformCodeTool {
1004
1041
  gitSnapshot: backupResult.metadata?.gitStashRef,
1005
1042
  };
1006
1043
  }
1007
- const batchKernel = createBatchKernel(() => loadBatchKernel(projectRoot));
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
+ });
1008
1055
  const result = await executeBatchTransformation(batchOptions, async (filePath) => {
1009
1056
  return this.transformSingleFile(filePath, params, batchKernel);
1010
1057
  });
1011
- const failedFiles = result.files
1012
- .filter((f) => !f.success)
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)
1013
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);
1014
1081
  const cancelled = ctx.signal?.aborted === true;
1015
1082
  // A cancelled batch restores every file, whatever the strategy
1016
1083
  const filesToRestore = cancelled
@@ -1033,12 +1100,13 @@ export class TransformCodeTool {
1033
1100
  success: attempt.success,
1034
1101
  };
1035
1102
  }
1036
- // Convert batch result to TransformationResult format
1103
+ const introducedErrors = [...introduced.values()].flat();
1104
+ const introducedList = [...introduced].flatMap(([path, errors]) => errors.map((e) => `${path}: ${e}`));
1037
1105
  return {
1038
- success: result.success && !cancelled,
1106
+ success: failedFiles.length === 0 && !cancelled,
1039
1107
  backup,
1040
1108
  rollback,
1041
- files: result.files,
1109
+ files,
1042
1110
  transformation: params.transformation,
1043
1111
  changes: {
1044
1112
  linesChanged: 0, // Aggregated in batch handler
@@ -1046,10 +1114,18 @@ export class TransformCodeTool {
1046
1114
  deletions: 0,
1047
1115
  },
1048
1116
  validation: {
1049
- syntaxValid: true, // Simplified for batch mode
1050
- typeCheckPassed: true,
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,
1051
1128
  },
1052
- orchestration: result.orchestration,
1053
1129
  progress: result.progress,
1054
1130
  };
1055
1131
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@angular-modernizer/adapter-mcp",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "MCP Server to expose Angular Modernizer tools to an AI assistant.",
5
5
  "keywords": [
6
6
  "angular",
@@ -31,16 +31,16 @@
31
31
  "glob": "^11.0.3",
32
32
  "ts-morph": "^27.0.2",
33
33
  "zod": "^4.6.5",
34
- "@angular-modernizer/core": "1.1.0",
35
- "@angular-modernizer/api": "1.1.0",
36
- "@angular-modernizer/orchestration": "1.1.0",
37
- "@angular-modernizer/plugin-analyzer": "1.1.0",
38
- "@angular-modernizer/plugin-angular": "1.1.0",
39
- "@angular-modernizer/plugin-architecture": "1.1.0",
40
- "@angular-modernizer/plugin-solid": "1.1.0",
41
- "@angular-modernizer/plugin-standalone": "1.1.0",
42
- "@angular-modernizer/plugin-system": "1.1.0",
43
- "@angular-modernizer/worker": "1.1.0"
34
+ "@angular-modernizer/api": "1.2.0",
35
+ "@angular-modernizer/core": "1.2.0",
36
+ "@angular-modernizer/plugin-angular": "1.2.0",
37
+ "@angular-modernizer/orchestration": "1.2.0",
38
+ "@angular-modernizer/plugin-analyzer": "1.2.0",
39
+ "@angular-modernizer/plugin-architecture": "1.2.0",
40
+ "@angular-modernizer/plugin-standalone": "1.2.0",
41
+ "@angular-modernizer/plugin-system": "1.2.0",
42
+ "@angular-modernizer/plugin-solid": "1.2.0",
43
+ "@angular-modernizer/worker": "1.2.0"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@types/express": "^4.17.13",