@angular-modernizer/adapter-mcp 1.2.0 → 2.0.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 (130) hide show
  1. package/CHANGELOG.md +662 -0
  2. package/README.md +84 -445
  3. package/dist/cli.js +9 -1
  4. package/dist/core/project-analyzer.js +2 -2
  5. package/dist/index.d.ts +9 -0
  6. package/dist/index.js +1 -0
  7. package/dist/scan-host/scan-host.d.ts +7 -0
  8. package/dist/scan-host/scan-host.js +73 -10
  9. package/dist/scan-host/scan-protocol.d.ts +2 -0
  10. package/dist/scan-host/scan-worker.js +14 -8
  11. package/dist/server/limited-stdio-transport.d.ts +6 -3
  12. package/dist/server/limited-stdio-transport.js +26 -9
  13. package/dist/server/mcp-server.js +1 -1
  14. package/dist/server/sdk-server.d.ts +14 -3
  15. package/dist/server/sdk-server.js +54 -6
  16. package/dist/server/tool-registry.d.ts +3 -1
  17. package/dist/server/tool-registry.js +8 -3
  18. package/dist/streaming/progress-store.d.ts +19 -7
  19. package/dist/streaming/progress-store.js +19 -8
  20. package/dist/tools/analyze-build-impact.d.ts +7 -4
  21. package/dist/tools/analyze-build-impact.js +8 -3
  22. package/dist/tools/analyze-core-to-shared.d.ts +10 -6
  23. package/dist/tools/analyze-core-to-shared.js +63 -60
  24. package/dist/tools/analyze-parser-performance.d.ts +57 -13
  25. package/dist/tools/analyze-parser-performance.js +67 -6
  26. package/dist/tools/analyze-project.d.ts +30 -4
  27. package/dist/tools/analyze-project.js +99 -15
  28. package/dist/tools/check-incremental-compatibility.d.ts +30 -41
  29. package/dist/tools/check-incremental-compatibility.js +32 -264
  30. package/dist/tools/collect-feedback.js +15 -2
  31. package/dist/tools/extract-libraries.js +42 -27
  32. package/dist/tools/find-angular-symbol.js +3 -2
  33. package/dist/tools/find-component-hosts.js +3 -2
  34. package/dist/tools/find-usages.js +21 -12
  35. package/dist/tools/get-call-graph.js +15 -2
  36. package/dist/tools/get-operation-progress-tool.d.ts +1 -1
  37. package/dist/tools/get-operation-progress-tool.js +2 -2
  38. package/dist/tools/get-operation-progress.d.ts +4 -1
  39. package/dist/tools/get-operation-progress.js +6 -2
  40. package/dist/tools/helpers/analysis-output.d.ts +32 -1
  41. package/dist/tools/helpers/analysis-output.js +22 -1
  42. package/dist/tools/helpers/build-cache.d.ts +27 -0
  43. package/dist/tools/helpers/build-cache.js +86 -0
  44. package/dist/tools/helpers/class-filter.d.ts +18 -0
  45. package/dist/tools/helpers/class-filter.js +30 -0
  46. package/dist/tools/helpers/cli-arguments.d.ts +23 -0
  47. package/dist/tools/helpers/cli-arguments.js +35 -0
  48. package/dist/tools/helpers/feedback-catalog.d.ts +38 -0
  49. package/dist/tools/helpers/feedback-catalog.js +196 -0
  50. package/dist/tools/helpers/feedback-sidecar.d.ts +201 -0
  51. package/dist/tools/helpers/feedback-sidecar.js +381 -0
  52. package/dist/tools/helpers/file-type-check.d.ts +34 -0
  53. package/dist/tools/helpers/file-type-check.js +56 -0
  54. package/dist/tools/helpers/output-contract.d.ts +42 -0
  55. package/dist/tools/helpers/output-contract.js +54 -0
  56. package/dist/tools/helpers/pattern-anonymizer.d.ts +27 -0
  57. package/dist/tools/helpers/pattern-anonymizer.js +159 -0
  58. package/dist/tools/helpers/project-cache.d.ts +5 -4
  59. package/dist/tools/helpers/project-cache.js +21 -16
  60. package/dist/tools/helpers/project-decorators.d.ts +11 -4
  61. package/dist/tools/helpers/project-decorators.js +13 -6
  62. package/dist/tools/helpers/refresh-apply.d.ts +94 -0
  63. package/dist/tools/helpers/refresh-apply.js +460 -0
  64. package/dist/tools/helpers/refresh-inventory.d.ts +106 -0
  65. package/dist/tools/helpers/refresh-inventory.js +610 -0
  66. package/dist/tools/helpers/rule-runner.js +3 -1
  67. package/dist/tools/helpers/scan-cache.d.ts +74 -5
  68. package/dist/tools/helpers/scan-cache.js +134 -6
  69. package/dist/tools/helpers/scan-engine.d.ts +30 -6
  70. package/dist/tools/helpers/scan-engine.js +131 -22
  71. package/dist/tools/helpers/scan-plan.js +16 -2
  72. package/dist/tools/helpers/source-map-loader.d.ts +55 -0
  73. package/dist/tools/helpers/source-map-loader.js +226 -0
  74. package/dist/tools/helpers/template-check.d.ts +76 -0
  75. package/dist/tools/helpers/template-check.js +158 -0
  76. package/dist/tools/helpers/tool-cache.d.ts +7 -2
  77. package/dist/tools/helpers/tool-cache.js +9 -3
  78. package/dist/tools/helpers/tool-context.d.ts +18 -0
  79. package/dist/tools/helpers/tool-context.js +29 -0
  80. package/dist/tools/helpers/transform-safety.d.ts +151 -1
  81. package/dist/tools/helpers/transform-safety.js +357 -4
  82. package/dist/tools/inspect-form-group.js +5 -0
  83. package/dist/tools/inspect-i18n.d.ts +1 -1
  84. package/dist/tools/inspect-template.js +8 -2
  85. package/dist/tools/learn-patterns.d.ts +43 -28
  86. package/dist/tools/learn-patterns.js +83 -161
  87. package/dist/tools/list-imports.d.ts +1 -1
  88. package/dist/tools/orchestrate-migration.d.ts +19 -1
  89. package/dist/tools/orchestrate-migration.js +52 -10
  90. package/dist/tools/parse-stack-trace.d.ts +48 -1
  91. package/dist/tools/parse-stack-trace.js +108 -9
  92. package/dist/tools/plan-migration.js +22 -10
  93. package/dist/tools/refresh-state.d.ts +378 -0
  94. package/dist/tools/refresh-state.js +370 -0
  95. package/dist/tools/resolve-type.js +10 -3
  96. package/dist/tools/review-feedback.d.ts +42 -7
  97. package/dist/tools/review-feedback.js +24 -17
  98. package/dist/tools/rollback-changes.d.ts +5 -0
  99. package/dist/tools/rollback-changes.js +7 -2
  100. package/dist/tools/run-angular-cli.js +36 -22
  101. package/dist/tools/run-build.d.ts +33 -28
  102. package/dist/tools/run-build.js +136 -438
  103. package/dist/tools/run-schematic.d.ts +8 -2
  104. package/dist/tools/run-schematic.js +80 -50
  105. package/dist/tools/scan-all.d.ts +31 -15
  106. package/dist/tools/scan-all.js +75 -109
  107. package/dist/tools/scan-angular.d.ts +27 -14
  108. package/dist/tools/scan-angular.js +70 -92
  109. package/dist/tools/scan-architecture.d.ts +29 -12
  110. package/dist/tools/scan-architecture.js +205 -135
  111. package/dist/tools/scan-solid.d.ts +27 -14
  112. package/dist/tools/scan-solid.js +73 -89
  113. package/dist/tools/search-codebase.d.ts +6 -1
  114. package/dist/tools/search-codebase.js +13 -7
  115. package/dist/tools/suggest-improvements.d.ts +34 -3
  116. package/dist/tools/suggest-improvements.js +34 -9
  117. package/dist/tools/trace-output-flow.js +3 -2
  118. package/dist/tools/transform-code-batch.d.ts +9 -9
  119. package/dist/tools/transform-code.d.ts +161 -12
  120. package/dist/tools/transform-code.js +715 -206
  121. package/dist/tools/validate-before-transform.js +2 -1
  122. package/dist/tools/validate-project-compatibility.d.ts +28 -55
  123. package/dist/tools/validate-project-compatibility.js +33 -225
  124. package/dist/tools/validate-transformation.d.ts +40 -26
  125. package/dist/tools/validate-transformation.js +115 -294
  126. package/dist/tools/verify-citations.js +8 -2
  127. package/dist/types.d.ts +9 -9
  128. package/dist/utils/format-tool-response.d.ts +3 -1
  129. package/dist/utils/format-tool-response.js +8 -3
  130. package/package.json +14 -13
