@angular-modernizer/adapter-mcp 1.0.0 → 1.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 (129) hide show
  1. package/README.md +78 -64
  2. package/dist/cli.js +8 -0
  3. package/dist/core/project-analyzer.d.ts +3 -12
  4. package/dist/core/project-analyzer.js +3 -12
  5. package/dist/index.d.ts +118 -3
  6. package/dist/index.js +46 -3
  7. package/dist/mcp-watcher.d.ts +28 -8
  8. package/dist/mcp-watcher.js +7 -7
  9. package/dist/scan-host/scan-host.d.ts +119 -0
  10. package/dist/scan-host/scan-host.js +376 -0
  11. package/dist/scan-host/scan-protocol.d.ts +35 -0
  12. package/dist/scan-host/scan-protocol.js +6 -0
  13. package/dist/scan-host/scan-worker.d.ts +14 -0
  14. package/dist/scan-host/scan-worker.js +48 -0
  15. package/dist/server/limited-stdio-transport.d.ts +7 -0
  16. package/dist/server/mcp-server.d.ts +11 -7
  17. package/dist/server/mcp-server.js +4 -7
  18. package/dist/server/sdk-server.d.ts +1 -0
  19. package/dist/server/tool-registry.d.ts +3 -7
  20. package/dist/server/tool-registry.js +1 -7
  21. package/dist/streaming/progress-store.d.ts +22 -5
  22. package/dist/streaming/progress-store.js +9 -5
  23. package/dist/tools/analyze-build-impact.d.ts +56 -34
  24. package/dist/tools/analyze-build-impact.js +30 -25
  25. package/dist/tools/analyze-core-to-shared.d.ts +42 -12
  26. package/dist/tools/analyze-core-to-shared.js +11 -10
  27. package/dist/tools/analyze-parser-performance.d.ts +23 -22
  28. package/dist/tools/analyze-parser-performance.js +20 -18
  29. package/dist/tools/analyze-project.d.ts +82 -12
  30. package/dist/tools/analyze-project.js +98 -101
  31. package/dist/tools/check-incremental-compatibility.d.ts +13 -11
  32. package/dist/tools/check-incremental-compatibility.js +11 -8
  33. package/dist/tools/collect-feedback.d.ts +41 -26
  34. package/dist/tools/collect-feedback.js +32 -23
  35. package/dist/tools/compare-health.d.ts +76 -19
  36. package/dist/tools/compare-health.js +26 -19
  37. package/dist/tools/extract-libraries.d.ts +44 -20
  38. package/dist/tools/extract-libraries.js +16 -17
  39. package/dist/tools/find-angular-symbol.d.ts +25 -23
  40. package/dist/tools/find-angular-symbol.js +17 -14
  41. package/dist/tools/find-component-hosts.d.ts +31 -25
  42. package/dist/tools/find-component-hosts.js +24 -21
  43. package/dist/tools/find-usages.d.ts +23 -21
  44. package/dist/tools/find-usages.js +19 -16
  45. package/dist/tools/get-bootstrap-execution.d.ts +33 -25
  46. package/dist/tools/get-bootstrap-execution.js +25 -22
  47. package/dist/tools/get-call-graph.d.ts +18 -13
  48. package/dist/tools/get-call-graph.js +24 -21
  49. package/dist/tools/get-operation-progress-tool.d.ts +12 -6
  50. package/dist/tools/get-operation-progress-tool.js +11 -6
  51. package/dist/tools/get-operation-progress.d.ts +26 -0
  52. package/dist/tools/helpers/analysis-output.d.ts +5 -0
  53. package/dist/tools/helpers/batch-kernel.d.ts +14 -0
  54. package/dist/tools/helpers/batch-kernel.js +12 -0
  55. package/dist/tools/helpers/compact-output.d.ts +2 -1
  56. package/dist/tools/helpers/compact-output.js +2 -1
  57. package/dist/tools/helpers/health-delta.d.ts +27 -14
  58. package/dist/tools/helpers/health-delta.js +11 -14
  59. package/dist/tools/helpers/project-cache.d.ts +50 -34
  60. package/dist/tools/helpers/project-cache.js +33 -34
  61. package/dist/tools/helpers/rule-runner.d.ts +23 -16
  62. package/dist/tools/helpers/rule-runner.js +24 -17
  63. package/dist/tools/helpers/scan-engine.d.ts +107 -0
  64. package/dist/tools/helpers/scan-engine.js +197 -0
  65. package/dist/tools/helpers/suggestion-generator.d.ts +9 -13
  66. package/dist/tools/helpers/suggestion-generator.js +0 -12
  67. package/dist/tools/helpers/tool-cache.d.ts +11 -0
  68. package/dist/tools/helpers/tool-cache.js +15 -0
  69. package/dist/tools/helpers/tool-context.d.ts +11 -8
  70. package/dist/tools/helpers/tool-context.js +5 -8
  71. package/dist/tools/inspect-form-group.d.ts +32 -25
  72. package/dist/tools/inspect-form-group.js +24 -21
  73. package/dist/tools/inspect-i18n.d.ts +28 -22
  74. package/dist/tools/inspect-i18n.js +20 -17
  75. package/dist/tools/inspect-template.d.ts +31 -24
  76. package/dist/tools/inspect-template.js +23 -20
  77. package/dist/tools/learn-patterns.d.ts +88 -12
  78. package/dist/tools/learn-patterns.js +17 -11
  79. package/dist/tools/list-imports.d.ts +42 -25
  80. package/dist/tools/list-imports.js +23 -20
  81. package/dist/tools/orchestrate-migration.d.ts +31 -9
  82. package/dist/tools/orchestrate-migration.js +12 -7
  83. package/dist/tools/parse-stack-trace.d.ts +23 -21
  84. package/dist/tools/parse-stack-trace.js +10 -7
  85. package/dist/tools/plan-migration.d.ts +65 -25
  86. package/dist/tools/plan-migration.js +19 -19
  87. package/dist/tools/resolve-type.d.ts +19 -9
  88. package/dist/tools/resolve-type.js +19 -11
  89. package/dist/tools/review-feedback.d.ts +27 -24
  90. package/dist/tools/review-feedback.js +24 -20
  91. package/dist/tools/rollback-changes.d.ts +13 -9
  92. package/dist/tools/rollback-changes.js +10 -7
  93. package/dist/tools/run-angular-cli.d.ts +12 -10
  94. package/dist/tools/run-angular-cli.js +11 -8
  95. package/dist/tools/run-build.d.ts +13 -11
  96. package/dist/tools/run-build.js +11 -8
  97. package/dist/tools/run-schematic.d.ts +12 -10
  98. package/dist/tools/run-schematic.js +11 -8
  99. package/dist/tools/scan-all.d.ts +69 -12
  100. package/dist/tools/scan-all.js +55 -122
  101. package/dist/tools/scan-angular.d.ts +41 -9
  102. package/dist/tools/scan-angular.js +66 -135
  103. package/dist/tools/scan-architecture.d.ts +75 -14
  104. package/dist/tools/scan-architecture.js +180 -185
  105. package/dist/tools/scan-solid.d.ts +40 -9
  106. package/dist/tools/scan-solid.js +64 -133
  107. package/dist/tools/search-codebase.d.ts +30 -24
  108. package/dist/tools/search-codebase.js +13 -10
  109. package/dist/tools/server-status.d.ts +116 -24
  110. package/dist/tools/server-status.js +85 -26
  111. package/dist/tools/suggest-improvements.d.ts +22 -19
  112. package/dist/tools/suggest-improvements.js +21 -17
  113. package/dist/tools/trace-output-flow.d.ts +32 -25
  114. package/dist/tools/trace-output-flow.js +24 -21
  115. package/dist/tools/transform-code.d.ts +71 -10
  116. package/dist/tools/transform-code.js +60 -42
  117. package/dist/tools/validate-before-transform.d.ts +24 -9
  118. package/dist/tools/validate-before-transform.js +10 -7
  119. package/dist/tools/validate-project-compatibility.d.ts +18 -13
  120. package/dist/tools/validate-project-compatibility.js +17 -11
  121. package/dist/tools/validate-transformation.d.ts +28 -11
  122. package/dist/tools/validate-transformation.js +14 -8
  123. package/dist/tools/verify-citations.d.ts +37 -16
  124. package/dist/tools/verify-citations.js +19 -16
  125. package/dist/types.d.ts +40 -10
  126. package/dist/types.js +0 -5
  127. package/package.json +12 -18
  128. package/dist/tools/shared/scan-types.d.ts +0 -200
  129. package/dist/tools/shared/scan-types.js +0 -7
