@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
@@ -13,6 +13,12 @@ export interface OperationMetadata {
13
13
  status: 'running' | 'completed' | 'failed' | 'cancelled';
14
14
  /** Error message of a failed operation. */
15
15
  error?: string;
16
+ /**
17
+ * Time the operation completed, failed, timed out or was cancelled, in
18
+ * milliseconds since the epoch; the TTL of a finished operation counts
19
+ * from here.
20
+ */
21
+ completedAt?: number;
16
22
  }
17
23
  /**
18
24
  * Complete operation state including events and metadata
@@ -27,9 +33,12 @@ export interface OperationState {
27
33
  }
28
34
  /**
29
35
  * Singleton store for the progress of streaming operations (deprecated
30
- * `streaming` path and get-operation-progress), with TTL-based cleanup:
31
- * finished operations are deleted after 5 minutes, running ones are marked
32
- * failed with a timeout event after 10.
36
+ * `streaming` path and get-operation-progress), with TTL-based cleanup: a
37
+ * sweep once a minute deletes finished operations 5 minutes after they
38
+ * completed, failed or were cancelled, and marks operations still running 10
39
+ * minutes after their start as failed (`error` "Operation timed out after
40
+ * Ns", one event with phase `complete`, the only terminal phase); a timed-out
41
+ * operation then stays readable as failed for another 5 minutes.
33
42
  *
34
43
  * @remarks
35
44
  * Call `setResult(operationId, result)` before `markComplete(operationId)`:
@@ -112,10 +121,13 @@ export declare class ProgressStore {
112
121
  private startCleanupTimer;
113
122
  /**
114
123
  * Clean up operations that have exceeded TTL.
115
- * - Running operations older than runningTtlMs (default 10 min) are marked as
116
- * failed and a synthetic timeout-error event is appended so that a late poll
117
- * still receives a meaningful failure response (BUG-4).
118
- * - Completed/failed operations older than ttlMs (default 5 min) are deleted.
124
+ * - Running operations older than runningTtlMs (default 10 min, from the
125
+ * start) are marked as failed and a synthetic timeout event is appended
126
+ * so that a late poll still receives a meaningful failure response (BUG-4).
127
+ * - Completed, failed and cancelled operations are deleted ttlMs (default
128
+ * 5 min) after they ended (`completedAt`); before, the age counted from the
129
+ * start, so an operation running longer than 5 min lost its result at the
130
+ * first sweep after completion.
119
131
  */
120
132
  private cleanupExpiredOperations;