@@ -75,6 +75,11 @@ export declare class RollbackChangesTool implements MCPTool {
75
75
  type: string;
76
76
  description: string;
77
77
  };
78
+ force: {
79
+ type: string;
80
+ description: string;
81
+ default: boolean;
82
+ };
78
83
  };
79
84
  };
80
85
  /**
@@ -62,6 +62,11 @@ export class RollbackChangesTool {
62
62
  type: 'string',
63
63
  description: 'Git project root (optional - used as project root when projectRoot is not given)',
64
64
  },
65
+ force: {
66
+ type: 'boolean',
67
+ description: 'Restore files that changed since the transformation that wrote their backup (default: false: such a file is left alone and reported, so an old backup never overwrites later edits)',
68
+ default: false,
69
+ },
65
70
  },
66
71
  };
67
72
  /**
@@ -89,7 +94,7 @@ export class RollbackChangesTool {
89
94
  };
90
95
  async execute(args) {
91
96
  const typedArgs = args;
92
- const { files, strategy = 'auto', backupDir, projectRoot, gitRoot, } = typedArgs;
97
+ const { files, strategy = 'auto', backupDir, projectRoot, gitRoot, force = false, } = typedArgs;
93
98
  const startTime = Date.now();
94
99
  // Convert strategy string to RollbackStrategy enum
95
100
  let rollbackStrategy;
@@ -115,7 +120,7 @@ export class RollbackChangesTool {
115
120
  strategy: rollbackStrategy,
116
121
  });
117
122
  try {
118
- const result = await rollbackManager.rollback(files);
123
+ const result = await rollbackManager.rollback(files, { force });
119
124
  const duration = Date.now() - startTime;
120
125
  const response = {
121
126
  success: result.success,
@@ -1,5 +1,7 @@
1
1
  import { spawn } from 'node:child_process';
2
- import { processGroupOptions, terminateOnAbort, terminateProcessTree, } from '@angular-modernizer/core';
2
+ import { noColorEnv, processGroupOptions, stripAnsi, terminateOnAbort, terminateProcessTree, } from '@angular-modernizer/core';
3
+ import { existsSync } from 'node:fs';
4
+ import { assertShellSafeArguments, cliNeedsShell } from './helpers/cli-arguments.js';
3
5
  import { outputTail, seconds } from './helpers/process-output.js';
4
6
  /** Text summary: what ran, how it ended, and the tail of stderr (or stdout) on failure. */