@@ -1,18 +1,3 @@
1
- /**
2
- * @angular-modernizer/adapter-mcp - Rule runner for scan tools
3
- *
4
- * Runs analysis rules over a file list with a time budget:
5
- * - all files are added to the project first, so project-wide rules
6
- * (library extraction, circular dependencies, type resolution) see the same,
7
- * complete project for every file instead of a prefix that grows per file;
8
- * the load yields and checks the signal per file as well
9
- * - the budget and the abort signal are checked between files; a rule that
10
- * is running cannot be interrupted (analysis is synchronous CPU work), so
11
- * the overrun is at most one file. With a signal the loop yields to the
12
- * event loop once per file, otherwise `notifications/cancelled` is not read
13
- * before the scan ends
14
- * - time per rule is recorded so slow rules show up in the result
15
- */
16
1
  import type { Project } from 'ts-morph';
17
2
  import { type AnalysisRule } from '@angular-modernizer/plugin-system';
18
3
  /** Default scan time budget: 5 minutes. */
@@ -29,8 +14,11 @@ export interface RuleRunnerViolation {
29
14
  suggestedFix?: string;
30
15
  metadata?: Record<string, unknown>;
31
16
  }
17
+ /** Total analysis time of one rule over all files of a scan. */
32
18
  export interface RuleTiming {
19
+ /** Rule id. */
33
20
  ruleId: string;
21
+ /** Time spent in the rule in milliseconds, summed over all files. */
34
22
  ms: number;
35
23
  }
