@angular-modernizer/adapter-mcp 0.2.0 → 1.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.
- package/README.md +188 -235
- package/dist/cli.js +77 -27
- package/dist/index.d.ts +11 -3
- package/dist/index.js +10 -2
- package/dist/mcp-watcher.d.ts +6 -1
- package/dist/mcp-watcher.js +14 -10
- package/dist/server/limited-stdio-transport.d.ts +68 -0
- package/dist/server/limited-stdio-transport.js +115 -0
- package/dist/server/mcp-server.d.ts +41 -12
- package/dist/server/mcp-server.js +113 -94
- package/dist/server/package-version.d.ts +16 -0
- package/dist/server/package-version.js +37 -0
- package/dist/server/sdk-server.d.ts +70 -0
- package/dist/server/sdk-server.js +113 -0
- package/dist/server/stdio-guard.d.ts +20 -0
- package/dist/server/stdio-guard.js +48 -0
- package/dist/server/tool-registry.d.ts +3 -2
- package/dist/server/tool-registry.js +5 -5
- package/dist/tools/analyze-build-impact.d.ts +346 -14
- package/dist/tools/analyze-build-impact.js +315 -31
- package/dist/tools/analyze-core-to-shared.d.ts +134 -4
- package/dist/tools/analyze-core-to-shared.js +113 -9
- package/dist/tools/analyze-parser-performance.d.ts +200 -7
- package/dist/tools/analyze-parser-performance.js +108 -47
- package/dist/tools/analyze-project.d.ts +267 -5
- package/dist/tools/analyze-project.js +196 -8
- package/dist/tools/check-incremental-compatibility.d.ts +61 -1
- package/dist/tools/check-incremental-compatibility.js +58 -2
- package/dist/tools/collect-feedback.d.ts +199 -10
- package/dist/tools/collect-feedback.js +171 -99
- package/dist/tools/compare-health.d.ts +356 -0
- package/dist/tools/compare-health.js +472 -0
- package/dist/tools/extract-libraries.d.ts +156 -4
- package/dist/tools/extract-libraries.js +115 -10
- package/dist/tools/find-angular-symbol.d.ts +98 -9
- package/dist/tools/find-angular-symbol.js +104 -12
- package/dist/tools/find-component-hosts.d.ts +684 -0
- package/dist/tools/find-component-hosts.js +441 -0
- package/dist/tools/find-usages.d.ts +99 -4
- package/dist/tools/find-usages.js +131 -11
- package/dist/tools/get-bootstrap-execution.d.ts +258 -0
- package/dist/tools/get-bootstrap-execution.js +324 -0
- package/dist/tools/get-call-graph.d.ts +139 -4
- package/dist/tools/get-call-graph.js +123 -13
- package/dist/tools/get-operation-progress-tool.d.ts +114 -2
- package/dist/tools/get-operation-progress-tool.js +114 -7
- package/dist/tools/get-operation-progress.d.ts +1 -1
- package/dist/tools/get-operation-progress.js +5 -5
- package/dist/tools/helpers/analysis-output.d.ts +177 -0
- package/dist/tools/helpers/analysis-output.js +165 -0
- package/dist/tools/helpers/build-schemas.d.ts +36 -0
- package/dist/tools/helpers/build-schemas.js +23 -0
- package/dist/tools/helpers/citation-file-source.d.ts +10 -0
- package/dist/tools/helpers/citation-file-source.js +82 -0
- package/dist/tools/helpers/compact-output.d.ts +61 -0
- package/dist/tools/helpers/compact-output.js +83 -0
- package/dist/tools/helpers/finding-window.d.ts +43 -0
- package/dist/tools/helpers/finding-window.js +64 -0
- package/dist/tools/helpers/health-delta.d.ts +86 -0
- package/dist/tools/helpers/health-delta.js +239 -0
- package/dist/tools/helpers/investigation-schemas.d.ts +93 -0
- package/dist/tools/helpers/investigation-schemas.js +48 -0
- package/dist/tools/helpers/library-imports.d.ts +57 -0
- package/dist/tools/helpers/library-imports.js +151 -0
- package/dist/tools/helpers/load-source-files.d.ts +30 -0
- package/dist/tools/helpers/load-source-files.js +34 -0
- package/dist/tools/helpers/output-contract.d.ts +32 -0
- package/dist/tools/helpers/output-contract.js +32 -0
- package/dist/tools/helpers/platform-root-resolver.d.ts +55 -25
- package/dist/tools/helpers/platform-root-resolver.js +75 -48
- package/dist/tools/helpers/process-output.d.ts +19 -0
- package/dist/tools/helpers/process-output.js +31 -0
- package/dist/tools/helpers/project-cache.d.ts +184 -0
- package/dist/tools/helpers/project-cache.js +331 -0
- package/dist/tools/helpers/project-decorators.d.ts +14 -0
- package/dist/tools/helpers/project-decorators.js +22 -0
- package/dist/tools/helpers/rule-matcher.js +5 -0
- package/dist/tools/helpers/rule-runner.d.ts +72 -0
- package/dist/tools/helpers/rule-runner.js +131 -0
- package/dist/tools/helpers/scan-cache.d.ts +22 -0
- package/dist/tools/helpers/scan-cache.js +34 -0
- package/dist/tools/helpers/scan-plan.d.ts +48 -0
- package/dist/tools/helpers/scan-plan.js +166 -0
- package/dist/tools/helpers/scope-paths.d.ts +17 -0
- package/dist/tools/helpers/scope-paths.js +32 -0
- package/dist/tools/helpers/stack-frame-file-index.d.ts +10 -0
- package/dist/tools/helpers/stack-frame-file-index.js +71 -0
- package/dist/tools/helpers/tool-context.d.ts +60 -0
- package/dist/tools/helpers/tool-context.js +82 -0
- package/dist/tools/helpers/transform-safety.d.ts +40 -0
- package/dist/tools/helpers/transform-safety.js +87 -0
- package/dist/tools/helpers/validation-output.d.ts +53 -0
- package/dist/tools/helpers/validation-output.js +48 -0
- package/dist/tools/inspect-form-group.d.ts +324 -0
- package/dist/tools/inspect-form-group.js +279 -0
- package/dist/tools/inspect-i18n.d.ts +466 -0
- package/dist/tools/inspect-i18n.js +400 -0
- package/dist/tools/inspect-template.d.ts +320 -0
- package/dist/tools/inspect-template.js +324 -0
- package/dist/tools/learn-patterns.d.ts +122 -1
- package/dist/tools/learn-patterns.js +97 -2
- package/dist/tools/list-imports.d.ts +128 -11
- package/dist/tools/list-imports.js +128 -8
- package/dist/tools/orchestrate-migration.d.ts +129 -5
- package/dist/tools/orchestrate-migration.js +166 -12
- package/dist/tools/parse-stack-trace.d.ts +59 -2
- package/dist/tools/parse-stack-trace.js +52 -4
- package/dist/tools/plan-migration.d.ts +418 -1
- package/dist/tools/plan-migration.js +355 -8
- package/dist/tools/resolve-type.d.ts +42 -1
- package/dist/tools/resolve-type.js +37 -4
- package/dist/tools/review-feedback.d.ts +206 -11
- package/dist/tools/review-feedback.js +132 -51
- package/dist/tools/rollback-changes.d.ts +79 -2
- package/dist/tools/rollback-changes.js +66 -14
- package/dist/tools/run-angular-cli.d.ts +45 -2
- package/dist/tools/run-angular-cli.js +67 -7
- package/dist/tools/run-build.d.ts +114 -2
- package/dist/tools/run-build.js +117 -8
- package/dist/tools/run-schematic.d.ts +70 -2
- package/dist/tools/run-schematic.js +104 -10
- package/dist/tools/scan-all.d.ts +24 -16
- package/dist/tools/scan-all.js +145 -137
- package/dist/tools/scan-angular.d.ts +20 -11
- package/dist/tools/scan-angular.js +52 -24
- package/dist/tools/scan-architecture.d.ts +42 -14
- package/dist/tools/scan-architecture.js +206 -163
- package/dist/tools/scan-solid.d.ts +20 -11
- package/dist/tools/scan-solid.js +52 -24
- package/dist/tools/search-codebase.d.ts +85 -1
- package/dist/tools/search-codebase.js +61 -4
- package/dist/tools/server-status.d.ts +370 -0
- package/dist/tools/server-status.js +369 -0
- package/dist/tools/suggest-improvements.d.ts +97 -5
- package/dist/tools/suggest-improvements.js +80 -44
- package/dist/tools/trace-output-flow.d.ts +791 -0
- package/dist/tools/trace-output-flow.js +668 -0
- package/dist/tools/transform-code-batch.d.ts +3 -0
- package/dist/tools/transform-code-batch.js +10 -5
- package/dist/tools/transform-code.d.ts +335 -12
- package/dist/tools/transform-code.js +649 -608
- package/dist/tools/validate-before-transform.d.ts +116 -2
- package/dist/tools/validate-before-transform.js +55 -2
- package/dist/tools/validate-project-compatibility.d.ts +64 -2
- package/dist/tools/validate-project-compatibility.js +67 -4
- package/dist/tools/validate-transformation.d.ts +220 -2
- package/dist/tools/validate-transformation.js +113 -15
- package/dist/tools/verify-citations.d.ts +181 -0
- package/dist/tools/verify-citations.js +218 -0
- package/dist/types.d.ts +45 -1
- package/dist/utils/format-tool-response.d.ts +22 -59
- package/dist/utils/format-tool-response.js +25 -134
- package/package.json +30 -13
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/core/project-analyzer.d.ts.map +0 -1
- package/dist/core/project-analyzer.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/mcp-watcher.d.ts.map +0 -1
- package/dist/mcp-watcher.js.map +0 -1
- package/dist/server/json-rpc-handler.d.ts +0 -57
- package/dist/server/json-rpc-handler.d.ts.map +0 -1
- package/dist/server/json-rpc-handler.js +0 -222
- package/dist/server/json-rpc-handler.js.map +0 -1
- package/dist/server/mcp-server.d.ts.map +0 -1
- package/dist/server/mcp-server.js.map +0 -1
- package/dist/server/tool-registry.d.ts.map +0 -1
- package/dist/server/tool-registry.js.map +0 -1
- package/dist/streaming/progress-store.d.ts.map +0 -1
- package/dist/streaming/progress-store.js.map +0 -1
- package/dist/tools/analyze-build-impact.d.ts.map +0 -1
- package/dist/tools/analyze-build-impact.js.map +0 -1
- package/dist/tools/analyze-core-to-shared.d.ts.map +0 -1
- package/dist/tools/analyze-core-to-shared.js.map +0 -1
- package/dist/tools/analyze-parser-performance.d.ts.map +0 -1
- package/dist/tools/analyze-parser-performance.js.map +0 -1
- package/dist/tools/analyze-project.d.ts.map +0 -1
- package/dist/tools/analyze-project.js.map +0 -1
- package/dist/tools/check-incremental-compatibility.d.ts.map +0 -1
- package/dist/tools/check-incremental-compatibility.js.map +0 -1
- package/dist/tools/collect-feedback.d.ts.map +0 -1
- package/dist/tools/collect-feedback.js.map +0 -1
- package/dist/tools/extract-libraries.d.ts.map +0 -1
- package/dist/tools/extract-libraries.js.map +0 -1
- package/dist/tools/find-angular-symbol.d.ts.map +0 -1
- package/dist/tools/find-angular-symbol.js.map +0 -1
- package/dist/tools/find-usages.d.ts.map +0 -1
- package/dist/tools/find-usages.js.map +0 -1
- package/dist/tools/get-call-graph.d.ts.map +0 -1
- package/dist/tools/get-call-graph.js.map +0 -1
- package/dist/tools/get-operation-progress-tool.d.ts.map +0 -1
- package/dist/tools/get-operation-progress-tool.js.map +0 -1
- package/dist/tools/get-operation-progress.d.ts.map +0 -1
- package/dist/tools/get-operation-progress.js.map +0 -1
- package/dist/tools/helpers/feedback-analyzer.d.ts.map +0 -1
- package/dist/tools/helpers/feedback-analyzer.js.map +0 -1
- package/dist/tools/helpers/find-ts-config.d.ts.map +0 -1
- package/dist/tools/helpers/find-ts-config.js.map +0 -1
- package/dist/tools/helpers/platform-root-resolver.d.ts.map +0 -1
- package/dist/tools/helpers/platform-root-resolver.js.map +0 -1
- package/dist/tools/helpers/rule-matcher.d.ts.map +0 -1
- package/dist/tools/helpers/rule-matcher.js.map +0 -1
- package/dist/tools/helpers/suggestion-generator.d.ts.map +0 -1
- package/dist/tools/helpers/suggestion-generator.js.map +0 -1
- package/dist/tools/learn-patterns.d.ts.map +0 -1
- package/dist/tools/learn-patterns.js.map +0 -1
- package/dist/tools/list-imports.d.ts.map +0 -1
- package/dist/tools/list-imports.js.map +0 -1
- package/dist/tools/orchestrate-migration.d.ts.map +0 -1
- package/dist/tools/orchestrate-migration.js.map +0 -1
- package/dist/tools/parse-stack-trace.d.ts.map +0 -1
- package/dist/tools/parse-stack-trace.js.map +0 -1
- package/dist/tools/plan-migration.d.ts.map +0 -1
- package/dist/tools/plan-migration.js.map +0 -1
- package/dist/tools/resolve-type.d.ts.map +0 -1
- package/dist/tools/resolve-type.js.map +0 -1
- package/dist/tools/review-feedback.d.ts.map +0 -1
- package/dist/tools/review-feedback.js.map +0 -1
- package/dist/tools/rollback-changes.d.ts.map +0 -1
- package/dist/tools/rollback-changes.js.map +0 -1
- package/dist/tools/run-angular-cli.d.ts.map +0 -1
- package/dist/tools/run-angular-cli.js.map +0 -1
- package/dist/tools/run-build.d.ts.map +0 -1
- package/dist/tools/run-build.js.map +0 -1
- package/dist/tools/run-schematic.d.ts.map +0 -1
- package/dist/tools/run-schematic.js.map +0 -1
- package/dist/tools/scan-all.d.ts.map +0 -1
- package/dist/tools/scan-all.js.map +0 -1
- package/dist/tools/scan-angular.d.ts.map +0 -1
- package/dist/tools/scan-angular.js.map +0 -1
- package/dist/tools/scan-architecture.d.ts.map +0 -1
- package/dist/tools/scan-architecture.js.map +0 -1
- package/dist/tools/scan-solid.d.ts.map +0 -1
- package/dist/tools/scan-solid.js.map +0 -1
- package/dist/tools/search-codebase.d.ts.map +0 -1
- package/dist/tools/search-codebase.js.map +0 -1
- package/dist/tools/shared/scan-types.d.ts.map +0 -1
- package/dist/tools/shared/scan-types.js.map +0 -1
- package/dist/tools/suggest-improvements.d.ts.map +0 -1
- package/dist/tools/suggest-improvements.js.map +0 -1
- package/dist/tools/transform-code-batch.d.ts.map +0 -1
- package/dist/tools/transform-code-batch.js.map +0 -1
- package/dist/tools/transform-code.d.ts.map +0 -1
- package/dist/tools/transform-code.js.map +0 -1
- package/dist/tools/validate-before-transform.d.ts.map +0 -1
- package/dist/tools/validate-before-transform.js.map +0 -1
- package/dist/tools/validate-project-compatibility.d.ts.map +0 -1
- package/dist/tools/validate-project-compatibility.js.map +0 -1
- package/dist/tools/validate-transformation.d.ts.map +0 -1
- package/dist/tools/validate-transformation.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/utils/format-tool-response.d.ts.map +0 -1
- package/dist/utils/format-tool-response.js.map +0 -1
|
@@ -8,15 +8,119 @@
|
|
|
8
8
|
*
|
|
9
9
|
* Enhancement: Style-aware migration planning that respects
|
|
10
10
|
* existing codebase conventions (RxJS patterns, DI style, etc.)
|
|
11
|
+
*
|
|
12
|
+
* Scan-based planning: when violations carry `filePath` (inline or from a
|
|
13
|
+
* saved scan-architecture result via `scanResultFile`) and `projectRoot` is
|
|
14
|
+
* set, the roadmap is built from the files themselves: grouped per file and
|
|
15
|
+
* layer, ordered dependencies first along the import graph, import cycles
|
|
16
|
+
* kept together (core `buildViolationPlan`). Otherwise the strategy templates
|
|
17
|
+
* decide the roadmap as before.
|
|
18
|
+
*/
|
|
19
|
+
import { isAbsolute, resolve } from 'node:path';
|
|
20
|
+
import { nameList } from './helpers/analysis-output.js';
|
|
21
|
+
import { STRING_ARRAY } from './helpers/investigation-schemas.js';
|
|
22
|
+
import { WARNINGS_OUTPUT_SCHEMA, withWarnings } from './helpers/output-contract.js';
|
|
23
|
+
import { COMPACT_OUTPUT_SCHEMA, limitList, parseCompactOptions, } from './helpers/compact-output.js';
|
|
24
|
+
import { buildScanPlan, readScanResultFile, } from './helpers/scan-plan.js';
|
|
25
|
+
/**
|
|
26
|
+
* Default list cap for the scan-based plan: the full plan for a large project
|
|
27
|
+
* (e.g. 21k violations in 534 files) exceeds the 4 MB response limit.
|
|
28
|
+
*/
|
|
29
|
+
const SCAN_PLAN_DEFAULT_MAX_RESULTS = 25;
|
|
30
|
+
const SCAN_SEVERITY_TO_PLAN = {
|
|
31
|
+
error: 'high',
|
|
32
|
+
warning: 'medium',
|
|
33
|
+
info: 'low',
|
|
34
|
+
low: 'low',
|
|
35
|
+
medium: 'medium',
|
|
36
|
+
high: 'high',
|
|
37
|
+
critical: 'critical',
|
|
38
|
+
};
|
|
39
|
+
const MIGRATION_STEP_SCHEMA = {
|
|
40
|
+
type: 'object',
|
|
41
|
+
properties: {
|
|
42
|
+
name: { type: 'string' },
|
|
43
|
+
action: { type: 'string' },
|
|
44
|
+
validation: { type: 'string' },
|
|
45
|
+
effort: { type: 'number' },
|
|
46
|
+
risk: { type: 'string' },
|
|
47
|
+
},
|
|
48
|
+
required: ['name', 'action', 'validation', 'effort', 'risk'],
|
|
49
|
+
};
|
|
50
|
+
const MIGRATION_STRATEGY_SCHEMA = {
|
|
51
|
+
type: 'object',
|
|
52
|
+
properties: {
|
|
53
|
+
id: { type: 'string' },
|
|
54
|
+
name: { type: 'string' },
|
|
55
|
+
description: { type: 'string' },
|
|
56
|
+
applicableArchitectures: STRING_ARRAY,
|
|
57
|
+
complexity: { type: 'string' },
|
|
58
|
+
successRate: { type: 'number' },
|
|
59
|
+
steps: { type: 'array', items: MIGRATION_STEP_SCHEMA },
|
|
60
|
+
prerequisites: STRING_ARRAY,
|
|
61
|
+
risks: STRING_ARRAY,
|
|
62
|
+
totalEffort: { type: 'number' },
|
|
63
|
+
overallRisk: { type: 'string' },
|
|
64
|
+
},
|
|
65
|
+
required: ['id', 'name', 'complexity', 'successRate', 'steps', 'totalEffort', 'overallRisk'],
|
|
66
|
+
};
|
|
67
|
+
/** Alternatives and phases named in the summary. */
|
|
68
|
+
const SUMMARY_NAMES = 10;
|
|
69
|
+
/**
|
|
70
|
+
* Text summary of a plan: strategy, alternatives, roadmap, the scan-based
|
|
71
|
+
* plan's own summary and the notes.
|
|
11
72
|
*/
|
|
73
|
+
function describePlan(plan) {
|
|
74
|
+
const strategy = plan.recommendedStrategy;
|
|
75
|
+
const lines = [
|
|
76
|
+
`Recommended strategy: ${strategy.name} (${strategy.id}; complexity ${strategy.complexity}, ` +
|
|
77
|
+
`risk ${strategy.overallRisk}, effort ${strategy.totalEffort}, ` +
|
|
78
|
+
`success rate ${Math.round(strategy.successRate * 100)}%).`,
|
|
79
|
+
];
|
|
80
|
+
const alternatives = nameList(plan.alternativeStrategies.map((s) => s.id), SUMMARY_NAMES);
|
|
81
|
+
if (alternatives !== undefined) {
|
|
82
|
+
lines.push(`Alternatives: ${alternatives}.`);
|
|
83
|
+
}
|
|
84
|
+
const phases = nameList(plan.roadmap.phases.map((p) => p.name), SUMMARY_NAMES);
|
|
85
|
+
lines.push(`Roadmap (${plan.planSource}, ${plan.roadmap.totalDuration})` +
|
|
86
|
+
(phases === undefined ? '.' : `: ${phases}.`));
|
|
87
|
+
if (plan.scanPlan !== undefined) {
|
|
88
|
+
lines.push(plan.scanPlan.summary);
|
|
89
|
+
}
|
|
90
|
+
if (plan.styleAlignmentScore !== undefined) {
|
|
91
|
+
lines.push(`Style alignment: ${plan.styleAlignmentScore}.`);
|
|
92
|
+
}
|
|
93
|
+
lines.push(...(plan.notes ?? []));
|
|
94
|
+
return lines.join('\n');
|
|
95
|
+
}
|
|
12
96
|
/**
|
|
13
97
|
* MCP tool for planning migrations.
|
|
14
98
|
*/
|
|
15
99
|
export class PlanMigrationTool {
|
|
100
|
+
projects;
|
|
101
|
+
/**
|
|
102
|
+
* @param projects - Shared project cache for the scan-based plan; without
|
|
103
|
+
* it every call parses the workspace anew.
|
|
104
|
+
*/
|
|
105
|
+
constructor(projects) {
|
|
106
|
+
this.projects = projects;
|
|
107
|
+
}
|
|
16
108
|
name = 'plan-migration';
|
|
17
|
-
|
|
109
|
+
title = 'Plan Migration';
|
|
110
|
+
annotations = {
|
|
111
|
+
readOnlyHint: true,
|
|
112
|
+
destructiveHint: false,
|
|
113
|
+
idempotentHint: true,
|
|
114
|
+
openWorldHint: false,
|
|
115
|
+
};
|
|
116
|
+
description = 'Generate comprehensive, style-aware migration plans for architectural improvements. ' +
|
|
117
|
+
'With projectRoot and file-level violations (filePath, e.g. from scan-architecture, inline or via ' +
|
|
118
|
+
'scanResultFile) the roadmap names concrete files: grouped per file and layer, ordered dependencies ' +
|
|
119
|
+
'first along the import graph, import cycles kept together (planSource "scan"). Without file paths ' +
|
|
120
|
+
'the strategy templates decide the roadmap (planSource "template"). summary is a short text of strategy and roadmap.';
|
|
18
121
|
inputSchema = {
|
|
19
122
|
type: 'object',
|
|
123
|
+
additionalProperties: false,
|
|
20
124
|
properties: {
|
|
21
125
|
violations: {
|
|
22
126
|
type: 'array',
|
|
@@ -27,13 +131,39 @@ export class PlanMigrationTool {
|
|
|
27
131
|
ruleId: { type: 'string' },
|
|
28
132
|
severity: {
|
|
29
133
|
type: 'string',
|
|
30
|
-
enum: ['low', 'medium', 'high', 'critical'],
|
|
134
|
+
enum: ['low', 'medium', 'high', 'critical', 'error', 'warning', 'info'],
|
|
31
135
|
},
|
|
32
136
|
category: { type: 'string' },
|
|
137
|
+
filePath: {
|
|
138
|
+
type: 'string',
|
|
139
|
+
description: 'File of the violation (absolute or relative to projectRoot). Enables the scan-based plan.',
|
|
140
|
+
},
|
|
141
|
+
line: { type: 'number' },
|
|
142
|
+
message: { type: 'string' },
|
|
33
143
|
},
|
|
34
144
|
required: ['ruleId', 'severity', 'category'],
|
|
35
145
|
},
|
|
36
146
|
},
|
|
147
|
+
projectRoot: {
|
|
148
|
+
type: 'string',
|
|
149
|
+
description: 'Project root with a tsconfig. Required for the scan-based plan (import graph and layers from ' +
|
|
150
|
+
'layers / layersSource).',
|
|
151
|
+
},
|
|
152
|
+
scanResultFile: {
|
|
153
|
+
type: 'string',
|
|
154
|
+
description: 'Saved scan-architecture result ({ violations: [...] }, a violation array, or the MCP text content) ' +
|
|
155
|
+
'to read violations from. Absolute or relative to projectRoot. Replaces or extends violations.',
|
|
156
|
+
},
|
|
157
|
+
maxResults: {
|
|
158
|
+
type: 'number',
|
|
159
|
+
description: 'Scan-based plan: at most this many files per phase and violations per file (phases and files are ' +
|
|
160
|
+
'marked truncated; counts cover everything). Default 25. Ignored by the template plan.',
|
|
161
|
+
},
|
|
162
|
+
maxPhases: {
|
|
163
|
+
type: 'number',
|
|
164
|
+
description: 'Upper bound for scan-based phases; consecutive dependency levels are merged beyond it. Default 6.',
|
|
165
|
+
},
|
|
166
|
+
summaryOnly: COMPACT_OUTPUT_SCHEMA.summaryOnly,
|
|
37
167
|
architecture: {
|
|
38
168
|
type: 'object',
|
|
39
169
|
description: 'Current architecture analysis',
|
|
@@ -146,12 +276,94 @@ export class PlanMigrationTool {
|
|
|
146
276
|
default: true,
|
|
147
277
|
},
|
|
148
278
|
},
|
|
149
|
-
|
|
279
|
+
// violations and architecture are required unless the plan is scan-based
|
|
280
|
+
// (scanResultFile or violations with filePath); checked in execute()
|
|
281
|
+
required: [],
|
|
282
|
+
};
|
|
283
|
+
outputSchema = {
|
|
284
|
+
type: 'object',
|
|
285
|
+
properties: {
|
|
286
|
+
recommendedStrategy: MIGRATION_STRATEGY_SCHEMA,
|
|
287
|
+
alternativeStrategies: { type: 'array', items: MIGRATION_STRATEGY_SCHEMA },
|
|
288
|
+
reasoning: {
|
|
289
|
+
type: 'object',
|
|
290
|
+
properties: {
|
|
291
|
+
primaryFactors: STRING_ARRAY,
|
|
292
|
+
constraintImpact: STRING_ARRAY,
|
|
293
|
+
riskAssessment: { type: 'string' },
|
|
294
|
+
},
|
|
295
|
+
required: ['primaryFactors', 'constraintImpact', 'riskAssessment'],
|
|
296
|
+
},
|
|
297
|
+
roadmap: {
|
|
298
|
+
type: 'object',
|
|
299
|
+
properties: {
|
|
300
|
+
phases: {
|
|
301
|
+
type: 'array',
|
|
302
|
+
items: {
|
|
303
|
+
type: 'object',
|
|
304
|
+
properties: {
|
|
305
|
+
name: { type: 'string' },
|
|
306
|
+
duration: { type: 'string' },
|
|
307
|
+
steps: { type: 'array', items: MIGRATION_STEP_SCHEMA },
|
|
308
|
+
deliverables: STRING_ARRAY,
|
|
309
|
+
},
|
|
310
|
+
required: ['name', 'duration', 'steps', 'deliverables'],
|
|
311
|
+
},
|
|
312
|
+
},
|
|
313
|
+
totalDuration: { type: 'string' },
|
|
314
|
+
milestones: STRING_ARRAY,
|
|
315
|
+
},
|
|
316
|
+
required: ['phases', 'totalDuration', 'milestones'],
|
|
317
|
+
},
|
|
318
|
+
successMetrics: STRING_ARRAY,
|
|
319
|
+
planSource: { type: 'string', enum: ['scan', 'template'] },
|
|
320
|
+
scanPlan: {
|
|
321
|
+
type: 'object',
|
|
322
|
+
properties: {
|
|
323
|
+
summary: { type: 'string' },
|
|
324
|
+
maxResults: { type: 'integer' },
|
|
325
|
+
layerSource: { type: 'string' },
|
|
326
|
+
graphFiles: { type: 'integer' },
|
|
327
|
+
stats: { type: 'object' },
|
|
328
|
+
cycles: { type: 'array', items: { type: 'object' } },
|
|
329
|
+
phases: { type: 'array', items: { type: 'object' } },
|
|
330
|
+
warnings: STRING_ARRAY,
|
|
331
|
+
},
|
|
332
|
+
required: ['summary', 'layerSource', 'graphFiles', 'stats', 'cycles', 'phases', 'warnings'],
|
|
333
|
+
},
|
|
334
|
+
notes: STRING_ARRAY,
|
|
335
|
+
styleAwareRiskAssessment: { type: 'object' },
|
|
336
|
+
styleConflictingSteps: { type: 'array', items: { type: 'object' } },
|
|
337
|
+
styleRecommendations: { type: 'array', items: { type: 'object' } },
|
|
338
|
+
styleAlignmentScore: { type: 'number' },
|
|
339
|
+
stepsWithStyleAnalysis: { type: 'array', items: { type: 'object' } },
|
|
340
|
+
summary: { type: 'string' },
|
|
341
|
+
...WARNINGS_OUTPUT_SCHEMA,
|
|
342
|
+
},
|
|
343
|
+
required: [
|
|
344
|
+
'recommendedStrategy',
|
|
345
|
+
'alternativeStrategies',
|
|
346
|
+
'reasoning',
|
|
347
|
+
'roadmap',
|
|
348
|
+
'successMetrics',
|
|
349
|
+
'planSource',
|
|
350
|
+
'summary',
|
|
351
|
+
],
|
|
150
352
|
};
|
|
151
353
|
async execute(args) {
|
|
152
354
|
const params = args;
|
|
153
|
-
const
|
|
154
|
-
const
|
|
355
|
+
const compact = parseCompactOptions(args);
|
|
356
|
+
const projectRoot = typeof params.projectRoot === 'string' ? params.projectRoot : undefined;
|
|
357
|
+
const scanInput = this.collectScanViolations(params, projectRoot);
|
|
358
|
+
const isScanBased = scanInput.some((v) => typeof v.filePath === 'string');
|
|
359
|
+
const violations = isScanBased
|
|
360
|
+
? scanInput.map((v) => ({
|
|
361
|
+
ruleId: v.ruleId,
|
|
362
|
+
severity: SCAN_SEVERITY_TO_PLAN[v.severity] ?? 'medium',
|
|
363
|
+
category: v.category,
|
|
364
|
+
}))
|
|
365
|
+
: params.violations;
|
|
366
|
+
const architecture = params.architecture ?? (isScanBased ? { pattern: 'unknown', confidence: 0 } : undefined);
|
|
155
367
|
const constraints = params.constraints;
|
|
156
368
|
const styleProfile = params.styleProfile;
|
|
157
369
|
const teamContext = params.teamContext;
|
|
@@ -195,16 +407,52 @@ export class PlanMigrationTool {
|
|
|
195
407
|
const recommendedStrategy = this.selectOptimalStrategy(availableStrategies, constraints, styleProfile);
|
|
196
408
|
// Generate alternative strategies
|
|
197
409
|
const alternativeStrategies = availableStrategies.filter((s) => s.id !== recommendedStrategy.id);
|
|
198
|
-
// Create implementation roadmap
|
|
199
|
-
const
|
|
410
|
+
// Create implementation roadmap: from the files when possible
|
|
411
|
+
const notes = [];
|
|
412
|
+
let scanPlan;
|
|
413
|
+
let loadWarnings = [];
|
|
414
|
+
if (isScanBased && projectRoot) {
|
|
415
|
+
const projects = this.projects;
|
|
416
|
+
let cachedTsConfig;
|
|
417
|
+
const built = await buildScanPlan({
|
|
418
|
+
projectRoot,
|
|
419
|
+
violations: scanInput,
|
|
420
|
+
...(typeof params.maxPhases === 'number' ? { maxPhases: params.maxPhases } : {}),
|
|
421
|
+
...(projects
|
|
422
|
+
? {
|
|
423
|
+
loadProject: (path) => {
|
|
424
|
+
cachedTsConfig = path;
|
|
425
|
+
return projects.get(path);
|
|
426
|
+
},
|
|
427
|
+
}
|
|
428
|
+
: {}),
|
|
429
|
+
});
|
|
430
|
+
if (projects !== undefined && cachedTsConfig !== undefined) {
|
|
431
|
+
loadWarnings = projects.warnings(cachedTsConfig);
|
|
432
|
+
}
|
|
433
|
+
const effective = {
|
|
434
|
+
summaryOnly: compact.summaryOnly,
|
|
435
|
+
maxResults: compact.maxResults ?? SCAN_PLAN_DEFAULT_MAX_RESULTS,
|
|
436
|
+
};
|
|
437
|
+
scanPlan = this.toScanPlanOutput(built, effective);
|
|
438
|
+
}
|
|
439
|
+
else if (isScanBased) {
|
|
440
|
+
notes.push('Violations have file paths but projectRoot is missing; the roadmap uses the strategy templates.');
|
|
441
|
+
}
|
|
442
|
+
const roadmap = scanPlan
|
|
443
|
+
? this.createScanRoadmap(scanPlan)
|
|
444
|
+
: this.createImplementationRoadmap(recommendedStrategy, constraints);
|
|
200
445
|
// Generate reasoning
|
|
201
446
|
const reasoning = this.generateReasoning(recommendedStrategy, violations, constraints);
|
|
202
|
-
|
|
447
|
+
const plan = {
|
|
203
448
|
recommendedStrategy,
|
|
204
449
|
alternativeStrategies,
|
|
205
450
|
reasoning,
|
|
206
451
|
roadmap,
|
|
207
452
|
successMetrics: this.generateSuccessMetrics(recommendedStrategy),
|
|
453
|
+
planSource: scanPlan ? 'scan' : 'template',
|
|
454
|
+
...(scanPlan ? { scanPlan } : {}),
|
|
455
|
+
...(notes.length > 0 ? { notes } : {}),
|
|
208
456
|
// Style-aware results
|
|
209
457
|
styleAwareRiskAssessment,
|
|
210
458
|
styleConflictingSteps,
|
|
@@ -212,6 +460,105 @@ export class PlanMigrationTool {
|
|
|
212
460
|
styleAlignmentScore,
|
|
213
461
|
stepsWithStyleAnalysis,
|
|
214
462
|
};
|
|
463
|
+
return withWarnings({ ...plan, summary: describePlan(plan) }, loadWarnings);
|
|
464
|
+
}
|
|
465
|
+
// ========================================================================
|
|
466
|
+
// Scan-Based Planning
|
|
467
|
+
// ========================================================================
|
|
468
|
+
/**
|
|
469
|
+
* Inline violations plus the ones from scanResultFile.
|
|
470
|
+
*/
|
|
471
|
+
collectScanViolations(params, projectRoot) {
|
|
472
|
+
const inline = Array.isArray(params.violations)
|
|
473
|
+
? params.violations
|
|
474
|
+
: [];
|
|
475
|
+
if (typeof params.scanResultFile !== 'string') {
|
|
476
|
+
return inline;
|
|
477
|
+
}
|
|
478
|
+
if (!isAbsolute(params.scanResultFile) && !projectRoot) {
|
|
479
|
+
throw new Error('projectRoot is required when scanResultFile is a relative path');
|
|
480
|
+
}
|
|
481
|
+
const file = isAbsolute(params.scanResultFile)
|
|
482
|
+
? params.scanResultFile
|
|
483
|
+
: resolve(projectRoot ?? '', params.scanResultFile);
|
|
484
|
+
return [...inline, ...readScanResultFile(file)];
|
|
485
|
+
}
|
|
486
|
+
toScanPlanOutput(built, compact) {
|
|
487
|
+
const { plan } = built;
|
|
488
|
+
const phases = plan.phases.map((phase) => {
|
|
489
|
+
const { files, ...rest } = phase;
|
|
490
|
+
if (compact.summaryOnly) {
|
|
491
|
+
return rest;
|
|
492
|
+
}
|
|
493
|
+
// maxResults caps the files per phase and the violations per file;
|
|
494
|
+
// the counts on phases and files still cover everything
|
|
495
|
+
const limited = limitList(files, compact.maxResults);
|
|
496
|
+
return {
|
|
497
|
+
...rest,
|
|
498
|
+
files: limited.items.map((file) => {
|
|
499
|
+
const violations = limitList(file.violations, compact.maxResults);
|
|
500
|
+
return {
|
|
501
|
+
...file,
|
|
502
|
+
violations: violations.items,
|
|
503
|
+
...(violations.truncated ? { violationsTruncated: true } : {}),
|
|
504
|
+
};
|
|
505
|
+
}),
|
|
506
|
+
...(limited.truncated ? { truncated: true } : {}),
|
|
507
|
+
};
|
|
508
|
+
});
|
|
509
|
+
const layers = Object.entries(plan.stats.byLayer)
|
|
510
|
+
.sort(([, a], [, b]) => b - a)
|
|
511
|
+
.map(([layer, count]) => `${layer} ${count}`)
|
|
512
|
+
.join(', ');
|
|
513
|
+
return {
|
|
514
|
+
summary: `${plan.stats.violations} violation(s) in ${plan.stats.files} file(s), ${plan.phases.length} phase(s) ` +
|
|
515
|
+
`over ${plan.stats.levels} dependency level(s), ${plan.cycles.length} import cycle(s). ` +
|
|
516
|
+
`Files by layer: ${layers || 'none'}.`,
|
|
517
|
+
...(compact.summaryOnly ? {} : { maxResults: compact.maxResults }),
|
|
518
|
+
layerSource: built.layerSource,
|
|
519
|
+
graphFiles: built.graphFiles,
|
|
520
|
+
stats: plan.stats,
|
|
521
|
+
cycles: plan.cycles,
|
|
522
|
+
phases,
|
|
523
|
+
warnings: built.warnings,
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Roadmap with one phase per scan-plan phase and one step per file.
|
|
528
|
+
*/
|
|
529
|
+
createScanRoadmap(scanPlan) {
|
|
530
|
+
const phases = scanPlan.phases.map((phase) => ({
|
|
531
|
+
name: phase.name,
|
|
532
|
+
duration: `${phase.fileCount} file(s), ${phase.violationCount} violation(s)`,
|
|
533
|
+
steps: (phase.files ?? []).map((file) => this.fileToStep(file)),
|
|
534
|
+
deliverables: [
|
|
535
|
+
`No remaining violations in the ${phase.fileCount} file(s) of phase ${phase.index}`,
|
|
536
|
+
...(phase.cycleIds.length > 0
|
|
537
|
+
? [`Import cycle(s) ${phase.cycleIds.join(', ')} resolved together`]
|
|
538
|
+
: []),
|
|
539
|
+
],
|
|
540
|
+
}));
|
|
541
|
+
return {
|
|
542
|
+
phases,
|
|
543
|
+
totalDuration: `${phases.length} phase(s), ${scanPlan.stats.files} file(s)`,
|
|
544
|
+
milestones: scanPlan.phases.map((phase) => `Phase ${phase.index} clean (${phase.layers.join(', ')})`),
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
fileToStep(file) {
|
|
548
|
+
const rules = Object.entries(file.byRule)
|
|
549
|
+
.sort(([, a], [, b]) => b - a)
|
|
550
|
+
.map(([rule, count]) => `${rule} x${count}`)
|
|
551
|
+
.join(', ');
|
|
552
|
+
const blocking = file.dependsOn.length > 0 ? ` after ${file.dependsOn.length} dependency file(s)` : '';
|
|
553
|
+
const cycle = file.cycleId !== undefined ? ` together with import cycle ${file.cycleId}` : '';
|
|
554
|
+
const severe = (file.bySeverity['error'] ?? 0) + (file.bySeverity['high'] ?? 0) + (file.bySeverity['critical'] ?? 0);
|
|
555
|
+
return {
|
|
556
|
+
name: `${file.order}. ${file.filePath}`,
|
|
557
|
+
action: `Fix ${file.violationCount} violation(s): ${rules}${blocking}${cycle}`,
|
|
558
|
+
validation: `Re-run scan-architecture on ${file.filePath}; run-build`,
|
|
559
|
+
effort: Math.min(10, file.violationCount),
|
|
560
|
+
risk: severe > 0 || file.cycleId !== undefined ? 'high' : file.dependsOn.length > 0 ? 'medium' : 'low',
|
|
561
|
+
};
|
|
215
562
|
}
|
|
216
563
|
// ========================================================================
|
|
217
564
|
// Style-Aware Migration Planning Methods
|
|
@@ -16,16 +16,22 @@
|
|
|
16
16
|
* // args: { file: '/project/src/app/user.service.ts', line: 42, column: 15, projectRoot: '/project' }
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
|
-
import { type MCPTool } from '../types.js';
|
|
19
|
+
import { type MCPTool, type ToolAnnotations } from '../types.js';
|
|
20
20
|
import { type ResolvedTypeInfo } from '@angular-modernizer/api';
|
|
21
|
+
import { ProjectCache } from './helpers/project-cache.js';
|
|
21
22
|
/**
|
|
22
23
|
* MCP tool that resolves the TypeScript type at a given source position.
|
|
23
24
|
*/
|
|
24
25
|
export declare class ResolveTypeTool implements MCPTool {
|
|
26
|
+
private readonly projects;
|
|
25
27
|
readonly name = "resolve-type";
|
|
28
|
+
readonly title = "Resolve Type";
|
|
29
|
+
readonly annotations: ToolAnnotations;
|
|
30
|
+
constructor(projects?: ProjectCache);
|
|
26
31
|
readonly description: string;
|
|
27
32
|
readonly inputSchema: {
|
|
28
33
|
type: string;
|
|
34
|
+
additionalProperties: boolean;
|
|
29
35
|
properties: {
|
|
30
36
|
file: {
|
|
31
37
|
type: string;
|
|
@@ -46,8 +52,43 @@ export declare class ResolveTypeTool implements MCPTool {
|
|
|
46
52
|
};
|
|
47
53
|
required: string[];
|
|
48
54
|
};
|
|
55
|
+
readonly outputSchema: {
|
|
56
|
+
type: string;
|
|
57
|
+
properties: {
|
|
58
|
+
warnings: {
|
|
59
|
+
readonly type: "array";
|
|
60
|
+
readonly items: {
|
|
61
|
+
readonly type: "string";
|
|
62
|
+
};
|
|
63
|
+
readonly description: "Conditions that can make the result incomplete, e.g. library imports that do not resolve because node_modules is missing.";
|
|
64
|
+
};
|
|
65
|
+
typeString: {
|
|
66
|
+
type: string;
|
|
67
|
+
};
|
|
68
|
+
genericParams: {
|
|
69
|
+
type: string;
|
|
70
|
+
items: {
|
|
71
|
+
type: string;
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
declaredIn: {
|
|
75
|
+
type: string;
|
|
76
|
+
};
|
|
77
|
+
isNullable: {
|
|
78
|
+
type: string;
|
|
79
|
+
};
|
|
80
|
+
isAsync: {
|
|
81
|
+
type: string;
|
|
82
|
+
};
|
|
83
|
+
summary: {
|
|
84
|
+
type: string;
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
required: string[];
|
|
88
|
+
};
|
|
49
89
|
execute(args: Record<string, unknown>): Promise<ResolvedTypeInfo & {
|
|
50
90
|
summary: string;
|
|
91
|
+
warnings?: string[];
|
|
51
92
|
}>;
|
|
52
93
|
private buildSummary;
|
|
53
94
|
}
|
|
@@ -16,21 +16,34 @@
|
|
|
16
16
|
* // args: { file: '/project/src/app/user.service.ts', line: 42, column: 15, projectRoot: '/project' }
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
|
-
import { Project } from 'ts-morph';
|
|
20
19
|
import { TypeResolver } from '@angular-modernizer/api';
|
|
21
20
|
import { existsSync } from 'node:fs';
|
|
22
21
|
import { findTsConfig } from './helpers/find-ts-config.js';
|
|
22
|
+
import { ProjectCache } from './helpers/project-cache.js';
|
|
23
|
+
import { WARNINGS_OUTPUT_SCHEMA, withWarnings, } from './helpers/output-contract.js';
|
|
23
24
|
/**
|
|
24
25
|
* MCP tool that resolves the TypeScript type at a given source position.
|
|
25
26
|
*/
|
|
26
27
|
export class ResolveTypeTool {
|
|
28
|
+
projects;
|
|
27
29
|
name = 'resolve-type';
|
|
30
|
+
title = 'Resolve Type';
|
|
31
|
+
annotations = {
|
|
32
|
+
readOnlyHint: true,
|
|
33
|
+
destructiveHint: false,
|
|
34
|
+
idempotentHint: true,
|
|
35
|
+
openWorldHint: false,
|
|
36
|
+
};
|
|
37
|
+
constructor(projects = new ProjectCache()) {
|
|
38
|
+
this.projects = projects;
|
|
39
|
+
}
|
|
28
40
|
description = 'Resolve the TypeScript type at a given position (file, line, column). ' +
|
|
29
41
|
'Returns the full type string, nullability, whether it is async (Promise/Observable), ' +
|
|
30
42
|
'and where the type is declared. Use during bug investigation to trace type mismatches ' +
|
|
31
43
|
'and null-reference errors.';
|
|
32
44
|
inputSchema = {
|
|
33
45
|
type: 'object',
|
|
46
|
+
additionalProperties: false,
|
|
34
47
|
properties: {
|
|
35
48
|
file: {
|
|
36
49
|
type: 'string',
|
|
@@ -51,6 +64,26 @@ export class ResolveTypeTool {
|
|
|
51
64
|
},
|
|
52
65
|
required: ['file', 'line', 'column', 'projectRoot'],
|
|
53
66
|
};
|
|
67
|
+
outputSchema = {
|
|
68
|
+
type: 'object',
|
|
69
|
+
properties: {
|
|
70
|
+
typeString: { type: 'string' },
|
|
71
|
+
genericParams: { type: 'array', items: { type: 'string' } },
|
|
72
|
+
declaredIn: { type: 'string' },
|
|
73
|
+
isNullable: { type: 'boolean' },
|
|
74
|
+
isAsync: { type: 'boolean' },
|
|
75
|
+
summary: { type: 'string' },
|
|
76
|
+
...WARNINGS_OUTPUT_SCHEMA,
|
|
77
|
+
},
|
|
78
|
+
required: [
|
|
79
|
+
'typeString',
|
|
80
|
+
'genericParams',
|
|
81
|
+
'declaredIn',
|
|
82
|
+
'isNullable',
|
|
83
|
+
'isAsync',
|
|
84
|
+
'summary',
|
|
85
|
+
],
|
|
86
|
+
};
|
|
54
87
|
async execute(args) {
|
|
55
88
|
const params = args;
|
|
56
89
|
if (!params.file) {
|
|
@@ -72,13 +105,13 @@ export class ResolveTypeTool {
|
|
|
72
105
|
if (!tsConfigPath) {
|
|
73
106
|
throw new Error(`tsconfig.json not found in projectRoot: ${params.projectRoot}`);
|
|
74
107
|
}
|
|
75
|
-
const project =
|
|
108
|
+
const project = this.projects.get(tsConfigPath);
|
|
76
109
|
const typeResolver = new TypeResolver(project);
|
|
77
110
|
const info = typeResolver.resolveType(params.file, params.line, params.column);
|
|
78
|
-
return {
|
|
111
|
+
return withWarnings({
|
|
79
112
|
...info,
|
|
80
113
|
summary: this.buildSummary(params.file, params.line, params.column, info),
|
|
81
|
-
};
|
|
114
|
+
}, this.projects.warnings(tsConfigPath));
|
|
82
115
|
}
|
|
83
116
|
buildSummary(file, line, column, info) {
|
|
84
117
|
if (info.typeString === 'unknown') {
|