5
7
  function describeCliRun(result) {
@@ -53,6 +55,9 @@ export class RunAngularCliTool {
53
55
  'serve',
54
56
  'test',
55
57
  'lint',
58
+ 'e2e',
59
+ 'extract-i18n',
60
+ 'version',
56
61
  ],
57
62
  },
58
63
  args: {
@@ -122,8 +127,13 @@ export class RunAngularCliTool {
122
127
  const options = params.options ?? {};
123
128
  const cwd = options.cwd ?? process.cwd();
124
129
  const timeout = options.timeout ?? 300000; // 5 minutes default
125
- const env = options.env ? { ...process.env, ...options.env } : process.env;
126
- // Build the full command
130
+ // Color off unless options.env asks for it: summary and output are text
131
+ const env = noColorEnv(process.env, options.env);
132
+ assertShellSafeArguments(commandArgs);
133
+ if (!existsSync(cwd)) {
134
+ throw new Error(`Working directory does not exist: ${cwd}`);
135
+ }
136
+ // Build the full command (for display; the process gets argv)
127
137
  const fullCommand = `ng ${command} ${commandArgs.join(' ')}`.trim();
128
138
  try {
129
139
  const startTime = Date.now();
@@ -135,6 +145,20 @@ export class RunAngularCliTool {
135
145
  signal: ctx.signal,
136
146
  });
137
147
  const executionTime = Date.now() - startTime;
148
+ if (result.timedOut) {
149
+ // What the command printed before the timeout stays in the result
150
+ return withSummary({
151
+ success: false,
152
+ command,
153
+ fullCommand,
154
+ exitCode: -1,
155
+ stdout: result.stdout,
156
+ stderr: `${result.stderr}${result.stderr === '' || result.stderr.endsWith('\n') ? '' : '\n'}Command timed out after ${timeout}ms`,
157
+ executionTime,
158
+ timedOut: true,
159
+ cwd,
160
+ });
161
+ }
138
162
  return withSummary({
139
163
  success: result.exitCode === 0,
140
164
  command,
@@ -147,19 +171,6 @@ export class RunAngularCliTool {
147
171
  });
148
172
  }
149
173
  catch (error) {
150
- if (error instanceof Error && error.message.includes('timed out')) {
151
- return withSummary({
152
- success: false,
153
- command,
154
- fullCommand,
155
- exitCode: -1,
156
- stdout: '',
157
- stderr: 'Command timed out',
158
- executionTime: timeout,
159
- timedOut: true,
160
- cwd,
161
- });
162
- }
163
174
  throw new Error(`Angular CLI command failed: ${error instanceof Error ? error.message : String(error)}`);
164
175
  }
165
176
  }
@@ -168,19 +179,21 @@ export class RunAngularCliTool {
168
179
  */
169
180
  async executeCommand(command, args, options) {
170
181
  return new Promise((resolve, reject) => {
182
+ // argv without a shell: `;` or `$( )` in an argument stays an argument
171
183
  const ngProcess = spawn('npx', ['ng', command, ...args], {
172
184
  cwd: options.cwd,
173
185
  env: options.env,
174
186
  stdio: ['pipe', 'pipe', 'pipe'],
175
- shell: true,
187
+ shell: cliNeedsShell(),
176
188
  ...processGroupOptions(),
177
189
  });
178
190
  let stdout = '';
179
191
  let stderr = '';
180
- // Set up timeout
192
+ let timedOut = false;
193
+ // Timeout: end the process tree, resolve on close with the output so far
181
194
  const timeoutId = setTimeout(() => {
195
+ timedOut = true;
182
196
  terminateProcessTree(ngProcess);
183
- reject(new Error(`Command timed out after ${options.timeout}ms`));
184
197
  }, options.timeout);
185
198
  const stopOnAbort = terminateOnAbort(ngProcess, options.signal);
186
199
  const cleanup = () => {
@@ -200,9 +213,10 @@ export class RunAngularCliTool {
200
213
  return;
201
214
  }
202
215
  resolve({
203
- exitCode: code ?? 0,
204
- stdout,
205
- stderr,
216
+ exitCode: code ?? -1,
217
+ stdout: stripAnsi(stdout),
218
+ stderr: stripAnsi(stderr),
219
+ timedOut,
206
220
  });
207
221
  });
208
222
  ngProcess.on('error', (error) => {
@@ -1,7 +1,10 @@
1
1
  import { type MCPTool, type ToolAnnotations, type ToolContext } from '../types.js';
2
2
  import { type IncompatibilityCheck } from '@angular-modernizer/core';
3
3
  /**
4
- * Incremental build metadata
4
+ * Incremental build metadata.
5
+ *
6
+ * @deprecated run-build has no incremental mode any more and no longer sets
7
+ * this field; kept for 1.x consumers of the type.
5
8
  */
6
9
  export interface IncrementalMetadata {
7
10
  /**
@@ -42,11 +45,17 @@ export interface BuildResult {
42
45
  */
43
46
  success: boolean;
44
47
  /**
45
- * Detected build system.
48
+ * Build system of the command: `angular-cli`, `nx`, `vite`, `webpack`,
49
+ * `npm` (build script), `config` (`build.command`) or `none`.
46
50
  */
47
51
  buildSystem: string;
48
52
  /**
49
- * Command that was executed.
53
+ * Where the command came from: `config`, `angular-cli`, `nx`, `vite`,
54
+ * `webpack`, `package-script`, or `argument` for an explicit `buildSystem`.
55
+ */
56
+ commandSource?: string;
57
+ /**
58
+ * First word of the command that was executed.
50
59
  */
51
60
  command: string;
52
61
  /**
@@ -54,7 +63,8 @@ export interface BuildResult {
54
63
  */
55
64
  fullCommand: string;
56
65
  /**
57
- * Exit code of the build command.
66
+ * Exit code of the build command (-1 when it did not run or timed out
67
+ * without one).
58
68
  */
59
69
  exitCode: number;
60
70
  /**
@@ -70,7 +80,7 @@ export interface BuildResult {
70
80
  */
71
81
  executionTime: number;
72
82
  /**
73
- * Whether the command timed out.
83
+ * Whether the command timed out; the build is stopped then.
74
84
  */
75
85
  timedOut?: boolean;
76
86
  /**
@@ -78,26 +88,26 @@ export interface BuildResult {
78
88
  */
79
89
  artifacts?: string[];
80
90
  /**
81
- * Build warnings and notices.
91
+ * Build warnings, cache warnings and deprecation notices.
82
92
  */
83
93
  warnings?: string[];
84
94
  /**
85
- * Incremental build metadata (if incremental mode was attempted)
95
+ * @deprecated No longer set; run-build has no incremental mode.
86
96
  */
87
97
  incremental?: IncrementalMetadata;
88
98
  /**
89
- * Incompatibility issues detected (if incremental mode was blocked)
99
+ * @deprecated No longer set; run-build has no incremental mode.
90
100
  */
91
101
  incompatibilityIssues?: IncompatibilityCheck[];
92
102
  /**
93
- * Short text: command, exit code, time, build mode, and the last output lines on failure.
103
+ * Short text: command, exit code, time, warnings, and the last output lines on failure.
94
104
  */
95
105
  summary: string;
96
106
  }
97
107
  /**
98
108
  * MCP tool for executing build systems and validating code transformations.
99
- * Supports Angular CLI, Nx, Webpack, Vite, and auto-detection.
100
- * Includes incremental build mode for efficient validation.
109
+ * Runs the project's build command: `build.command` of the project config,
110
+ * else the detected build system, else the `build` script of package.json.
101
111
  */
102
112
  export declare class RunBuildTool implements MCPTool {
103
113
  name: string;
@@ -125,6 +135,7 @@ export declare class RunBuildTool implements MCPTool {
125
135
  incrementalMode: {
126
136
  type: string;
127
137
  description: string;
138
+ deprecated: boolean;
128
139
  };
129
140
  changedFiles: {
130
141
  type: string;
@@ -132,11 +143,12 @@ export declare class RunBuildTool implements MCPTool {
132
143
  type: string;
133
144
  };
134
145
  description: string;
146
+ deprecated: boolean;
135
147
  };
136
148
  forceFullBuild: {
137
149
  type: string;
138
150
  description: string;
139
- default: boolean;
151
+ deprecated: boolean;
140
152
  };
141
153
  cacheStrategy: {
142
154
  type: string;
@@ -159,7 +171,6 @@ export declare class RunBuildTool implements MCPTool {
159
171
  timeout: {
160
172
  type: string;
161
173
  description: string;
162
- default: number;
163
174
  };
164
175
  args: {
165
176
  type: string;
@@ -186,6 +197,9 @@ export declare class RunBuildTool implements MCPTool {
186
197
  buildSystem: {
187
198
  type: string;
188
199
  };
200
+ commandSource: {
201
+ type: string;
202
+ };
189
203
  command: {
190
204
  type: string;
191
205
  };
@@ -222,6 +236,7 @@ export declare class RunBuildTool implements MCPTool {
222
236
  };
223
237
  incremental: {
224
238
  type: string;
239
+ description: string;
225
240
  properties: {
226
241
  enabled: {
227
242
  type: string;
@@ -284,27 +299,17 @@ export declare class RunBuildTool implements MCPTool {
284
299
  execute(args: Record<string, unknown>, ctx?: ToolContext): Promise<BuildResult>;
285
300
  private runBuild;
286
301
  /**
287
- * Detects changed files using git status
302
+ * The command to run: the project's build command for `auto-detect`, the
303
+ * default command of an explicitly named build system otherwise.
288
304
  */
289
- private detectChangedFiles;
290
- /**
291
- * Executes an incremental build using IncompatibilityDetector and IncrementalBuildValidator
292
- */
293
- private executeIncrementalBuild;
294
- /**
295
- * Detect the build system used in the project.
296
- */
297
- private detectBuildSystem;
305
+ private resolveCommand;
298
306
  /**
299
307
  * Get default build command for a specific build system.
300
308
  */
301
309
  private getDefaultBuildCommand;
302
310
  /**
303
- * Build command arguments with options.
304
- */
305
- private buildCommandArgs;
306
- /**
307
- * Execute a build command.
311
+ * Execute a build command line in a shell. A timeout stops the process tree
312
+ * and resolves with `timedOut`; a cancel stops it and rejects.
308
313
  */
309
314
  private executeBuildCommand;
310
315
  /**