36
24
  export interface RuleRunResult {
@@ -59,14 +47,33 @@ export interface RuleRunOptions {
59
47
  signal?: AbortSignal;
60
48
  isCancelled?: () => boolean;
61
49
  onFileAnalyzed?: (analyzed: number, total: number, violations: number) => void;
50
+ /** Findings of each analyzed file, in analysis order. */
51
+ onFileResults?: (filePath: string, violations: RuleRunnerViolation[]) => void;
52
+ /** Keep the findings in `violations` (default); `false` leaves it empty. */
53
+ collect?: boolean;
62
54
  }
63
55
  /**
64
56
  * Parse the `maxDurationMs` tool parameter.
65
57
  */
66
58
  export declare function parseMaxDurationMs(value: unknown): number;
59
+ /**
60
+ * Runs analysis rules over a file list with a time budget.
61
+ *
62
+ * @remarks
63
+ * - All files are added to the project first, so project-wide rules
64
+ * (library extraction, circular dependencies, type resolution) see the same,
65
+ * complete project for every file instead of a prefix that grows per file;
66
+ * the load yields and checks the signal per file as well.
67
+ * - The budget and the abort signal are checked between files; a rule that
68
+ * is running cannot be interrupted (analysis is synchronous CPU work), so
69
+ * the overrun is at most one file. With a signal the loop yields to the
70
+ * event loop once per file, otherwise `notifications/cancelled` is not read
71
+ * before the scan ends.
72
+ * - Time per rule is recorded so slow rules show up in the result.
73
+ */
67
74
  export declare function runRulesOverFiles(options: RuleRunOptions): Promise<RuleRunResult>;
68
75
  /**
69
76
  * Human-readable note for an incomplete run.
70
77
  */
71
- export declare function incompleteNote(result: RuleRunResult, budgetMs: number): string | undefined;
78
+ export declare function incompleteNote(result: Omit<RuleRunResult, 'violations'>, budgetMs: number): string | undefined;
72
79
  //# sourceMappingURL=rule-runner.d.ts.map
@@ -1,18 +1,3 @@
1
- /**
2
- * @angular-modernizer/adapter-mcp - Rule runner for scan tools
3
- *
4
- * Runs analysis rules over a file list with a time budget:
5
- * - all files are added to the project first, so project-wide rules
6
- * (library extraction, circular dependencies, type resolution) see the same,
7
- * complete project for every file instead of a prefix that grows per file;
8
- * the load yields and checks the signal per file as well
9
- * - the budget and the abort signal are checked between files; a rule that
10
- * is running cannot be interrupted (analysis is synchronous CPU work), so
11
- * the overrun is at most one file. With a signal the loop yields to the
12
- * event loop once per file, otherwise `notifications/cancelled` is not read
13
- * before the scan ends
14
- * - time per rule is recorded so slow rules show up in the result
15
- */
16
1
  import { ContextFactory, } from '@angular-modernizer/plugin-system';
17
2
  import { yieldIfCancellable } from './tool-context.js';
18
3
  import { loadSourceFiles } from './load-source-files.js';
@@ -30,6 +15,21 @@ export function parseMaxDurationMs(value) {
30
15
  }
31
16
  return value;
32
17
  }
