@angular-modernizer/adapter-mcp 1.2.0 → 2.1.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 (138) hide show
  1. package/CHANGELOG.md +688 -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 +10 -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 +55 -4
  27. package/dist/tools/analyze-project.js +104 -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/compare-health.d.ts +40 -4
  32. package/dist/tools/compare-health.js +22 -5
  33. package/dist/tools/extract-libraries.js +42 -27
  34. package/dist/tools/find-angular-symbol.js +3 -2
  35. package/dist/tools/find-component-hosts.js +3 -2
  36. package/dist/tools/find-usages.js +21 -12
  37. package/dist/tools/get-call-graph.js +15 -2
  38. package/dist/tools/get-operation-progress-tool.d.ts +1 -1
  39. package/dist/tools/get-operation-progress-tool.js +2 -2
  40. package/dist/tools/get-operation-progress.d.ts +4 -1
  41. package/dist/tools/get-operation-progress.js +6 -2
  42. package/dist/tools/helpers/analysis-output.d.ts +32 -1
  43. package/dist/tools/helpers/analysis-output.js +25 -1
  44. package/dist/tools/helpers/build-cache.d.ts +27 -0
  45. package/dist/tools/helpers/build-cache.js +86 -0
  46. package/dist/tools/helpers/class-filter.d.ts +18 -0
  47. package/dist/tools/helpers/class-filter.js +30 -0
  48. package/dist/tools/helpers/cli-arguments.d.ts +23 -0
  49. package/dist/tools/helpers/cli-arguments.js +35 -0
  50. package/dist/tools/helpers/feedback-catalog.d.ts +38 -0
  51. package/dist/tools/helpers/feedback-catalog.js +196 -0
  52. package/dist/tools/helpers/feedback-sidecar.d.ts +201 -0
  53. package/dist/tools/helpers/feedback-sidecar.js +381 -0
  54. package/dist/tools/helpers/file-type-check.d.ts +34 -0
  55. package/dist/tools/helpers/file-type-check.js +56 -0
  56. package/dist/tools/helpers/health-delta.d.ts +6 -0
  57. package/dist/tools/helpers/health-delta.js +4 -1
  58. package/dist/tools/helpers/library-import-warning.d.ts +33 -0
  59. package/dist/tools/helpers/library-import-warning.js +38 -0
  60. package/dist/tools/helpers/library-imports.d.ts +38 -14
  61. package/dist/tools/helpers/library-imports.js +128 -23
  62. package/dist/tools/helpers/output-contract.d.ts +64 -0
  63. package/dist/tools/helpers/output-contract.js +67 -0
  64. package/dist/tools/helpers/pattern-anonymizer.d.ts +27 -0
  65. package/dist/tools/helpers/pattern-anonymizer.js +159 -0
  66. package/dist/tools/helpers/project-cache.d.ts +5 -4
  67. package/dist/tools/helpers/project-cache.js +21 -16
  68. package/dist/tools/helpers/project-decorators.d.ts +11 -4
  69. package/dist/tools/helpers/project-decorators.js +13 -6
  70. package/dist/tools/helpers/refresh-apply.d.ts +94 -0
  71. package/dist/tools/helpers/refresh-apply.js +460 -0
  72. package/dist/tools/helpers/refresh-inventory.d.ts +106 -0
  73. package/dist/tools/helpers/refresh-inventory.js +631 -0
  74. package/dist/tools/helpers/rule-runner.js +3 -1
  75. package/dist/tools/helpers/scan-cache.d.ts +117 -5
  76. package/dist/tools/helpers/scan-cache.js +179 -6
  77. package/dist/tools/helpers/scan-engine.d.ts +43 -6
  78. package/dist/tools/helpers/scan-engine.js +141 -22
  79. package/dist/tools/helpers/scan-plan.js +16 -2
  80. package/dist/tools/helpers/source-map-loader.d.ts +55 -0
  81. package/dist/tools/helpers/source-map-loader.js +226 -0
  82. package/dist/tools/helpers/template-check.d.ts +76 -0
  83. package/dist/tools/helpers/template-check.js +158 -0
  84. package/dist/tools/helpers/tool-cache.d.ts +7 -2
  85. package/dist/tools/helpers/tool-cache.js +9 -3
  86. package/dist/tools/helpers/tool-context.d.ts +18 -0
  87. package/dist/tools/helpers/tool-context.js +29 -0
  88. package/dist/tools/helpers/transform-safety.d.ts +151 -1
  89. package/dist/tools/helpers/transform-safety.js +357 -4
  90. package/dist/tools/inspect-form-group.js +5 -0
  91. package/dist/tools/inspect-i18n.d.ts +1 -1
  92. package/dist/tools/inspect-template.js +8 -2
  93. package/dist/tools/learn-patterns.d.ts +43 -28
  94. package/dist/tools/learn-patterns.js +83 -161
  95. package/dist/tools/list-imports.d.ts +1 -1
  96. package/dist/tools/orchestrate-migration.d.ts +19 -1
  97. package/dist/tools/orchestrate-migration.js +52 -10
  98. package/dist/tools/parse-stack-trace.d.ts +48 -1
  99. package/dist/tools/parse-stack-trace.js +108 -9
  100. package/dist/tools/plan-migration.js +22 -10
  101. package/dist/tools/refresh-state.d.ts +378 -0
  102. package/dist/tools/refresh-state.js +370 -0
  103. package/dist/tools/resolve-type.js +10 -3
  104. package/dist/tools/review-feedback.d.ts +42 -7
  105. package/dist/tools/review-feedback.js +24 -17
  106. package/dist/tools/rollback-changes.d.ts +5 -0
  107. package/dist/tools/rollback-changes.js +7 -2
  108. package/dist/tools/run-angular-cli.js +36 -22
  109. package/dist/tools/run-build.d.ts +33 -28
  110. package/dist/tools/run-build.js +136 -438
  111. package/dist/tools/run-schematic.d.ts +8 -2
  112. package/dist/tools/run-schematic.js +80 -50
  113. package/dist/tools/scan-all.d.ts +37 -15
  114. package/dist/tools/scan-all.js +76 -115
  115. package/dist/tools/scan-angular.d.ts +33 -14
  116. package/dist/tools/scan-angular.js +77 -94
  117. package/dist/tools/scan-architecture.d.ts +37 -12
  118. package/dist/tools/scan-architecture.js +220 -139
  119. package/dist/tools/scan-solid.d.ts +33 -14
  120. package/dist/tools/scan-solid.js +80 -91
  121. package/dist/tools/search-codebase.d.ts +6 -1
  122. package/dist/tools/search-codebase.js +13 -7
  123. package/dist/tools/suggest-improvements.d.ts +34 -3
  124. package/dist/tools/suggest-improvements.js +34 -9
  125. package/dist/tools/trace-output-flow.js +3 -2
  126. package/dist/tools/transform-code-batch.d.ts +9 -9
  127. package/dist/tools/transform-code.d.ts +161 -12
  128. package/dist/tools/transform-code.js +715 -206
  129. package/dist/tools/validate-before-transform.js +2 -1
  130. package/dist/tools/validate-project-compatibility.d.ts +28 -55
  131. package/dist/tools/validate-project-compatibility.js +33 -225
  132. package/dist/tools/validate-transformation.d.ts +40 -26
  133. package/dist/tools/validate-transformation.js +115 -294
  134. package/dist/tools/verify-citations.js +8 -2
  135. package/dist/types.d.ts +9 -9
  136. package/dist/utils/format-tool-response.d.ts +3 -1
  137. package/dist/utils/format-tool-response.js +8 -3
  138. package/package.json +14 -13