121
133
  /**
@@ -1,8 +1,11 @@
1
1
  /**
2
2
  * Singleton store for the progress of streaming operations (deprecated
3
- * `streaming` path and get-operation-progress), with TTL-based cleanup:
4
- * finished operations are deleted after 5 minutes, running ones are marked
5
- * failed with a timeout event after 10.
3
+ * `streaming` path and get-operation-progress), with TTL-based cleanup: a
4
+ * sweep once a minute deletes finished operations 5 minutes after they
5
+ * completed, failed or were cancelled, and marks operations still running 10
6
+ * minutes after their start as failed (`error` "Operation timed out after
7
+ * Ns", one event with phase `complete`, the only terminal phase); a timed-out
8
+ * operation then stays readable as failed for another 5 minutes.
6
9
  *
7
10
  * @remarks
8
11
  * Call `setResult(operationId, result)` before `markComplete(operationId)`:
@@ -88,6 +91,7 @@ export class ProgressStore {
88
91
  throw new Error(`Operation not found: ${operationId}`);
89
92
  }
90
93
  operation.metadata.status = 'completed';
94
+ operation.metadata.completedAt = Date.now();
91
95
  }
92
96
  /**
93
97
  * Mark operation as failed
@@ -99,6 +103,7 @@ export class ProgressStore {
99
103
  }
100
104
  operation.metadata.status = 'failed';
101
105
  operation.metadata.error = error;
106
+ operation.metadata.completedAt = Date.now();
102
107
  }
103
108
  /**
104
109
  * Store the final result of a completed operation (e.g. violations array).
@@ -132,6 +137,7 @@ export class ProgressStore {
132
137
  }
133
138
  operation.metadata.status = 'cancelled';
134
139
  operation.metadata.error = 'Cancelled by user';
140
+ operation.metadata.completedAt = Date.now();
135
141
  }
136
142
  /**
137
143
  * Returns true if the operation has been cancelled.
@@ -169,10 +175,13 @@ export class ProgressStore {
169
175
  }
170
176
  /**
171
177
  * Clean up operations that have exceeded TTL.
172
- * - Running operations older than runningTtlMs (default 10 min) are marked as
173
- * failed and a synthetic timeout-error event is appended so that a late poll
174
- * still receives a meaningful failure response (BUG-4).
175
- * - Completed/failed operations older than ttlMs (default 5 min) are deleted.
178
+ * - Running operations older than runningTtlMs (default 10 min, from the
179
+ * start) are marked as failed and a synthetic timeout event is appended
180
+ * so that a late poll still receives a meaningful failure response (BUG-4).
181
+ * - Completed, failed and cancelled operations are deleted ttlMs (default
182
+ * 5 min) after they ended (`completedAt`); before, the age counted from the
183
+ * start, so an operation running longer than 5 min lost its result at the
184
+ * first sweep after completion.
176
185
  */