18
+ /**
19
+ * Runs analysis rules over a file list with a time budget.
20
+ *
21
+ * @remarks
22
+ * - All files are added to the project first, so project-wide rules
23
+ * (library extraction, circular dependencies, type resolution) see the same,
24
+ * complete project for every file instead of a prefix that grows per file;
25
+ * the load yields and checks the signal per file as well.
26
+ * - The budget and the abort signal are checked between files; a rule that
27
+ * is running cannot be interrupted (analysis is synchronous CPU work), so
28
+ * the overrun is at most one file. With a signal the loop yields to the
29
+ * event loop once per file, otherwise `notifications/cancelled` is not read
30
+ * before the scan ends.
31
+ * - Time per rule is recorded so slow rules show up in the result.
32
+ */
33
33
  export async function runRulesOverFiles(options) {
34
34
  const startTime = options.startTime ?? Date.now();
35
35
  const budget = options.maxDurationMs ?? DEFAULT_MAX_DURATION_MS;
@@ -55,6 +55,7 @@ export async function runRulesOverFiles(options) {
55
55
  const violations = [];
56
56
  const timings = new Map();
57
57
  let filesAnalyzed = 0;
58
+ let violationCount = 0;
58
59
  let stopReason;
59
60
  for (const sourceFile of sourceFiles) {
60
61
  await yieldIfCancellable(options.signal);
@@ -66,6 +67,7 @@ export async function runRulesOverFiles(options) {
66
67
  stopReason = 'time-budget';
67
68
  break;
68
69
  }
70
+ const fileViolations = [];
69
71
  try {
70
72
  for (const rule of rules) {
71
73
  const ruleStart = Date.now();
@@ -77,15 +79,20 @@ export async function runRulesOverFiles(options) {
77
79
  }));
78
80
  timings.set(rule.id, (timings.get(rule.id) ?? 0) + Date.now() - ruleStart);
79
81
  for (const result of results) {
80
- violations.push(toViolation(rule, result));
82
+ fileViolations.push(toViolation(rule, result));
81
83
  }
82
84
  }
83
85
  }
84
86
  catch (error) {
85
87
  console.warn(`Error analyzing ${sourceFile.getFilePath()}:`, error);
86
88
  }
89
+ if (options.collect !== false) {
90
+ violations.push(...fileViolations);
91
+ }
92
+ violationCount += fileViolations.length;
87
93
  filesAnalyzed++;
88
- options.onFileAnalyzed?.(filesAnalyzed, sourceFiles.length, violations.length);
94
+ options.onFileResults?.(sourceFile.getFilePath(), fileViolations);
95
+ options.onFileAnalyzed?.(filesAnalyzed, sourceFiles.length, violationCount);
89
96
  }