@@ -2,6 +2,8 @@ import { isAbsolute, relative, resolve } from 'node:path';
2
2
  import { RealFileSystemAdapter, } from '@angular-modernizer/core';
3
3
  import { COMPACT_OUTPUT_SCHEMA, limitList, parseCompactOptions, } from './helpers/compact-output.js';
4
4
  import { DEFAULT_HEALTH_SNAPSHOT_PATH, HEALTH_SNAPSHOT_VERSION, compareHealth, compareViolations, parseHealthSnapshot, scopeDifferences, serializeHealthSnapshot, } from './helpers/health-delta.js';
5
+ import { withLibraryImportWarning, } from './helpers/library-import-warning.js';
6
+ import { UNRESOLVED_LIBRARY_IMPORTS_OUTPUT_SCHEMA, WARNINGS_OUTPUT_SCHEMA, } from './helpers/output-contract.js';
5
7
  import { ScanAllTool } from './scan-all.js';
6
8
  /** Violations spelled out per list in the summary; the rest is in the lists. */
7
9
  const SUMMARY_LINES = 15;
@@ -61,7 +63,9 @@ export class CompareHealthTool {
61
63
  'with digits ignored, not by line, so code moving up or down stays unchanged. The first run writes the ' +
62
64
  'baseline (status baseline-created). After a comparison the snapshot is replaced by the current run ' +
63
65
  'unless updateSnapshot is false. A snapshot taken with other rules or include/exclude patterns is not ' +
64
- 'compared (status scope-mismatch) and is only replaced with updateSnapshot: true. currentRun.bySeverity ' +
66
+ 'compared (status scope-mismatch) and is only replaced with updateSnapshot: true; the same for a snapshot ' +
67
+ 'whose library imports resolved while the current ones do not, or the other way round (status ' +
68
+ 'environment-mismatch, missing node_modules). currentRun.bySeverity ' +
65
69
  'and byCategory count all violations. Writes only the snapshot file.';
66
70
  annotations = {
67
71
  readOnlyHint: false,
@@ -124,6 +128,7 @@ export class CompareHealthTool {
124
128
  'baseline-created',
125
129
  'no-baseline',
126
130
  'scope-mismatch',
131
+ 'environment-mismatch',
127
132
  'invalid-snapshot',
128
133
  ],
129
134
  },
@@ -191,6 +196,8 @@ export class CompareHealthTool {
191
196
  rulesRemoved: STRING_LIST,
192
197
  scopeDifferences: STRING_LIST,
193
198
  truncated: { type: 'boolean' },
199
+ ...WARNINGS_OUTPUT_SCHEMA,
200
+ ...UNRESOLVED_LIBRARY_IMPORTS_OUTPUT_SCHEMA,
194
201
  summary: { type: 'string' },
195
202
  },
196
203
  required: [
@@ -234,6 +241,7 @@ export class CompareHealthTool {
234
241
  scope: input.scope,
235
242
  rulesExecuted: [...scanResult.metadata.rulesExecuted].sort(),
236
243
  analyzedFiles: scanResult.counts.analyzedFiles,
244
+ libraryTypesResolved: (scanResult.unresolvedLibraryImports?.imports ?? 0) === 0,
237
245
  violations: scanResult.violations
238
246
  .map(toHealthViolation)
239
247
  .sort(compareViolations),
@@ -243,7 +251,7 @@ export class CompareHealthTool {
243
251
  const differences = previous === undefined
244
252
  ? []
245
253
  : scopeDifferences(previous.scope, current.scope);
246
- const status = decideStatus(stored, differences);
254
+ const status = decideStatus(stored, differences, current);
247
255
  const write = input.updateSnapshot === true ||
248
256
  (input.updateSnapshot === undefined &&
249
257
  (status === 'compared' || status === 'baseline-created'));
@@ -260,7 +268,7 @@ export class CompareHealthTool {
260
268
  differences,
261
269
  compact,
262
270
  });
263
- return output;
271
+ return withLibraryImportWarning(output, scanResult.unresolvedLibraryImports);
264
272
  }
265
273
  async readSnapshot(path) {
266
274
  if (!(await this.fileSystem.exists(path))) {
@@ -334,14 +342,19 @@ function toHealthViolation(v) {
334
342
  ...(v.line === undefined ? {} : { line: v.line }),
335
343
  };
336
344
  }
337
- function decideStatus(stored, differences) {
345
+ function decideStatus(stored, differences, current) {
338
346
  if (!stored.exists) {
339
347
  return 'baseline-created';
340
348
  }
341
349
  if (stored.snapshot === undefined) {
342
350
  return 'invalid-snapshot';
343
351
  }
344
- return differences.length > 0 ? 'scope-mismatch' : 'compared';
352
+ if (differences.length > 0) {
353
+ return 'scope-mismatch';
354
+ }
355
+ return stored.snapshot.libraryTypesResolved === current.libraryTypesResolved
356
+ ? 'compared'
357
+ : 'environment-mismatch';
345
358
  }
346
359
  function buildOutput(parts) {
347
360
  const { root, snapshotLabel, written, previous, current, differences, compact, } = parts;
@@ -470,6 +483,10 @@ function describeOther(status, snapshotLabel, previous, current, differences, wr
470
483
  case 'scope-mismatch':
471
484
  return (`The previous run (${previous?.createdAt ?? '?'}) used another scope, so nothing was compared: ` +
472
485
  `${differences.join('; ')}.${replaced}`);
486
+ case 'environment-mismatch':
487
+ return (`Library imports ${current.libraryTypesResolved ? 'resolve now but did not' : 'do not resolve now but did'} ` +
488
+ `in the previous run (${previous?.createdAt ?? '?'}), so rules that need library types are not ` +
489
+ `comparable and nothing was compared; is node_modules missing or incomplete in one of the runs?${replaced}`);
473
490
  case 'invalid-snapshot':
474
491
  return `${snapshotLabel} is not a readable health snapshot (version ${HEALTH_SNAPSHOT_VERSION}); nothing was compared.${replaced}`;
475
492
  case 'compared':
@@ -1,6 +1,6 @@
1
1
  import { findTsConfig } from './helpers/find-ts-config.js';
2
- import { Kernel, loadConfig } from '@angular-modernizer/core';
3
- import { LibraryExtractionAnalysisRule } from '@angular-modernizer/plugin-architecture';
2
+ import { Kernel, applySuppressionComments, loadConfig } from '@angular-modernizer/core';
3
+ import { LIBRARY_EXTRACTION_DEFAULTS, LibraryExtractionAnalysisRule } from '@angular-modernizer/plugin-architecture';
4
4
  import { ContextFactory } from '@angular-modernizer/plugin-system';
5
5
  import { createPublicApi } from '@angular-modernizer/api';
6
6
  import { glob } from 'glob';
@@ -8,32 +8,45 @@ import { resolve, extname } from 'node:path';
8
8
  import { countList, pageNote } from './helpers/analysis-output.js';
9
9
  import { COUNT_OBJECT, STRING_ARRAY } from './helpers/investigation-schemas.js';
10
10
  /**
11
- * Default folders scanned for candidates. `libs` / `projects` cover Nx and
12
- * Angular CLI library workspaces; `models` / `interfaces` cover data-only
13
- * foundations (interfaces, types, enums, consts).
11
+ * Default folders scanned for candidates, shared with the
12
+ * `architecture:library-extraction-opportunity` rule
13
+ * (['shared', 'common', 'core', 'libs']). Data-only foundations in `models` or
14
+ * `interfaces` are found when those folders are passed as `targetFolders`.
14
15
  */
15
- const DEFAULT_TARGET_FOLDERS = [
16
- 'shared',
17
- 'common',
18
- 'core',
19
- 'libs',
20
- 'models',
21
- 'interfaces',
22
- 'projects',
23
- ];
16
+ const DEFAULT_TARGET_FOLDERS = LIBRARY_EXTRACTION_DEFAULTS.targetFolders;
17
+ /**
18
+ * Default minimum reusability (0-100), shared with the
19
+ * `architecture:library-extraction-opportunity` rule (40).
20
+ */
21
+ const DEFAULT_MIN_REUSABILITY = LIBRARY_EXTRACTION_DEFAULTS.minReusabilityScore;
24
22
  /**
25
- * Default minimum reusability (0-100). Every file in a target folder starts
26
- * at 30 (location bonus), so 40 still requires real signals (few external
27
- * dependencies, barrel export or importers) without demanding 2+ importers
28
- * AND a barrel export like the former 60 did. The scanner itself uses 20.
23
+ * Default minimum cohesion (0-1), shared with the
24
+ * `architecture:library-extraction-opportunity` rule (0.5).
29
25
  */
30
- const DEFAULT_MIN_REUSABILITY = 40;
26
+ const DEFAULT_MIN_COHESION = LIBRARY_EXTRACTION_DEFAULTS.minCohesionScore;
27
+ /**
28
+ * Files that never become library artifacts: tests, e2e code, tool configs and
29
+ * declaration files, matched against the path relative to the project root.
30
+ * The scanner's `**\/` also matches no folder; the root-level forms stay for
31
+ * readability.
32
+ */
33
+ const NON_LIBRARY_PATTERNS = [
34
+ '*.spec.ts',
35
+ '**/*.spec.ts',
36
+ '*.test.ts',
37
+ '**/*.test.ts',
38
+ 'e2e/**',
39
+ '**/e2e/**',
40
+ '*.config.ts',
41
+ '**/*.config.ts',
42
+ '*.d.ts',
43
+ '**/*.d.ts',
44
+ ];
31
45
  /**
32
- * Default minimum cohesion (0-1). 0.5 means at least half of the weighted
33
- * location / naming / import signals agree; the former 0.7 rejected any
34
- * cluster spread over more than one sub-folder. The scanner itself uses 0.3.
46
+ * Files not loaded into the project at all. Spec and test files stay loaded:
47
+ * the scanner counts an artifact's spec file as test evidence.
35
48
  */
36
- const DEFAULT_MIN_COHESION = 0.5;
49
+ const NOT_LOADED_PATTERNS = ['**/e2e/**', '**/*.config.ts'];
37
50
  /** Candidates spelled out in the summary; the rest is in `opportunities`. */
38
51
  const SUMMARY_CANDIDATES = 5;
39
52
  /**
@@ -102,7 +115,7 @@ export class ExtractLibrariesTool {
102
115
  targetFolders: {
103
116
  type: 'array',
104
117
  items: { type: 'string' },
105
- description: "Folders to scan for extraction candidates. Default: ['shared', 'common', 'core', 'libs', 'models', 'interfaces', 'projects']",
118
+ description: "Folders to scan for extraction candidates (whole path segments). Default: ['shared', 'common', 'core', 'libs'], the default of the architecture:library-extraction-opportunity rule; pass models, interfaces or other folders here to scan them.",
106
119
  },
107
120
  minReusabilityScore: {
108
121
  type: 'number',
@@ -202,7 +215,7 @@ export class ExtractLibrariesTool {
202
215
  }
203
216
  const startTime = Date.now();
204
217
  const projectRoot = resolve(params.rootPath);
205
- const targetFolders = params.targetFolders ?? DEFAULT_TARGET_FOLDERS;
218
+ const targetFolders = params.targetFolders ?? [...DEFAULT_TARGET_FOLDERS];
206
219
  const minReusabilityScore = params.minReusabilityScore ?? DEFAULT_MIN_REUSABILITY;
207
220
  const minCohesionScore = params.minCohesionScore ?? DEFAULT_MIN_COHESION;
208
221
  const maxResults = params.maxResults ?? 1000;
@@ -228,9 +241,11 @@ export class ExtractLibrariesTool {
228
241
  '**/dist/**',
229
242
  '**/build/**',
230
243
  '**/.git/**',
244
+ ...NOT_LOADED_PATTERNS,
231
245
  ...(params.excludePatterns ?? []),
232
246
  ],
233
247
  absolute: true,
248
+ nodir: true,
234
249
  });
235
250
  const tsFiles = allFiles.filter((f) => extname(f) === '.ts');
236
251
  for (const filePath of tsFiles) {
@@ -256,7 +271,7 @@ export class ExtractLibrariesTool {
256
271
  targetFolders,
257
272
  minReusabilityScore,
258
273
  minCohesionScore,
259
- excludePatterns: params.excludePatterns ?? [],
274
+ excludePatterns: [...NON_LIBRARY_PATTERNS, ...(params.excludePatterns ?? [])],
260
275
  });
261
276
  const context = ContextFactory.createAnalysisContext({
262
277
  sourceFile: entrySourceFile,
@@ -264,7 +279,7 @@ export class ExtractLibrariesTool {
264
279
  api,
265
280
  config: extractRulesConfig,
266
281
  });
267
- const rawResults = await extractionRule.analyze(context);
282
+ const rawResults = applySuppressionComments(await extractionRule.analyze(context), extractionRule.id, extractRulesConfig, project);
268
283
  // Cast and paginate results
269
284
  const allOpportunities = rawResults;
270
285
  const paginated = allOpportunities.slice(resultOffset, resultOffset + maxResults);
@@ -140,11 +140,12 @@ export class FindAngularSymbolTool {
140
140
  throw new Error(`tsconfig.json not found in projectRoot: ${params.projectRoot}`);
141
141
  }
142
142
  const project = await acquireProject(this.projects, tsConfigPath, ctx);
143
+ const decorators = configuredComponentDecorators(params.projectRoot);
143
144
  const finder = new AngularSymbolFinder(project, {
144
- componentDecorators: configuredComponentDecorators(params.projectRoot),
145
+ componentDecorators: decorators.componentDecorators,
145
146
  });
146
147
  const results = finder.findSymbol(params.query, params.type);
147
- const warnings = this.projects.warnings(tsConfigPath);
148
+ const warnings = [...decorators.warnings, ...this.projects.warnings(tsConfigPath)];
148
149
  const countsByType = {};
149
150
  for (const r of results) {
150
151
  countsByType[r.angularType] = (countsByType[r.angularType] ?? 0) + 1;
@@ -315,8 +315,9 @@ export class FindComponentHostsTool {
315
315
  const file = params.file === undefined || isAbsolute(params.file)
316
316
  ? params.file
317
317
  : resolve(params.projectRoot, params.file);
318
+ const decorators = configuredComponentDecorators(params.projectRoot);
318
319
  const finder = new ComponentHostFinder((await acquireProject(this.projects, tsConfigPath, ctx)), {
319
- componentDecorators: configuredComponentDecorators(params.projectRoot),
320
+ componentDecorators: decorators.componentDecorators,
320
321
  includeTestHosts: params.includeTestHosts === true,
321
322
  includeDynamic: params.includeDynamic !== false,
322
323
  });
@@ -327,7 +328,7 @@ export class FindComponentHostsTool {
327
328
  });
328
329
  const { hosts, coverage, dynamicHosts, candidateHosts, ...rest } = result;
329
330
  const summary = this.buildSummary(params, result);
330
- const warnings = this.projects.warnings(tsConfigPath);
331
+ const warnings = [...decorators.warnings, ...this.projects.warnings(tsConfigPath)];
331
332
  if (compact.summaryOnly) {
332
333
  return withWarnings({
333
334
  ...rest,
@@ -1,5 +1,6 @@
1
1
  import { UsageFinder, } from '@angular-modernizer/api';
2
2
  import { existsSync } from 'node:fs';
3
+ import { isAbsolute, resolve } from 'node:path';
3
4
  import { findTsConfig } from './helpers/find-ts-config.js';
4
5
  import { ProjectCache, acquireProject } from './helpers/project-cache.js';
5
6
  import { COMPACT_OUTPUT_SCHEMA, countByDirectory, limitList, parseCompactOptions, truncationNote, } from './helpers/compact-output.js';
@@ -69,7 +70,7 @@ export class FindUsagesTool {
69
70
  },
70
71
  file: {
71
72
  type: 'string',
72
- description: 'Only report usages located in this file (absolute path, .ts or .html). ' +
73
+ description: 'Only report usages located in this file (absolute, or relative to projectRoot; .ts or .html). ' +
73
74
  'The symbol declaration may live in any file. Optional.',
74
75
  },
75
76
  usageType: {
@@ -166,11 +167,15 @@ export class FindUsagesTool {
166
167
  // The shared ProjectCache: a fresh Project cost 4 to 6 s per call on a
167
168
  // large workspace and sat next to the cached one while the search ran.
168
169
  const project = await acquireProject(this.projects, tsConfigPath, ctx);
170
+ const decorators = configuredComponentDecorators(params.projectRoot);
169
171
  const finder = new UsageFinder(project, {
170
- componentDecorators: configuredComponentDecorators(params.projectRoot),
172
+ componentDecorators: decorators.componentDecorators,
171
173
  });
174
+ const file = params.file === undefined || isAbsolute(params.file)
175
+ ? params.file
176
+ : resolve(params.projectRoot, params.file);
172
177
  const usages = finder.findUsages(params.symbol, {
173
- file: params.file,
178
+ file,
174
179
  usageType: params.usageType,
175
180
  includeTemplates: params.includeTemplates !== false,
176
181
  includeUnresolved: params.includeUnresolved !== false,
@@ -181,19 +186,19 @@ export class FindUsagesTool {
181
186
  }
182
187
  const countsByDirectory = countByDirectory(usages.map((u) => u.file), params.projectRoot, DIRECTORY_DEPTH);
183
188
  const shown = limitList(usages, compact.maxResults);
184
- const warnings = this.projects.warnings(tsConfigPath);
189
+ const warnings = [...decorators.warnings, ...this.projects.warnings(tsConfigPath)];
185
190
  if (compact.summaryOnly) {
186
191
  return withWarnings({
187
192
  totalCount: usages.length,
188
193
  truncated: false,
189
- summary: this.buildCompactSummary(params.symbol, usages, countsByType, countsByDirectory, params.file),
194
+ summary: this.buildCompactSummary(params.symbol, usages, countsByType, countsByDirectory, file, params.usageType),
190
195
  countsByType,
191
196
  countsByDirectory,
192
197
  tsConfigPath,
193
198
  }, warnings);
194
199
  }
195
200
  const note = truncationNote(shown.items.length, usages.length, 'usages');
196
- const summary = this.buildSummary(params.symbol, shown.items, params.file);
201
+ const summary = this.buildSummary(params.symbol, shown.items, file, params.usageType);
197
202
  return withWarnings({
198
203
  usages: shown.items,
199
204
  totalCount: usages.length,
@@ -204,9 +209,9 @@ export class FindUsagesTool {
204
209
  tsConfigPath,
205
210
  }, warnings);
206
211
  }
207
- buildCompactSummary(symbol, usages, countsByType, countsByDirectory, file) {
212
+ buildCompactSummary(symbol, usages, countsByType, countsByDirectory, file, usageType) {
208
213
  if (usages.length === 0) {
209
- return this.buildSummary(symbol, usages, file);
214
+ return this.buildSummary(symbol, usages, file, usageType);
210
215
  }
211
216
  const fileCount = new Set(usages.map((u) => u.file)).size;
212
217
  const types = Object.entries(countsByType)
@@ -214,7 +219,7 @@ export class FindUsagesTool {
214
219
  .join(', ');
215
220
  const directories = Object.entries(countsByDirectory);
216
221
  const lines = [
217
- `Found ${usages.length} usage(s) of '${symbol}' in ${fileCount} file(s). By type: ${types}.`,
222
+ `Found ${usages.length} usage(s)${ofType(usageType)} of '${symbol}' in ${fileCount} file(s). By type: ${types}.`,
218
223
  'Top directories:',
219
224
  ...directories
220
225
  .slice(0, SUMMARY_TOP_DIRECTORIES)
@@ -225,10 +230,10 @@ export class FindUsagesTool {
225
230
  }
226
231
  return lines.join('\n');
227
232
  }
228
- buildSummary(symbol, usages, file) {
233
+ buildSummary(symbol, usages, file, usageType) {
229
234
  if (usages.length === 0) {
230
235
  const scope = file ? `in ${file}` : 'across the project';
231
- return (`No usages of '${symbol}' found ${scope}. Only files in the tsconfig program ` +
236
+ return (`No usages${ofType(usageType)} of '${symbol}' found ${scope}. Only files in the tsconfig program ` +
232
237
  'and component templates were searched; verify with search-codebase (text mode) ' +
233
238
  'before treating this as proof of absence.');
234
239
  }
@@ -239,7 +244,7 @@ export class FindUsagesTool {
239
244
  byFile.set(u.file, list);
240
245
  }
241
246
  const lines = [
242
- `Found ${usages.length} usage(s) of '${symbol}' across ${byFile.size} file(s):`,
247
+ `Found ${usages.length} usage(s)${ofType(usageType)} of '${symbol}' across ${byFile.size} file(s):`,
243
248
  ];
244
249
  for (const [filePath, fileUsages] of byFile) {
245
250
  lines.push(` ${filePath} (${fileUsages.length})`);
@@ -256,4 +261,8 @@ export class FindUsagesTool {
256
261
  return lines.join('\n');
257
262
  }
258
263
  }
264
+ /** Names the `usageType` filter in the summary (` of type call`), empty without one. */
265
+ function ofType(usageType) {
266
+ return usageType === undefined ? '' : ` of type ${usageType}`;
267
+ }
259
268
  //# sourceMappingURL=find-usages.js.map
@@ -1,5 +1,6 @@
1
1
  import { CallGraphBuilder, } from '@angular-modernizer/api';
2
2
  import { existsSync } from 'node:fs';
3
+ import { isAbsolute, resolve } from 'node:path';
3
4
  import { findTsConfig } from './helpers/find-ts-config.js';
4
5
  import { ProjectCache, acquireProject } from './helpers/project-cache.js';
5
6
  import { WARNINGS_OUTPUT_SCHEMA, withWarnings, } from './helpers/output-contract.js';
@@ -64,6 +65,9 @@ export class GetCallGraphTool {
64
65
  'Callers of component members include calls from the component template as leaf nodes ' +
65
66
  '(kind "template", template file and line, snippet), also from templates of subclasses that inherit the member ' +
66
67
  '(className of the subclass, inheritedFrom of the declaring class; a subclass overriding it is left out). ' +
68
+ 'Calls at the top level of a file, also inside anonymous callbacks there (describe/it blocks), are leaf callers ' +
69
+ 'with name "<module>" and kind "module" (file, line and snippet of the call); calls in anonymous callbacks ' +
70
+ 'inside a method or function count for that method or function. ' +
67
71
  'Use method "ClassName.constructor" to see what runs transitively during construction. ' +
68
72
  'Use after parse-stack-trace to trace error propagation through the call hierarchy.';
69
73
  /**
@@ -81,7 +85,7 @@ export class GetCallGraphTool {
81
85
  },
82
86
  file: {
83
87
  type: 'string',
84
- description: 'Absolute path of the source file containing the method.',
88
+ description: 'Source file containing the method (absolute path, or relative to projectRoot).',
85
89
  },
86
90
  projectRoot: {
87
91
  type: 'string',
@@ -164,6 +168,12 @@ export class GetCallGraphTool {
164
168
  if (!existsSync(params.projectRoot)) {
165
169
  throw new Error(`projectRoot does not exist: ${params.projectRoot}`);
166
170
  }
171
+ const filePath = isAbsolute(params.file)
172
+ ? params.file
173
+ : resolve(params.projectRoot, params.file);
174
+ if (!existsSync(filePath)) {
175
+ throw new Error(`file does not exist: ${filePath}`);
176
+ }
167
177
  const tsConfigPath = findTsConfig(params.projectRoot);
168
178
  if (!tsConfigPath) {
169
179
  throw new Error(`tsconfig.json not found in projectRoot: ${params.projectRoot}`);
@@ -180,7 +190,7 @@ export class GetCallGraphTool {
180
190
  maxNodes: params.maxNodes ?? 200,
181
191
  includeLifecycleHooks: params.includeLifecycleHooks ?? false,
182
192
  };
183
- const result = graphBuilder.buildCallGraph(params.method, params.file, options);
193
+ const result = graphBuilder.buildCallGraph(params.method, filePath, options);
184
194
  const summary = this.buildSummary(params.method, result);
185
195
  if (params.summaryOnly) {
186
196
  const { callers: _callers, callees: _callees, ...rest } = result;
@@ -233,6 +243,9 @@ export class GetCallGraphTool {
233
243
  return lines;
234
244
  }
235
245
  label(node) {
246
+ if (node.kind === 'module') {
247
+ return `module level: ${node.snippet ?? ''}`;
248
+ }
236
249
  if (node.kind === 'template') {
237
250
  const inherited = node.inheritedFrom === undefined ? '' : ` (inherits ${node.inheritedFrom})`;
238
251
  return `template of ${node.className ?? 'component'}${inherited}: ${node.snippet ?? ''}`;
@@ -3,7 +3,7 @@ import { getOperationProgress } from './get-operation-progress.js';
3
3
  type OperationProgress = Awaited<ReturnType<typeof getOperationProgress>>;
4
4
  /**
5
5
  * MCP tool for querying the progress of streaming operations (deprecated, kept
6
- * in 1.x): polls an operation started with `streaming: true` by transform-code
6
+ * in 2.x): polls an operation started with `streaming: true` by transform-code
7
7
  * or scan-architecture.
8
8
  */
9
9
  export declare class GetOperationProgressTool implements MCPTool {
@@ -30,7 +30,7 @@ function describeProgress(progress) {
30
30
  }
31
31
  /**
32
32
  * MCP tool for querying the progress of streaming operations (deprecated, kept
33
- * in 1.x): polls an operation started with `streaming: true` by transform-code
33
+ * in 2.x): polls an operation started with `streaming: true` by transform-code
34
34
  * or scan-architecture.
35
35
  */
36
36
  export class GetOperationProgressTool {
@@ -42,7 +42,7 @@ export class GetOperationProgressTool {
42
42
  idempotentHint: true,
43
43
  openWorldHint: false,
44
44
  };
45
- description = 'Deprecated, kept in 1.x: polls an operation started with streaming: true (transform-code, scan-architecture). ' +
45
+ description = 'Deprecated, kept in 2.x: polls an operation started with streaming: true (transform-code, scan-architecture). ' +
46
46
  'Call those tools synchronously instead: they send MCP progress notifications when the request has a progressToken ' +
47
47
  'and stop on notifications/cancelled. ' +
48
48
  'Get progress for a streaming operation (transformation or analysis). ' +
@@ -65,7 +65,10 @@ export declare function getOperationProgress(input: GetOperationProgressInput):
65
65
  }[];
66
66
  /** Number of all events of the operation, regardless of `sinceTimestamp`. */
67
67
  totalEvents: number;
68
- /** Milliseconds since the operation started. */
68
+ /**
69
+ * Milliseconds from the start to now for a running operation, to the moment
70
+ * it completed, failed, timed out or was cancelled for a finished one.
71
+ */
69
72
  elapsedTime: number;
70
73
  /** Estimated milliseconds until completion; only for running operations with progress. */
71
74
  eta?: number;
@@ -36,8 +36,12 @@ export async function getOperationProgress(input) {
36
36
  // Get metadata
37
37
  const metadata = store.getMetadata(operationId);
38
38
  const events = store.getEvents(operationId, sinceTimestamp);
39
- // Calculate elapsed time
40
- const elapsedTime = Date.now() - metadata.startTime;
39
+ // A finished operation's clock stops when it completed, failed, timed out
40
+ // or was cancelled; only a running operation counts up to now.
41
+ const endTime = metadata.status === 'running'
42
+ ? Date.now()
43
+ : (metadata.completedAt ?? Date.now());
44
+ const elapsedTime = endTime - metadata.startTime;
41
45
  // Estimate ETA based on progress (only for running operations)
42
46
  let eta;
43
47
  if (metadata.status === 'running' && events.length > 0) {
@@ -135,7 +135,8 @@ export declare const SCAN_VIOLATION_SCHEMA: {
135
135
  readonly required: readonly ["ruleId", "severity", "message", "filePath"];
136
136
  };
137
137
  /**
138
- * Run details of a scan that stopped early (time budget or cancellation);
138
+ * Run details of a scan that stopped early (time budget or cancellation) or,
139
+ * in scan-architecture, left files out at its `maxFiles` cap;
139
140
  * scan-architecture always reports them.
140
141
  */
141
142
  export declare const SCAN_EXECUTION_SCHEMA: {
@@ -153,6 +154,9 @@ export declare const SCAN_EXECUTION_SCHEMA: {
153
154
  readonly skippedFiles: {
154
155
  readonly type: "integer";
155
156
  };
157
+ readonly scopeFiles: {
158
+ readonly type: "integer";
159
+ };
156
160
  readonly ruleTimings: {
157
161
  readonly type: "array";
158
162
  readonly items: {
@@ -165,6 +169,33 @@ export declare const SCAN_EXECUTION_SCHEMA: {
165
169
  };
166
170
  readonly required: readonly ["incomplete", "skippedFiles"];
167
171
  };
172
+ /**
173
+ * Notice for an `orchestration` argument of scan-all, scan-solid or
174
+ * scan-angular. They always run in the scan worker; the argument used to be
175
+ * ignored while the result claimed a parallel run.
176
+ */
177
+ export declare const SCAN_ORCHESTRATION_NOTICE = "orchestration is deprecated and has no effect: the scan always runs in the scan worker. Leave it unset.";
178
+ /**
179
+ * Input schema of the deprecated `orchestration` argument of scan-all,
180
+ * scan-solid and scan-angular, kept so 1.x callers are not rejected.
181
+ */
182
+ export declare const DEPRECATED_SCAN_ORCHESTRATION_SCHEMA: {
183
+ readonly type: "object";
184
+ readonly description: "Deprecated, no effect, kept in 2.x: the scan always runs in the scan worker and answers with a notice in warnings. Leave unset.";
185
+ readonly deprecated: true;
186
+ readonly properties: {
187
+ readonly parallel: {
188
+ readonly type: "boolean";
189
+ readonly description: "Deprecated, no effect.";
190
+ readonly deprecated: true;
191
+ };
192
+ readonly maxWorkers: {
193
+ readonly type: "number";
194
+ readonly description: "Deprecated, no effect.";
195
+ readonly deprecated: true;
196
+ };
197
+ };
198
+ };
168
199
  /**
169
200
  * Output schema of a scan: violations, counts, metadata and summary, plus
170
201
  * the tool's own fields. Only `counts`, `metadata` and `summary` are required.
@@ -4,6 +4,7 @@
4
4
  * Schema pieces and summary helpers shared by analyze-project and the scans.
5
5
  * Objects stay open, see `output-contract.ts`.
6
6
  */
7
+ import { UNRESOLVED_LIBRARY_IMPORTS_OUTPUT_SCHEMA, WARNINGS_OUTPUT_SCHEMA, } from './output-contract.js';
7
8
  /** `pagination` of a paged result list. */
8
9
  export const PAGINATION_SCHEMA = {
9
10
  type: 'object',
@@ -79,7 +80,8 @@ export const SCAN_VIOLATION_SCHEMA = {
79
80
  required: ['ruleId', 'severity', 'message', 'filePath'],
80
81
  };
81
82
  /**
82
- * Run details of a scan that stopped early (time budget or cancellation);
83
+ * Run details of a scan that stopped early (time budget or cancellation) or,
84
+ * in scan-architecture, left files out at its `maxFiles` cap;
83
85
  * scan-architecture always reports them.
84
86
  */
85
87
  export const SCAN_EXECUTION_SCHEMA = {
@@ -89,11 +91,31 @@ export const SCAN_EXECUTION_SCHEMA = {
89
91
  incomplete: { type: 'boolean' },
90
92
  stopReason: { type: 'string' },
91
93
  skippedFiles: { type: 'integer' },
94
+ scopeFiles: { type: 'integer' },
92
95
  ruleTimings: { type: 'array', items: { type: 'object' } },
93
96
  note: { type: 'string' },
94
97
  },
95
98
  required: ['incomplete', 'skippedFiles'],
96
99
  };
100
+ /**
101
+ * Notice for an `orchestration` argument of scan-all, scan-solid or
102
+ * scan-angular. They always run in the scan worker; the argument used to be
103
+ * ignored while the result claimed a parallel run.
104
+ */
105
+ export const SCAN_ORCHESTRATION_NOTICE = 'orchestration is deprecated and has no effect: the scan always runs in the scan worker. Leave it unset.';
106
+ /**
107
+ * Input schema of the deprecated `orchestration` argument of scan-all,
108
+ * scan-solid and scan-angular, kept so 1.x callers are not rejected.
109
+ */
110
+ export const DEPRECATED_SCAN_ORCHESTRATION_SCHEMA = {
111
+ type: 'object',
112
+ description: 'Deprecated, no effect, kept in 2.x: the scan always runs in the scan worker and answers with a notice in warnings. Leave unset.',
113
+ deprecated: true,
114
+ properties: {
115
+ parallel: { type: 'boolean', description: 'Deprecated, no effect.', deprecated: true },
116
+ maxWorkers: { type: 'number', description: 'Deprecated, no effect.', deprecated: true },
117
+ },
118
+ };
97
119
  /**
98
120
  * Output schema of a scan: violations, counts, metadata and summary, plus
99
121
  * the tool's own fields. Only `counts`, `metadata` and `summary` are required.
@@ -115,6 +137,8 @@ export function scanOutputSchema(extra = {}) {
115
137
  },
116
138
  pagination: PAGINATION_SCHEMA,
117
139
  orchestration: { type: 'object' },
140
+ ...WARNINGS_OUTPUT_SCHEMA,
141
+ ...UNRESOLVED_LIBRARY_IMPORTS_OUTPUT_SCHEMA,
118
142
  ...extra,
119
143
  summary: { type: 'string' },
120
144
  },
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @angular-modernizer/adapter-mcp - Build cache clearing (`cacheStrategy: 'clear'`)
3
+ *
4
+ * run-build and validate-transformation remove the build caches of the project
5
+ * before an incremental build. Each cache is resolved through symlinks first and
6
+ * removed only when it lies inside the project root and not under `node_modules`:
7
+ * a linked or shared `node_modules` (pnpm, monorepos, project copies) leads out
8
+ * of the project, and `rm -rf` used to delete there.
9
+ */
10
+ /** Outcome of {@link clearBuildCaches}. */
11
+ export interface CacheClearResult {
12
+ /** Caches removed, relative to the project root. */
13
+ cleared: string[];
14
+ /** Caches left in place, with the reason. */
15
+ warnings: string[];
16
+ }
17
+ /**
18
+ * Remove the Angular CLI cache and, in an Nx workspace, the Nx cache of a project.
19
+ *
20
+ * Missing caches are skipped silently; a cache that resolves outside the project
21
+ * root or under `node_modules`, or that cannot be removed, is left in place and
22
+ * reported in `warnings`.
23
+ *
24
+ * @param projectRoot - Root folder of the project
25
+ */
26
+ export declare function clearBuildCaches(projectRoot: string): CacheClearResult;
27
+ //# sourceMappingURL=build-cache.d.ts.map