177
186
  cleanupExpiredOperations() {
178
187
  const now = Date.now();
@@ -184,7 +193,8 @@ export class ProgressStore {
184
193
  operation.metadata.status === 'cancelled';
185
194
  if (isCompleted) {
186
195
  // Delete completed/failed operations past the short TTL.
187
- if (age > this.ttlMs) {
196
+ const ended = operation.metadata.completedAt ?? operation.metadata.startTime;
197
+ if (now - ended > this.ttlMs) {
188
198
  expiredIds.push(operationId);
189
199
  }
190
200
  }
@@ -193,6 +203,7 @@ export class ProgressStore {
193
203
  if (age > this.runningTtlMs) {
194
204
  operation.metadata.status = 'failed';
195
205
  operation.metadata.error = `Operation timed out after ${Math.round(age / 1000)}s`;
206
+ operation.metadata.completedAt = now;
196
207
  operation.events.push({
197
208
  phase: 'complete',
198
209
  percentage: 100,
@@ -27,7 +27,8 @@ export interface EstimatedBuildScope {
27
27
  */
28
28
  affectedModules?: string[];
29
29
  /**
30
- * Estimated build time in seconds
30
+ * Heuristic in seconds: affected files / 10, at least 5. Not measured; the
31
+ * Angular CLI always builds the whole application.
31
32
  */
32
33
  estimatedBuildTime: number;
33
34
  /**
@@ -173,7 +174,7 @@ export interface AnalyzeBuildImpactOutput {
173
174
  */
174
175
  affectedModules?: string[];
175
176
  /**
176
- * Estimated build time in seconds
177
+ * Heuristic in seconds: affected files / 10, at least 5. Not measured.
177
178
  */
178
179
  estimatedBuildTime: number;
179
180
  /**
@@ -334,7 +335,8 @@ export declare class AnalyzeBuildImpactTool implements MCPTool {
334
335
  };
335
336
  };
336
337
  estimatedBuildTime: {
337
- type: string;
338
+ readonly type: "number";
339
+ readonly description: "Heuristic in seconds: affected files / 10, at least 5. Not measured; the Angular CLI always builds the whole application.";
338
340
  };
339
341
  valueDependentFiles: {
340
342
  readonly type: "array";
@@ -379,7 +381,8 @@ export declare class AnalyzeBuildImpactTool implements MCPTool {
379
381
  };
380
382
  };
381
383
  estimatedBuildTime: {
382
- type: string;
384
+ readonly type: "number";
385
+ readonly description: "Heuristic in seconds: affected files / 10, at least 5. Not measured; the Angular CLI always builds the whole application.";
383
386
  };
384
387
  mappedFiles: {
385
388
  type: string;
@@ -8,6 +8,11 @@ import { acquireProject } from './helpers/project-cache.js';
8
8
  import { STRING_ARRAY } from './helpers/investigation-schemas.js';
9
9
  import { WARNINGS_OUTPUT_SCHEMA, withWarnings } from './helpers/output-contract.js';
10
10
  import { COMPACT_OUTPUT_SCHEMA, limitList, parseCompactOptions, } from './helpers/compact-output.js';
11
+ /** Output schema of the build time estimate: a file-count heuristic. */
12
+ const ESTIMATED_BUILD_TIME_SCHEMA = {
13
+ type: 'number',
14
+ description: 'Heuristic in seconds: affected files / 10, at least 5. Not measured; the Angular CLI always builds the whole application.',
15
+ };
11
16
  const BUILD_IMPACT_COUNT_KEYS = [
12
17
  'changedFiles',
13
18
  'dependentFiles',
@@ -28,7 +33,7 @@ function describeBuildImpact(result, strategy, summaryOnly) {
28
33
  `${c.changedFiles} changed, ${c.dependentFiles} dependent file(s) (${c.valueDependentFiles} value, ` +
29
34
  `${c.typeOnlyDependentFiles} type-only, ${c.templateDependentFiles} template host(s)), ` +
30
35
  `${c.reExportFiles} re-export(s), ${c.affectedModules} module(s); strategy ${strategy}, ` +
31
- `about ${result.estimatedBuildTime} s build.`,
36
+ `heuristic build estimate ${result.estimatedBuildTime} s (files / 10, at least 5 s; not measured).`,
32
37
  ];
33
38
  if (summaryOnly) {
34
39
  lines.push('File lists omitted (summaryOnly).');
@@ -147,7 +152,7 @@ export class AnalyzeBuildImpactTool {
147
152
  changedFiles: STRING_ARRAY,
148
153
  dependentFiles: STRING_ARRAY,
149
154
  affectedModules: STRING_ARRAY,
150
- estimatedBuildTime: { type: 'number' },
155
+ estimatedBuildTime: ESTIMATED_BUILD_TIME_SCHEMA,
151
156
  valueDependentFiles: STRING_ARRAY,
152
157
  typeOnlyDependentFiles: STRING_ARRAY,
153
158
  reExportFiles: STRING_ARRAY,
@@ -158,7 +163,7 @@ export class AnalyzeBuildImpactTool {
158
163
  },
159
164
  affectedFiles: STRING_ARRAY,
160
165
  affectedModules: STRING_ARRAY,
161
- estimatedBuildTime: { type: 'number' },
166
+ estimatedBuildTime: ESTIMATED_BUILD_TIME_SCHEMA,
162
167
  mappedFiles: {
163
168
  type: 'array',
164
169
  items: {
@@ -296,9 +296,17 @@ export declare class AnalyzeCoreToSharedTool implements MCPTool {
296
296
  */
297
297
  private assessImpact;
298
298
  /**
299
- * Find files that depend on the given core file.
299
+ * Map every file under `src/` to the files it imports, resolved through the
300
+ * project's module resolution (relative specifiers and tsconfig `paths`
301
+ * aliases alike). Keyed by the imported file, values are its importers.
300
302
  */
301
- private findReverseDependencies;
303
+ private buildReverseDependencyIndex;
304
+ /**
305
+ * The files one source file imports or re-exports from, with the names it
306
+ * takes from each. Specifiers that do not resolve to a project file are
307
+ * skipped.
308
+ */
309
+ private importsByResolvedTarget;
302
310
  /**
303
311
  * Find transitive dependencies of the core file.
304
312
  */
@@ -315,9 +323,5 @@ export declare class AnalyzeCoreToSharedTool implements MCPTool {
315
323
  * Calculate summary statistics from violations.
316
324
  */
317
325
  private calculateSummary;
318
- /**
319
- * Escape special regex characters.
320
- */
321
- private escapeRegExp;
322
326
  }
323
327
  //# sourceMappingURL=analyze-core-to-shared.d.ts.map
@@ -1,7 +1,7 @@
1
1
  import { findTsConfig } from './helpers/find-ts-config.js';
2
2
  import { Kernel } from '@angular-modernizer/core';
3
3
  import { glob } from 'glob';
4
- import { resolve, extname, relative, dirname } from 'node:path';
4
+ import { resolve, extname, relative } from 'node:path';
5
5
  import { readFileSync, statSync } from 'node:fs';
6
6
  import { countList } from './helpers/analysis-output.js';
7
7
  import { COUNT_OBJECT, STRING_ARRAY } from './helpers/investigation-schemas.js';
@@ -205,10 +205,17 @@ export class AnalyzeCoreToSharedTool {
205
205
  // Analyze files for core-to-shared violations
206
206
  const violations = [];
207
207
  const project = kernel.getProject();
208
+ const rootPath = params.rootPath;
209
+ // Built once, on the first impact assessment
210
+ let reverseIndex;
211
+ const reverseDependenciesOf = async (coreFilePath) => {
212
+ reverseIndex ??= this.buildReverseDependencyIndex(project, rootPath);
213
+ return (await reverseIndex).get(coreFilePath) ?? [];
214
+ };
208
215
  for (const filePath of filesToAnalyze) {
209
216
  try {
210
217
  const sourceFile = project.addSourceFileAtPath(filePath);
211
- const fileViolations = await this.analyzeFileForCoreToSharedViolations(sourceFile, params.rootPath, includeImpactAssessment);
218
+ const fileViolations = await this.analyzeFileForCoreToSharedViolations(sourceFile, reverseDependenciesOf, includeImpactAssessment);
212
219
  violations.push(...fileViolations);
213
220
  }
214
221
  catch (error) {
@@ -277,7 +284,7 @@ export class AnalyzeCoreToSharedTool {
277
284
  /**
278
285
  * Analyze a single file for core-to-shared violations.
279
286
  */
280
- async analyzeFileForCoreToSharedViolations(sourceFile, rootPath, includeImpactAssessment) {
287
+ async analyzeFileForCoreToSharedViolations(sourceFile, reverseDependenciesOf, includeImpactAssessment) {
281
288
  const violations = [];
282
289
  const filePath = sourceFile.getFilePath();
283
290
  // Analyze all imports
@@ -288,7 +295,7 @@ export class AnalyzeCoreToSharedTool {
288
295
  if (this.isSharedModuleImport(moduleSpecifier)) {
289
296
  const importedItems = this.extractImportedItems(importDecl);
290
297
  for (const importedItem of importedItems) {
291
- const violation = await this.createViolation(filePath, importDecl.getStartLineNumber(), moduleSpecifier, importedItem, rootPath, includeImpactAssessment);
298
+ const violation = await this.createViolation(filePath, importDecl.getStartLineNumber(), moduleSpecifier, importedItem, reverseDependenciesOf, includeImpactAssessment);
292
299
  violations.push(violation);
293
300
  }
294
301
  }
@@ -342,11 +349,11 @@ export class AnalyzeCoreToSharedTool {
342
349
  /**
343
350
  * Create a violation object with impact assessment.
344
351
  */
345
- async createViolation(filePath, line, importedModule, importedItem, rootPath, includeImpactAssessment) {
352
+ async createViolation(filePath, line, importedModule, importedItem, reverseDependenciesOf, includeImpactAssessment) {
346
353
  const violationId = `${filePath}:${line}:${importedModule}:${importedItem.name}`;
347
354
  let impactAssessment;
348
355
  if (includeImpactAssessment) {
349
- impactAssessment = await this.assessImpact(filePath, rootPath);
356
+ impactAssessment = await this.assessImpact(filePath, reverseDependenciesOf);
350
357
  }
351
358
  const severity = this.determineSeverity(impactAssessment);
352
359
  return {
@@ -371,9 +378,9 @@ export class AnalyzeCoreToSharedTool {
371
378
  /**
372
379
  * Assess the impact of a core-to-shared violation.
373
380
  */
374
- async assessImpact(coreFilePath, rootPath) {
375
- const reverseDeps = await this.findReverseDependencies(coreFilePath, rootPath);
376
- const transitiveDeps = this.findTransitiveDependencies(coreFilePath, rootPath);
381
+ async assessImpact(coreFilePath, reverseDependenciesOf) {
382
+ const reverseDeps = await reverseDependenciesOf(coreFilePath);
383
+ const transitiveDeps = this.findTransitiveDependencies(coreFilePath);
377
384
  const impact = this.assessBreakingChangeImpact(reverseDeps);
378
385
  return {
379
386
  breakingChangeRisk: impact.risk,
@@ -383,16 +390,18 @@ export class AnalyzeCoreToSharedTool {
383
390
  };
384
391
  }
385
392
  /**
386
- * Find files that depend on the given core file.
393
+ * Map every file under `src/` to the files it imports, resolved through the
394
+ * project's module resolution (relative specifiers and tsconfig `paths`
395
+ * aliases alike). Keyed by the imported file, values are its importers.
387
396
  */
388
- async findReverseDependencies(coreFilePath, rootPath) {
389
- const reverseDeps = [];
397
+ async buildReverseDependencyIndex(project, rootPath) {
398
+ const index = new Map();
390
399
  const srcPath = resolve(rootPath, 'src');
391
400
  try {
392
- // Find all TypeScript files in the project
393
401
  const allFiles = await glob('**/*.{ts,tsx}', {
394
402
  cwd: srcPath,
395
403
  absolute: true,
404
+ nodir: true,
396
405
  ignore: [
397
406
  '**/node_modules/**',
398
407
  '**/dist/**',
@@ -400,57 +409,57 @@ export class AnalyzeCoreToSharedTool {
400
409
  '**/*.test.ts',
401
410
  ],
402
411
  });
403
- for (const filePath of allFiles) {
404
- try {
405
- const content = readFileSync(filePath, 'utf8');
406
- const relativeCorePath = relative(dirname(filePath), coreFilePath);
407
- // Check for imports of the core file
408
- const importPatterns = [
409
- new RegExp(`import.*from.*['"]${this.escapeRegExp(relativeCorePath.replaceAll('\\', '/'))}['"]`, 'g'),
410
- new RegExp(String.raw `import.*from.*['"]\./${this.escapeRegExp(relative(dirname(coreFilePath), filePath).replaceAll('\\', '/'))}['"]`, 'g'),
411
- ];
412
- let hasImport = false;
413
- const imports = [];
414
- for (const pattern of importPatterns) {
415
- if (pattern.test(content)) {
416
- hasImport = true;
417
- // Extract imported items
418
- const importRegex = /import\s+{([^}]+)}\s+from/g;
419
- let importMatch;
420
- while ((importMatch = importRegex.exec(content)) !== null) {
421
- const importStr = importMatch[1];
422
- if (importStr != null) {
423
- const parsedImports = importStr
424
- .split(',')
425
- .map((s) => s.trim().split(' as ')[0])
426
- .filter((s) => s && s.length > 0);
427
- imports.push(...parsedImports);
428
- }
429
- }
430
- break;
431
- }
432
- }
433
- if (hasImport) {
434
- reverseDeps.push({
435
- file: relative(srcPath, filePath),
436
- imports: [...new Set(imports)], // Remove duplicates
437
- });
438
- }
439
- }
440
- catch (_error) {
441
- // Skip files that can't be read
412
+ const sourceFiles = allFiles
413
+ .sort()
414
+ .map((filePath) => project.addSourceFileAtPathIfExists(filePath))
415
+ .filter((sourceFile) => sourceFile !== undefined);
416
+ for (const sourceFile of sourceFiles) {
417
+ const importsByTarget = this.importsByResolvedTarget(sourceFile);
418
+ const file = relative(srcPath, sourceFile.getFilePath());
419
+ for (const [target, imports] of importsByTarget) {
420
+ const importers = index.get(target) ?? [];
421
+ importers.push({ file, imports: [...new Set(imports)] });
422
+ index.set(target, importers);
442
423
  }
443
424
  }
444
425
  }
445
426
  catch (error) {
446
427
  console.warn('Error finding reverse dependencies:', error);
447
428
  }
448
- return reverseDeps;
429
+ return index;
430
+ }
431
+ /**
432
+ * The files one source file imports or re-exports from, with the names it
433
+ * takes from each. Specifiers that do not resolve to a project file are
434
+ * skipped.
435
+ */
436
+ importsByResolvedTarget(sourceFile) {
437
+ const byTarget = new Map();
438
+ const add = (target, names) => {
439
+ if (!target || target === sourceFile) {
440
+ return;
441
+ }
442
+ const key = target.getFilePath();
443
+ byTarget.set(key, [...(byTarget.get(key) ?? []), ...names]);
444
+ };
445
+ for (const importDecl of sourceFile.getImportDeclarations()) {
446
+ const names = importDecl.getNamedImports().map((named) => named.getName());
447
+ const defaultImport = importDecl.getDefaultImport();
448
+ if (defaultImport) {
449
+ names.push(defaultImport.getText());
450
+ }
451
+ add(importDecl.getModuleSpecifierSourceFile(), names);
452
+ }
453
+ for (const exportDecl of sourceFile.getExportDeclarations()) {
454
+ const names = exportDecl.getNamedExports().map((named) => named.getName());
455
+ add(exportDecl.getModuleSpecifierSourceFile(), names);
456
+ }
457
+ return byTarget;
449
458
  }
450
459
  /**
451
460
  * Find transitive dependencies of the core file.
452
461
  */
453
- findTransitiveDependencies(coreFilePath, _rootPath) {
462
+ findTransitiveDependencies(coreFilePath) {
454
463
  const transitiveDeps = new Set();
455
464
  try {
456
465
  const content = readFileSync(coreFilePath, 'utf8');
@@ -531,11 +540,5 @@ export class AnalyzeCoreToSharedTool {
531
540
  uniqueSharedModules: sharedModules.size,
532
541
  };
533
542
  }
534
- /**
535
- * Escape special regex characters.
536
- */
537
- escapeRegExp(string) {
538
- return string.replaceAll(/[.*+?^${}()|[\]\\]/g, String.raw `\$&`);
539
- }
540
543
  }
541
544
  //# sourceMappingURL=analyze-core-to-shared.js.map
@@ -1,5 +1,6 @@
1
1
  import { type MCPTool, type ToolAnnotations } from '../types.js';
2
2
  import { type ParserImprovementSuggestion } from '@angular-modernizer/core';
3
+ import { type SkippedRecords } from './helpers/feedback-sidecar.js';
3
4
  /**
4
5
  * Output from analyze-parser-performance tool
5
6
  */
@@ -10,13 +11,21 @@ export interface AnalyzeParserPerformanceOutput {
10
11
  totalTransformations: number;
11
12
  /** Locations where sessions were read from */
12
13
  sourcesRead: string[];
14
+ /** Records skipped because the feedback sidecar marks them (0 with `includeOutdated`) */
15
+ skippedRecords: SkippedRecords;
16
+ /** Unusable sidecar, or session files changed since refresh-state marked them */
17
+ sidecarWarnings?: string[];
13
18
  /** Aggregated metrics across all sessions */
14
19
  aggregatedMetrics: AggregatedParserMetrics;
15
20
  /** Improvement suggestions sorted by priority */
16
21
  suggestions: ParserImprovementSuggestion[];
17
22
  /** Per-session detailed metrics */
18
23
  sessionMetrics: SessionMetricsDetail[];
19
- /** Human-readable summary for LLM consumption */
24
+ /** Always `true`: the tool is deprecated, removal planned for 3.0. */
25
+ deprecated: boolean;
26
+ /** The deprecation notice. */
27
+ message: string;
28
+ /** Human-readable summary for LLM consumption, starting with the deprecation notice */
20
29
  summary: string;
21
30
  }
22
31
  /**
@@ -74,6 +83,9 @@ export interface SessionMetricsDetail {
74
83
  * Location Support:
75
84
  * - 'both' (default): the project, plus the platform store when ANGULAR_MODERNIZER_PLATFORM_ROOT is set
76
85
  * - Automatic session deduplication by sessionId
86
+ *
87
+ * @deprecated No MCP tool writes the parser metadata this tool reads; it stays
88
+ * registered and working in 2.x, removal planned for 3.0.
77
89
  */
78
90
  export declare class AnalyzeParserPerformanceTool implements MCPTool {
79
91
  name: string;
@@ -88,6 +100,11 @@ export declare class AnalyzeParserPerformanceTool implements MCPTool {
88
100
  readonly type: "object";
89
101
  readonly additionalProperties: false;
90
102
  readonly properties: {
103
+ readonly includeOutdated: {
104
+ readonly type: "boolean";
105
+ readonly default: false;
106
+ readonly description: "Also read the records that .claude-feedback/index/consolidated.json marks as duplicate or outdated (written by refresh-state apply, part 'feedback'); default false skips them and counts them in skippedRecords";
107
+ };
91
108
  readonly projectRoot: {
92
109
  readonly type: "string";
93
110
  readonly description: "Project root path (defaults to process.cwd() if not provided)";
@@ -114,18 +131,6 @@ export declare class AnalyzeParserPerformanceTool implements MCPTool {
114
131
  outputSchema: {
115
132
  type: string;
116
133
  properties: {
117
- sessionsAnalyzed: {
118
- type: string;
119
- };
120
- totalTransformations: {
121
- type: string;
122
- };
123
- sourcesRead: {
124
- readonly type: "array";
125
- readonly items: {
126
- readonly type: "string";
127
- };
128
- };
129
134
  aggregatedMetrics: {
130
135
  type: string;
131
136
  properties: {
@@ -234,9 +239,48 @@ export declare class AnalyzeParserPerformanceTool implements MCPTool {
234
239
  required: string[];
235
240
  };
236
241
  };
242
+ deprecated: {
243
+ type: string;
244
+ };
245
+ message: {
246
+ type: string;
247
+ };
237
248
  summary: {
238
249
  type: string;
239
250
  };
251
+ skippedRecords: {
252
+ readonly type: "object";
253
+ readonly properties: {
254
+ readonly total: {
255
+ readonly type: "integer";
256
+ };
257
+ readonly byReason: {
258
+ readonly type: "object";
259
+ readonly additionalProperties: {
260
+ readonly type: "integer";
261
+ };
262
+ };
263
+ };
264
+ readonly required: readonly ["total", "byReason"];
265
+ };
266
+ sidecarWarnings: {
267
+ readonly type: "array";
268
+ readonly items: {
269
+ readonly type: "string";
270
+ };
271
+ };
272
+ sessionsAnalyzed: {
273
+ type: string;
274
+ };
275
+ totalTransformations: {
276
+ type: string;
277
+ };
278
+ sourcesRead: {
279
+ readonly type: "array";
280
+ readonly items: {
281
+ readonly type: "string";
282
+ };
283
+ };
240
284
  };
241
285
  required: string[];
242
286
  };