90
97
  return {
91
98
  violations,
@@ -0,0 +1,107 @@
1
+ /**
2
+ * @angular-modernizer/adapter-mcp - Analysis part of the scan tools
3
+ *
4
+ * The part of a scan between "build the kernel" and "all files analyzed":
5
+ * kernel, project, rules, file loading and rule runs. It runs in a scan worker
6
+ * (`scan-host/`) or, as fallback and under Jest, in the calling thread; both
7
+ * paths run this function, so they produce the same findings in the same
8
+ * order. Glob, scan cache, result window, progress and the MCP protocol stay
9
+ * with the tool on the main thread.
10
+ *
11
+ * The engine does not write to disk (the kernel gets no cache config), so a
12
+ * worker killed in the middle leaves nothing half written.
13
+ */
14
+ import { type RuleRunResult, type RuleRunnerViolation } from './rule-runner.js';
15
+ /** Plugins a scan runs. */
16
+ export type ScanPluginSet = 'all' | 'solid' | 'angular' | 'architecture' | 'analyzer';
17
+ /**
18
+ * What to analyze and how. Plain data: it is the `workerData` of a scan
19
+ * worker.
20
+ */
21
+ export interface ScanSpec {
22
+ /** Tool name, for logs and server-status. */
23
+ tool: string;
24
+ plugins: ScanPluginSet;
25
+ tsConfigPath: string;
26
+ /** Root whose `.angular-modernizer.json` supplies the rule configuration. */
27
+ rootPath: string;
28
+ /** Files to analyze, absolute, in analysis order. */
29
+ files: string[];
30
+ /**
31
+ * - `batches`: per batch remove all files, add the batch, analyze it
32
+ * (scan-all, scan-solid, scan-angular).
33
+ * - `runner`: add all files, then run the rules with the time budget
34
+ * (scan-architecture).
35
+ * - `sequential`: project from the tsconfig, files added one by one
36
+ * (analyze-project).
37
+ */
38
+ mode: 'batches' | 'runner' | 'sequential';
39
+ /** Batch size of `batches`. */
40
+ batchSize?: number;
41
+ /**
42
+ * `batches`: analyze every file the project holds after the load
43
+ * (scan-solid, scan-angular) instead of the loaded ones (scan-all).
44
+ */
45
+ analyzeProjectFiles?: boolean;
46
+ /** Record the template dependencies of each analyzed file (scan-all cache). */
47
+ templateDependencies?: boolean;
48
+ /** `runner`: run only these rules; none left is an error. */
49
+ ruleIds?: string[];
50
+ /** `runner`: time budget in ms, `0` disables it. */
51
+ maxDurationMs?: number;
52
+ /** `runner`: start of the budget (epoch ms). */
53
+ startTime?: number;
54
+ }
55
+ /** A finding as the scans collect it. */
56
+ export interface ScanFinding {
57
+ /** Set by the `runner` mode only. */
58
+ id?: string;
59
+ ruleId: string;
60
+ severity: RuleRunnerViolation['severity'];
61
+ message: string;
62
+ filePath: string;
63
+ line?: number;
64
+ column?: number;
65
+ category: string;
66
+ suggestedFix?: string;
67
+ metadata?: Record<string, unknown>;
68
+ }
69
+ /** Findings of one analyzed file. */
70
+ export interface ScanFileEvent {
71
+ /** The analyzed file. */
72
+ filePath: string;
73
+ /** Its findings, in rule order; they may point at other files (templates). */
74
+ findings: ScanFinding[];
75
+ /** Template dependencies, only with {@link ScanSpec.templateDependencies}. */
76
+ dependencies?: string[];
77
+ }
78
+ /** Receives the engine's output as it is produced. */
79
+ export interface ScanSink {
80
+ /** Rules are known (after `kernel.initialize()`). */
81
+ ready?(ruleIds: string[]): void;
82
+ /** One file is analyzed. */
83
+ file(event: ScanFileEvent): void;
84
+ /** `batches`: a batch of `files` files is done, failed loads included. */
85
+ batchDone?(files: number): void;
86
+ }
87
+ /** How the `runner` mode ended: the rule runner result without findings. */
88
+ export type ScanRunSummary = Omit<RuleRunResult, 'violations'>;
89
+ /** End of a scan run. */
90
+ export interface ScanEngineResult {
91
+ /** `true` when a cancel stopped the run. */
92
+ cancelled: boolean;
93
+ /** Ids of the rules that ran; empty when the run stopped before they were known. */
94
+ ruleIds: string[];
95
+ /** `runner` mode only. */
96
+ run?: ScanRunSummary;
97
+ }
98
+ /** Cancellation of an in-thread run; a worker is terminated instead. */
99
+ export interface ScanControl {
100
+ /** Yields once per file and stops when aborted. */
101
+ signal?: AbortSignal;
102
+ }
103
+ /**
104
+ * Runs the analysis part of a scan and reports each analyzed file to `sink`.
105
+ */
106
+ export declare function runScanEngine(spec: ScanSpec, sink: ScanSink, control?: ScanControl): Promise<ScanEngineResult>;
107
+ //# sourceMappingURL=scan-engine.d.ts.map
@@ -0,0 +1,197 @@
1
+ /**
2
+ * @angular-modernizer/adapter-mcp - Analysis part of the scan tools
3
+ *
4
+ * The part of a scan between "build the kernel" and "all files analyzed":
5
+ * kernel, project, rules, file loading and rule runs. It runs in a scan worker
6
+ * (`scan-host/`) or, as fallback and under Jest, in the calling thread; both
7
+ * paths run this function, so they produce the same findings in the same
8
+ * order. Glob, scan cache, result window, progress and the MCP protocol stay
9
+ * with the tool on the main thread.
10
+ *
11
+ * The engine does not write to disk (the kernel gets no cache config), so a
12
+ * worker killed in the middle leaves nothing half written.
13
+ */
14
+ import { existsSync } from 'node:fs';
15
+ import { Kernel, loadConfig } from '@angular-modernizer/core';
16
+ import { createPublicApi } from '@angular-modernizer/api';
17
+ import { ContextFactory, } from '@angular-modernizer/plugin-system';
18
+ import { loadSourceFiles } from './load-source-files.js';
19
+ import { runRulesOverFiles, } from './rule-runner.js';
20
+ import { templateDependencies } from './scan-cache.js';
21
+ import { yieldIfCancellable } from './tool-context.js';
22
+ /**
23
+ * Plugins of a scan, loaded on demand: a worker loads only the plugins its
24
+ * scan runs (plugin-angular brings `@angular/compiler`).
25
+ */
26
+ async function createPlugins(set) {
27
+ switch (set) {
28
+ case 'all': {
29
+ const [solid, angular, architecture] = await Promise.all([
30
+ import('@angular-modernizer/plugin-solid'),
31
+ import('@angular-modernizer/plugin-angular'),
32
+ import('@angular-modernizer/plugin-architecture'),
33
+ ]);
34
+ return [
35
+ new solid.SolidPlugin(),
36
+ new angular.AngularPlugin(),
37
+ new architecture.ArchitecturePlugin(),
38
+ ];
39
+ }
40
+ case 'solid':
41
+ return [new (await import('@angular-modernizer/plugin-solid')).SolidPlugin()];
42
+ case 'angular':
43
+ return [new (await import('@angular-modernizer/plugin-angular')).AngularPlugin()];
44
+ case 'architecture':
45
+ return [new (await import('@angular-modernizer/plugin-architecture')).ArchitecturePlugin()];
46
+ case 'analyzer':
47
+ return [new (await import('@angular-modernizer/plugin-analyzer')).AnalyzerPlugin()];
48
+ }
49
+ }
50
+ /**
51
+ * Runs the analysis part of a scan and reports each analyzed file to `sink`.
52
+ */
53
+ export async function runScanEngine(spec, sink, control = {}) {
54
+ // analyze-project analyzes against the whole tsconfig program; the other
55
+ // scans add their files themselves (keeps dist/, e2e/ and the like out).
56
+ const kernel = new Kernel({
57
+ tsConfigPath: spec.tsConfigPath,
58
+ plugins: await createPlugins(spec.plugins),
59
+ fileSystem: undefined,
60
+ projectOptions: { skipAddingFilesFromTsConfig: spec.mode !== 'sequential' },
61
+ });
62
+ await kernel.initialize();
63
+ // The kernel's plugin instances carry the ruleConfigs of .angular-modernizer.json
64
+ const allRules = kernel
65
+ .getAllPlugins()
66
+ .flatMap((p) => p.getAnalysisRules());
67
+ const rules = spec.ruleIds === undefined
68
+ ? allRules
69
+ : allRules.filter((rule) => spec.ruleIds.includes(rule.id));
70
+ if (rules.length === 0 && spec.mode === 'runner') {
71
+ throw new Error('No matching rules found');
72
+ }
73
+ const ruleIds = rules.map((r) => r.id);
74
+ sink.ready?.(ruleIds);
75
+ // Per-rule overrides of .angular-modernizer.json (BUG-3)
76
+ const config = (loadConfig(spec.rootPath).rules ?? {});
77
+ switch (spec.mode) {
78
+ case 'batches':
79
+ return runBatches(kernel, rules, config, spec, sink, control, ruleIds);
80
+ case 'runner':
81
+ return runRunner(kernel, rules, config, spec, sink, control, ruleIds);
82
+ case 'sequential':
83
+ return runSequential(kernel, rules, config, spec, sink, control, ruleIds);
84
+ }
85
+ }
86
+ async function runBatches(kernel, rules, config, spec, sink, control, ruleIds) {
87
+ const { signal } = control;
88
+ const batchSize = spec.batchSize ?? 100;
89
+ const totalBatches = Math.ceil(spec.files.length / batchSize);
90
+ const project = kernel.getProject();
91
+ for (let batchNum = 0; batchNum < totalBatches; batchNum++) {
92
+ const batchFiles = spec.files.slice(batchNum * batchSize, (batchNum + 1) * batchSize);
93
+ console.info(`\n${spec.tool} batch ${batchNum + 1}/${totalBatches}: ${batchFiles.length} files`);
94
+ // A new batch replaces the files of the previous one
95
+ for (const file of project.getSourceFiles()) {
96
+ project.removeSourceFile(file);
97
+ }
98
+ // Sorted order kept: findings must come out in the order a warm run
99
+ // reads them from the cache. A cancel during the load stops the scan.
100
+ const loaded = await loadSourceFiles(project, batchFiles, { signal });
101
+ if (loaded.cancelled) {
102
+ return { cancelled: true, ruleIds };
103
+ }
104
+ const api = createPublicApi(project);
105
+ const sourceFiles = spec.analyzeProjectFiles === true ? project.getSourceFiles() : loaded.sourceFiles;
106
+ for (const sourceFile of sourceFiles) {
107
+ await yieldIfCancellable(signal);
108
+ if (signal?.aborted === true) {
109
+ return { cancelled: true, ruleIds };
110
+ }
111
+ const findings = [];
112
+ for (const rule of rules) {
113
+ try {
114
+ const results = await rule.analyze(ContextFactory.createAnalysisContext({ sourceFile, project, api: api, config }));
115
+ for (const result of results) {
116
+ findings.push(toFinding(rule, result));
117
+ }
118
+ }
119
+ catch (error) {
120
+ console.warn(`Failed to analyze with rule ${rule.id}:`, error);
121
+ }
122
+ }
123
+ sink.file(fileEvent(sourceFile, findings, spec));
124
+ }
125
+ sink.batchDone?.(batchFiles.length);
126
+ }
127
+ return { cancelled: false, ruleIds };
128
+ }
129
+ async function runRunner(kernel, rules, config, spec, sink, control, ruleIds) {
130
+ const project = kernel.getProject();
131
+ const run = await runRulesOverFiles({
132
+ project,
133
+ files: spec.files,
134
+ rules,
135
+ api: createPublicApi(project),
136
+ config,
137
+ maxDurationMs: spec.maxDurationMs,
138
+ startTime: spec.startTime,
139
+ signal: control.signal,
140
+ collect: false,
141
+ onFileResults: (filePath, violations) => sink.file({ filePath, findings: violations }),
142
+ });
143
+ const { violations: _collected, ...summary } = run;
144
+ return { cancelled: run.stopReason === 'cancelled', ruleIds, run: summary };
145
+ }
146
+ async function runSequential(kernel, rules, config, spec, sink, control, ruleIds) {
147
+ const { signal } = control;
148
+ const project = kernel.getProject();
149
+ const api = createPublicApi(project);
150
+ for (const filePath of spec.files) {
151
+ await yieldIfCancellable(signal);
152
+ if (signal?.aborted === true) {
153
+ return { cancelled: true, ruleIds };
154
+ }
155
+ // A file that fails counts as analyzed with the findings it got so far
156
+ const findings = [];
157
+ try {
158
+ const sourceFile = project.addSourceFileAtPath(filePath);
159
+ for (const rule of rules) {
160
+ const results = await rule.analyze(ContextFactory.createAnalysisContext({ sourceFile, project, api: api, config }));
161
+ for (const result of results) {
162
+ findings.push(toFinding(rule, result));
163
+ }
164
+ }
165
+ }
166
+ catch (error) {
167
+ console.warn(`Error analyzing ${filePath}:`, error);
168
+ }
169
+ sink.file({ filePath, findings });
170
+ }
171
+ return { cancelled: false, ruleIds };
172
+ }
173
+ function toFinding(rule, result) {
174
+ return {
175
+ ruleId: result.ruleId,
176
+ severity: result.severity ?? rule.severity,
177
+ message: result.message,
178
+ filePath: result.filePath,
179
+ line: result.line,
180
+ column: result.column,
181
+ category: rule.category,
182
+ suggestedFix: result.suggestedFix,
183
+ metadata: result.metadata,
184
+ };
185
+ }
186
+ function fileEvent(sourceFile, findings, spec) {
187
+ const filePath = sourceFile.getFilePath();
188
+ if (spec.templateDependencies !== true) {
189
+ return { filePath, findings };
190
+ }
191
+ return {
192
+ filePath,
193
+ findings,
194
+ dependencies: templateDependencies(filePath, sourceFile.getFullText(), findings.map((f) => f.filePath), existsSync),
195
+ };
196
+ }
197
+ //# sourceMappingURL=scan-engine.js.map
@@ -1,15 +1,3 @@
1
- /**
2
- * @angular-modernizer/adapter-mcp - Suggestion Generator Helper
3
- *
4
- * Generates actionable rule improvement suggestions based on feedback analysis.
5
- *
6
- * Suggestion Logic:
7
- * - Parameter adjustment: ≥3 high-confidence failures → lower threshold
8
- * - Prerequisite check: ≥40% failures share common pattern → add validation
9
- * - Approach change: Alternative approach has >90% success rate → switch
10
- *
11
- * All suggestions require human approval before implementation.
12
- */
13
1
  import type { TransformationFeedback } from '@angular-modernizer/core';
14
2
  /**
15
3
  * Performance metrics for a transformation rule
@@ -23,7 +11,15 @@ export interface Performance {
23
11
  qualityImprovement: number;
24
12
  }
25
13
  /**
26
- * Actionable suggestion for rule improvement
14
+ * Rule improvement suggestion generated from feedback analysis.
15
+ *
16
+ * @remarks
17
+ * Suggestion logic:
18
+ * - Parameter adjustment: ≥3 high-confidence failures → lower threshold
19
+ * - Prerequisite check: ≥40% failures share common pattern → add validation
20
+ * - Approach change: Alternative approach has >90% success rate → switch
21
+ *
22
+ * All suggestions require human approval before implementation.
27
23
  */
28
24
  export interface Suggestion {
29
25
  /** Type of suggestion */
@@ -1,15 +1,3 @@
1
- /**
2
- * @angular-modernizer/adapter-mcp - Suggestion Generator Helper
3
- *
4
- * Generates actionable rule improvement suggestions based on feedback analysis.
5
- *
6
- * Suggestion Logic:
7
- * - Parameter adjustment: ≥3 high-confidence failures → lower threshold
8
- * - Prerequisite check: ≥40% failures share common pattern → add validation
9
- * - Approach change: Alternative approach has >90% success rate → switch
10
- *
11
- * All suggestions require human approval before implementation.
12
- */
13
1
  /**
14
2
  * Calculate current performance metrics for a rule
15
3
  *
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @angular-modernizer/adapter-mcp - Scan cache of the single-plugin scans
3
+ *
4
+ * scan-solid, scan-angular and scan-architecture read and write their cache
5
+ * on the main thread; the kernel that used to own it runs in the scan worker
6
+ * now and gets no cache config there.
7
+ */
8
+ import { CacheManager } from '@angular-modernizer/core';
9
+ /** Opens `.angular-modernizer-cache/<tool>/` of `rootPath`. */
10
+ export declare function openToolCache(rootPath: string, tool: 'solid' | 'angular' | 'architecture'): Promise<CacheManager>;
11
+ //# sourceMappingURL=tool-cache.d.ts.map
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @angular-modernizer/adapter-mcp - Scan cache of the single-plugin scans
3
+ *
4
+ * scan-solid, scan-angular and scan-architecture read and write their cache
5
+ * on the main thread; the kernel that used to own it runs in the scan worker
6
+ * now and gets no cache config there.
7
+ */
8
+ import { CacheManager, RealFileSystemAdapter, createToolCacheConfig, } from '@angular-modernizer/core';
9
+ /** Opens `.angular-modernizer-cache/<tool>/` of `rootPath`. */
10
+ export async function openToolCache(rootPath, tool) {
11
+ const cache = new CacheManager(new RealFileSystemAdapter(), createToolCacheConfig(rootPath, tool));
12
+ await cache.initialize();
13
+ return cache;
14
+ }
15
+ //# sourceMappingURL=tool-cache.js.map
@@ -1,11 +1,3 @@
1
- /**
2
- * @angular-modernizer/adapter-mcp - Helpers for the per-call tool context
3
- *
4
- * Analysis is synchronous CPU work: while a loop runs, the server does not
5
- * read stdin, so `notifications/cancelled` only arrives once the loop gives
6
- * the event loop a turn. Long loops therefore yield once per file when the
7
- * call can be cancelled ({@link yieldIfCancellable}).
8
- */
9
1
  import { type ProgressFn } from '../../types.js';
10
2
  /** Minimum gap between two progress notifications. */
11
3
  export declare const PROGRESS_INTERVAL_MS = 250;
@@ -18,6 +10,11 @@ export declare function throttleProgress(send: ProgressFn, intervalMs?: number,
18
10
  * Gives the event loop one turn when the call can be cancelled, so a pending
19
11
  * `notifications/cancelled` is read and `signal` aborts. Without a signal
20
12
  * (direct calls, tests) it returns at once.
13
+ *
14
+ * @remarks
15
+ * Analysis is synchronous CPU work: while a loop runs, the server does not
16
+ * read stdin, so `notifications/cancelled` only arrives once the loop gives
17
+ * the event loop a turn. Long loops therefore call this once per file.
21
18
  */
22
19
  export declare function yieldIfCancellable(signal: AbortSignal | undefined): Promise<void>;
23
20
  /** Progress message of a file loop: `12/40 files, 3 violations`. */
@@ -29,11 +26,17 @@ export declare function fileProgressMessage(analyzed: number, total: number, vio
29
26
  export declare function fileProgress(progress: ProgressFn | undefined): ((analyzed: number, total: number, violations: number) => void) | undefined;
30
27
  /** Execution details of a scan the client cancelled. */
31
28
  export interface CancelledExecution {
29
+ /** Time budget of the scan in milliseconds, when the tool has one. */
32
30
  maxDurationMs?: number;
31
+ /** Always `true`: the scan stopped early. */
33
32
  incomplete: true;
33
+ /** Why the scan stopped. */
34
34
  stopReason: 'cancelled';
35
+ /** Files that were not analyzed. */
35
36
  skippedFiles: number;
37
+ /** Always empty for a cancelled scan. */
36
38
  ruleTimings: [];
39
+ /** Human-readable note: files analyzed and skipped. */
37
40
  note: string;
38
41
  }
39
42
  /**
@@ -1,11 +1,3 @@
1
- /**
2
- * @angular-modernizer/adapter-mcp - Helpers for the per-call tool context
3
- *
4
- * Analysis is synchronous CPU work: while a loop runs, the server does not
5
- * read stdin, so `notifications/cancelled` only arrives once the loop gives
6
- * the event loop a turn. Long loops therefore yield once per file when the
7
- * call can be cancelled ({@link yieldIfCancellable}).
8
- */
9
1
  /** Minimum gap between two progress notifications. */
10
2
  export const PROGRESS_INTERVAL_MS = 250;
11
3
  /**
@@ -28,6 +20,11 @@ export function throttleProgress(send, intervalMs = PROGRESS_INTERVAL_MS, now =
28
20
  * Gives the event loop one turn when the call can be cancelled, so a pending
29
21
  * `notifications/cancelled` is read and `signal` aborts. Without a signal
30
22
  * (direct calls, tests) it returns at once.
23
+ *
24
+ * @remarks
25
+ * Analysis is synchronous CPU work: while a loop runs, the server does not
26
+ * read stdin, so `notifications/cancelled` only arrives once the loop gives
27
+ * the event loop a turn. Long loops therefore call this once per file.
31
28
  */
32
29
  export async function yieldIfCancellable(signal) {
33
30
  if (signal === undefined) {