@angular-modernizer/adapter-mcp 1.0.0 → 1.2.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 (131) hide show
  1. package/README.md +81 -65
  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 +58 -36
  24. package/dist/tools/analyze-build-impact.js +36 -29
  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 +87 -14
  30. package/dist/tools/analyze-project.js +140 -122
  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 +27 -25
  40. package/dist/tools/find-angular-symbol.js +19 -16
  41. package/dist/tools/find-component-hosts.d.ts +33 -27
  42. package/dist/tools/find-component-hosts.js +27 -24
  43. package/dist/tools/find-usages.d.ts +25 -23
  44. package/dist/tools/find-usages.js +21 -18
  45. package/dist/tools/get-bootstrap-execution.d.ts +35 -27
  46. package/dist/tools/get-bootstrap-execution.js +28 -25
  47. package/dist/tools/get-call-graph.d.ts +19 -14
  48. package/dist/tools/get-call-graph.js +26 -23
  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 +123 -36
  60. package/dist/tools/helpers/project-cache.js +227 -43
  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/scan-plan.d.ts +1 -1
  66. package/dist/tools/helpers/scan-plan.js +1 -1
  67. package/dist/tools/helpers/suggestion-generator.d.ts +9 -13
  68. package/dist/tools/helpers/suggestion-generator.js +0 -12
  69. package/dist/tools/helpers/tool-cache.d.ts +11 -0
  70. package/dist/tools/helpers/tool-cache.js +15 -0
  71. package/dist/tools/helpers/tool-context.d.ts +11 -8
  72. package/dist/tools/helpers/tool-context.js +5 -8
  73. package/dist/tools/inspect-form-group.d.ts +34 -27
  74. package/dist/tools/inspect-form-group.js +27 -24
  75. package/dist/tools/inspect-i18n.d.ts +31 -25
  76. package/dist/tools/inspect-i18n.js +23 -20
  77. package/dist/tools/inspect-template.d.ts +32 -25
  78. package/dist/tools/inspect-template.js +26 -23
  79. package/dist/tools/learn-patterns.d.ts +88 -12
  80. package/dist/tools/learn-patterns.js +17 -11
  81. package/dist/tools/list-imports.d.ts +45 -28
  82. package/dist/tools/list-imports.js +26 -23
  83. package/dist/tools/orchestrate-migration.d.ts +31 -9
  84. package/dist/tools/orchestrate-migration.js +12 -7
  85. package/dist/tools/parse-stack-trace.d.ts +23 -21
  86. package/dist/tools/parse-stack-trace.js +10 -7
  87. package/dist/tools/plan-migration.d.ts +67 -27
  88. package/dist/tools/plan-migration.js +22 -21
  89. package/dist/tools/resolve-type.d.ts +20 -10
  90. package/dist/tools/resolve-type.js +21 -13
  91. package/dist/tools/review-feedback.d.ts +27 -24
  92. package/dist/tools/review-feedback.js +24 -20
  93. package/dist/tools/rollback-changes.d.ts +13 -9
  94. package/dist/tools/rollback-changes.js +10 -7
  95. package/dist/tools/run-angular-cli.d.ts +12 -10
  96. package/dist/tools/run-angular-cli.js +11 -8
  97. package/dist/tools/run-build.d.ts +13 -11
  98. package/dist/tools/run-build.js +11 -8
  99. package/dist/tools/run-schematic.d.ts +12 -10
  100. package/dist/tools/run-schematic.js +11 -8
  101. package/dist/tools/scan-all.d.ts +69 -12
  102. package/dist/tools/scan-all.js +55 -122
  103. package/dist/tools/scan-angular.d.ts +41 -9
  104. package/dist/tools/scan-angular.js +66 -135
  105. package/dist/tools/scan-architecture.d.ts +75 -14
  106. package/dist/tools/scan-architecture.js +180 -185
  107. package/dist/tools/scan-solid.d.ts +40 -9
  108. package/dist/tools/scan-solid.js +64 -133
  109. package/dist/tools/search-codebase.d.ts +32 -26
  110. package/dist/tools/search-codebase.js +15 -12
  111. package/dist/tools/server-status.d.ts +116 -24
  112. package/dist/tools/server-status.js +85 -26
  113. package/dist/tools/suggest-improvements.d.ts +22 -19
  114. package/dist/tools/suggest-improvements.js +21 -17
  115. package/dist/tools/trace-output-flow.d.ts +34 -27
  116. package/dist/tools/trace-output-flow.js +27 -24
  117. package/dist/tools/transform-code.d.ts +71 -10
  118. package/dist/tools/transform-code.js +148 -54
  119. package/dist/tools/validate-before-transform.d.ts +24 -9
  120. package/dist/tools/validate-before-transform.js +10 -7
  121. package/dist/tools/validate-project-compatibility.d.ts +18 -13
  122. package/dist/tools/validate-project-compatibility.js +17 -11
  123. package/dist/tools/validate-transformation.d.ts +28 -11
  124. package/dist/tools/validate-transformation.js +14 -8
  125. package/dist/tools/verify-citations.d.ts +37 -16
  126. package/dist/tools/verify-citations.js +19 -16
  127. package/dist/types.d.ts +40 -10
  128. package/dist/types.js +0 -5
  129. package/package.json +12 -18
  130. package/dist/tools/shared/scan-types.d.ts +0 -200
  131. package/dist/tools/shared/scan-types.js +0 -7
@@ -1,10 +1,3 @@
1
- /**
2
- * @angular-modernizer/adapter-mcp - MCP Server
3
- *
4
- * Owns the stdio server lifecycle. The protocol is served by the MCP SDK
5
- * (`serveStdio`, both eras) over a size-limited stdio transport; the tools
6
- * come from the tool registry.
7
- */
8
1
  import { serveStdio } from '@modelcontextprotocol/server/stdio';
9
2
  import { ToolRegistry } from './tool-registry.js';
10
3
  import { createServerFactory } from './sdk-server.js';
@@ -22,6 +15,10 @@ const SHUTDOWN_FLUSH_TIMEOUT_MS = 1000;
22
15
  * Main MCP server class that handles the complete MCP protocol lifecycle.
23
16
  *
24
17
  * @remarks
18
+ * Owns the stdio server lifecycle. The protocol is served by the MCP SDK
19
+ * (`serveStdio`, both eras) over a size-limited stdio transport; the tools
20
+ * come from the tool registry.
21
+ *
25
22
  * The stdio server ends when the client goes away: stdin `end`, `close` or
26
23
  * `error`, a failing stdout (EPIPE), SIGINT, SIGTERM, SIGHUP, or its parent
27
24
  * process disappearing. The last check covers clients that die while another
@@ -23,6 +23,7 @@ import { type ToolContext } from '../types.js';
23
23
  export type ProtocolEra = 'legacy' | 'modern';
24
24
  /** What the client negotiated, as far as it is known. */
25
25
  export interface ProtocolInfo {
26
+ /** Protocol era of the connection. */
26
27
  era?: ProtocolEra;
27
28
  /** Protocol revision the last request was served with. */
28
29
  version?: string;
@@ -1,12 +1,6 @@
1
- /**
2
- * @angular-modernizer/adapter-mcp - Tool Registry
3
- *
4
- * Central registry for MCP tools. Manages tool registration,
5
- * discovery, and execution coordination.
6
- */
7
1
  import { type MCPTool, type ToolContext } from '../types.js';
8
2
  /**
9
- * Registry for MCP tools with registration and discovery capabilities.
3
+ * Central registry for MCP tools: registration, discovery and execution.
10
4
  */
11
5
  export declare class ToolRegistry {
12
6
  private readonly tools;
@@ -67,7 +61,9 @@ export declare class ToolRegistry {
67
61
  * @returns Statistics about registered tools
68
62
  */
69
63
  getStats(): {
64
+ /** Number of registered tools. */
70
65
  totalTools: number;
66
+ /** Names of the registered tools. */
71
67
  toolNames: string[];
72
68
  };
73
69
  }
@@ -1,12 +1,6 @@
1
- /**
2
- * @angular-modernizer/adapter-mcp - Tool Registry
3
- *
4
- * Central registry for MCP tools. Manages tool registration,
5
- * discovery, and execution coordination.
6
- */
7
1
  import { formatStructuredToolResponse } from '../utils/format-tool-response.js';
8
2
  /**
9
- * Registry for MCP tools with registration and discovery capabilities.
3
+ * Central registry for MCP tools: registration, discovery and execution.
10
4
  */
11
5
  export class ToolRegistry {
12
6
  tools = new Map();
@@ -1,28 +1,40 @@
1
- /**
2
- * @angular-modernizer/adapter-mcp - Progress Store
3
- */
4
1
  import type { StreamingProgressEvent } from '@angular-modernizer/core';
5
2
  /**
6
3
  * Metadata for tracking operation lifecycle
7
4
  */
8
5
  export interface OperationMetadata {
6
+ /** Operation id returned to the client. */
9
7
  readonly operationId: string;
8
+ /** Kind of operation. */
10
9
  readonly type: 'transformation' | 'analysis';
10
+ /** Start time in milliseconds since the epoch. */
11
11
  readonly startTime: number;
12
+ /** Lifecycle status; starts as `'running'`. */
12
13
  status: 'running' | 'completed' | 'failed' | 'cancelled';
14
+ /** Error message of a failed operation. */
13
15
  error?: string;
14
16
  }
15
17
  /**
16
18
  * Complete operation state including events and metadata
17
19
  */
18
20
  export interface OperationState {
21
+ /** Lifecycle metadata. */
19
22
  metadata: OperationMetadata;
23
+ /** Progress events in the order they were added. */
20
24
  events: StreamingProgressEvent[];
25
+ /** Final result, stored with `setResult` before `markComplete`. */
21
26
  result?: unknown;
22
27
  }
23
28
  /**
24
- * Thread-safe singleton store for streaming operation progress
25
- * Provides TTL-based cleanup and efficient event querying
29
+ * Singleton store for the progress of streaming operations (deprecated
30
+ * `streaming` path and get-operation-progress), with TTL-based cleanup:
31
+ * finished operations are deleted after 5 minutes, running ones are marked
32
+ * failed with a timeout event after 10.
33
+ *
34
+ * @remarks
35
+ * Call `setResult(operationId, result)` before `markComplete(operationId)`:
36
+ * get-operation-progress returns `result` only for completed operations that
37
+ * have one.
26
38
  */
27
39
  export declare class ProgressStore {
28
40
  private static instance;
@@ -110,10 +122,15 @@ export declare class ProgressStore {
110
122
  * Get store statistics (for monitoring)
111
123
  */
112
124
  getStats(): {
125
+ /** Number of stored operations. */
113
126
  totalOperations: number;
127
+ /** Operations with status `'running'`. */
114
128
  runningOperations: number;
129
+ /** Operations with status `'completed'`. */
115
130
  completedOperations: number;
131
+ /** Operations with status `'failed'`. */
116
132
  failedOperations: number;
133
+ /** Operations with status `'cancelled'`. */
117
134
  cancelledOperations: number;
118
135
  };
119
136
  }
@@ -1,9 +1,13 @@
1
1
  /**
2
- * @angular-modernizer/adapter-mcp - Progress Store
3
- */
4
- /**
5
- * Thread-safe singleton store for streaming operation progress
6
- * Provides TTL-based cleanup and efficient event querying
2
+ * Singleton store for the progress of streaming operations (deprecated
3
+ * `streaming` path and get-operation-progress), with TTL-based cleanup:
4
+ * finished operations are deleted after 5 minutes, running ones are marked
5
+ * failed with a timeout event after 10.
6
+ *
7
+ * @remarks
8
+ * Call `setResult(operationId, result)` before `markComplete(operationId)`:
9
+ * get-operation-progress returns `result` only for completed operations that
10
+ * have one.
7
11
  */
8
12
  export class ProgressStore {
9
13
  static instance = null;
@@ -1,40 +1,15 @@
1
- /**
2
- * @angular-modernizer/adapter-mcp - Analyze Build Impact Tool
3
- *
4
- * MCP tool for analyzing build impact before transformations.
5
- * Estimates affected files, modules, build time, and provides AI-friendly recommendations.
6
- * Uses IncrementalAnalyzer.getBuildScope() with the target files as the changed
7
- * set. The underlying DependencyGraphBuilder follows `export ... from`,
8
- * resolves tsconfig path aliases, splits value vs type-only dependents and
9
- * does not let barrels inflate the radius. Optional `symbols` restrict the
10
- * impact to consumers of specific exported symbols.
11
- *
12
- * External templates (`.html`) are not part of the TypeScript program; they
13
- * are mapped to the component files that own them (`templateUrl`, then same
14
- * basename) instead of failing. Such a component is recompiled, but its
15
- * dependents are not counted, because a template edit does not change the
16
- * component's TypeScript API. Files that cannot be mapped are listed in
17
- * `unresolvedFiles`. `summaryOnly` and `maxResults` shorten the file lists;
18
- * counts always describe the full result.
19
- *
20
- * Host components that use a changed component, directive or pipe only in
21
- * their template (NgModule declarations, no import of the class) are listed
22
- * as `templateDependentFiles` and, with the used classes, in `templateHosts`.
23
- * They are recompiled and template type-checked; their own dependents are not
24
- * counted.
25
- */
26
- import { type MCPTool, type ToolAnnotations } from '../types.js';
1
+ import { type MCPTool, type ToolAnnotations, type ToolContext } from '../types.js';
27
2
  import { type BuildScopeSymbolImpact } from '@angular-modernizer/core';
28
3
  import { type TemplateEdge } from '@angular-modernizer/api';
29
4
  import { type ProjectCache } from './helpers/project-cache.js';
30
5
  /**
31
6
  * Build scope strategy
32
7
  */
33
- type BuildScopeStrategy = 'affected-only' | 'partial' | 'full';
8
+ export type BuildScopeStrategy = 'affected-only' | 'partial' | 'full';
34
9
  /**
35
10
  * Estimated build scope information
36
11
  */
37
- interface EstimatedBuildScope {
12
+ export interface EstimatedBuildScope {
38
13
  /**
39
14
  * Recommended build strategy based on impact
40
15
  */
@@ -79,7 +54,7 @@ interface EstimatedBuildScope {
79
54
  /**
80
55
  * Dependency information for a file
81
56
  */
82
- interface DependencyInfo {
57
+ export interface DependencyInfo {
83
58
  /**
84
59
  * File path
85
60
  */
@@ -112,49 +87,67 @@ interface DependencyInfo {
112
87
  /**
113
88
  * Sizes of the full result, independent of `summaryOnly` / `maxResults`.
114
89
  */
115
- interface BuildImpactCounts {
90
+ export interface BuildImpactCounts {
91
+ /** Requested files that resolved to the TypeScript program. */
116
92
  changedFiles: number;
93
+ /** Files that depend on the changed files. */
117
94
  dependentFiles: number;
95
+ /** Dependents that need a JavaScript rebuild. */
118
96
  valueDependentFiles: number;
97
+ /** Dependents that import types only (type-check, no rebuild). */
119
98
  typeOnlyDependentFiles: number;
99
+ /** Host components that use a changed class only in their template. */
120
100
  templateDependentFiles: number;
101
+ /** Barrel files that only re-export changed code. */
121
102
  reExportFiles: number;
103
+ /** Changed files plus dependents. */
122
104
  affectedFiles: number;
105
+ /** Affected NgModules. */
123
106
  affectedModules: number;
124
107
  }
125
108
  /**
126
109
  * A host component that uses changed classes in its template only.
127
110
  */
128
- interface TemplateHost {
111
+ export interface TemplateHost {
129
112
  /** Host component file. */
130
113
  file: string;
114
+ /** Host component class. */
131
115
  component: string;
116
+ /** Changed classes the host's template uses. */
132
117
  uses: {
118
+ /** Class used by the template. */
133
119
  className: string;
120
+ /** How the template uses the class. */
134
121
  via: TemplateEdge['via'];
122
+ /** Source file declaring the used class. */
135
123
  file: string;
124
+ /** Template file of the first use (`.html`, or the `.ts` file for inline templates). */
136
125
  templateFile: string;
137
126
  }[];
138
127
  }
139
128
  /**
140
129
  * A requested non-TypeScript file mapped to the component files that own it.
141
130
  */
142
- interface MappedFile {
131
+ export interface MappedFile {
132
+ /** Requested file, e.g. an `.html` template. */
143
133
  file: string;
134
+ /** Component files that own it. */
144
135
  mappedTo: string[];
145
136
  }
146
137
  /**
147
138
  * A requested file that could not be placed in the TypeScript program.
148
139
  */
149
- interface UnresolvedFile {
140
+ export interface UnresolvedFile {
141
+ /** Requested file. */
150
142
  file: string;
143
+ /** Why it could not be analyzed. */
151
144
  reason: string;
152
145
  }
153
146
  /**
154
147
  * Output result of build impact analysis. `recommendation` comes first so it
155
148
  * is the first thing a reader of the JSON sees.
156
149
  */
157
- interface AnalyzeBuildImpactOutput {
150
+ export interface AnalyzeBuildImpactOutput {
158
151
  /**
159
152
  * AI-friendly recommendation
160
153
  */
@@ -215,6 +208,28 @@ interface AnalyzeBuildImpactOutput {
215
208
  }
216
209
  /**
217
210
  * MCP tool for analyzing build impact before transformations.
211
+ * Estimates affected files, modules, build time, and gives a recommendation.
212
+ *
213
+ * @remarks
214
+ * Uses `IncrementalAnalyzer.getBuildScope()` with the target files as the
215
+ * changed set. The underlying `DependencyGraphBuilder` follows
216
+ * `export ... from`, resolves tsconfig path aliases, splits value vs type-only
217
+ * dependents and does not let barrels inflate the radius. Optional `symbols`
218
+ * restrict the impact to consumers of specific exported symbols.
219
+ *
220
+ * External templates (`.html`) are not part of the TypeScript program; they
221
+ * are mapped to the component files that own them (`templateUrl`, then same
222
+ * basename) instead of failing. Such a component is recompiled, but its
223
+ * dependents are not counted, because a template edit does not change the
224
+ * component's TypeScript API. Files that cannot be mapped are listed in
225
+ * `unresolvedFiles`. `summaryOnly` and `maxResults` shorten the file lists;
226
+ * counts always describe the full result.
227
+ *
228
+ * Host components that use a changed component, directive or pipe only in
229
+ * their template (NgModule declarations, no import of the class) are listed
230
+ * as `templateDependentFiles` and, with the used classes, in `templateHosts`.
231
+ * They are recompiled and template type-checked; their own dependents are not
232
+ * counted.
218
233
  */
219
234
  export declare class AnalyzeBuildImpactTool implements MCPTool {
220
235
  private readonly projects?;
@@ -227,6 +242,10 @@ export declare class AnalyzeBuildImpactTool implements MCPTool {
227
242
  title: string;
228
243
  annotations: ToolAnnotations;
229
244
  description: string;
245
+ /**
246
+ * JSON Schema of the tool arguments.
247
+ * @hidden
248
+ */
230
249
  inputSchema: {
231
250
  type: string;
232
251
  additionalProperties: boolean;
@@ -261,6 +280,10 @@ export declare class AnalyzeBuildImpactTool implements MCPTool {
261
280
  };
262
281
  required: string[];
263
282
  };
283
+ /**
284
+ * JSON Schema of the tool result (`structuredContent`).
285
+ * @hidden
286
+ */
264
287
  outputSchema: {
265
288
  type: string;
266
289
  properties: {
@@ -469,7 +492,7 @@ export declare class AnalyzeBuildImpactTool implements MCPTool {
469
492
  };
470
493
  required: string[];
471
494
  };
472
- execute(args: Record<string, unknown>): Promise<AnalyzeBuildImpactOutput>;
495
+ execute(args: Record<string, unknown>, ctx?: ToolContext): Promise<AnalyzeBuildImpactOutput>;
473
496
  /**
474
497
  * Splits the requested files into files of the TypeScript program, `.html`
475
498
  * templates mapped to their component files, and files that fit neither.
@@ -499,5 +522,4 @@ export declare class AnalyzeBuildImpactTool implements MCPTool {
499
522
  */
500
523
  private getComponentClass;
501
524
  }
502
- export {};
503
525
  //# sourceMappingURL=analyze-build-impact.d.ts.map
@@ -1,34 +1,10 @@
1
- /**
2
- * @angular-modernizer/adapter-mcp - Analyze Build Impact Tool
3
- *
4
- * MCP tool for analyzing build impact before transformations.
5
- * Estimates affected files, modules, build time, and provides AI-friendly recommendations.
6
- * Uses IncrementalAnalyzer.getBuildScope() with the target files as the changed
7
- * set. The underlying DependencyGraphBuilder follows `export ... from`,
8
- * resolves tsconfig path aliases, splits value vs type-only dependents and
9
- * does not let barrels inflate the radius. Optional `symbols` restrict the
10
- * impact to consumers of specific exported symbols.
11
- *
12
- * External templates (`.html`) are not part of the TypeScript program; they
13
- * are mapped to the component files that own them (`templateUrl`, then same
14
- * basename) instead of failing. Such a component is recompiled, but its
15
- * dependents are not counted, because a template edit does not change the
16
- * component's TypeScript API. Files that cannot be mapped are listed in
17
- * `unresolvedFiles`. `summaryOnly` and `maxResults` shorten the file lists;
18
- * counts always describe the full result.
19
- *
20
- * Host components that use a changed component, directive or pipe only in
21
- * their template (NgModule declarations, no import of the class) are listed
22
- * as `templateDependentFiles` and, with the used classes, in `templateHosts`.
23
- * They are recompiled and template type-checked; their own dependents are not
24
- * counted.
25
- */
26
1
  import { Project } from 'ts-morph';
27
2
  import { IncrementalAnalyzer, } from '@angular-modernizer/core';
28
3
  import { findTemplateOwnerFiles, } from '@angular-modernizer/api';
29
4
  import { existsSync } from 'node:fs';
30
5
  import { join } from 'node:path';
31
6
  import { findTsConfig } from './helpers/find-ts-config.js';
7
+ import { acquireProject } from './helpers/project-cache.js';
32
8
  import { STRING_ARRAY } from './helpers/investigation-schemas.js';
33
9
  import { WARNINGS_OUTPUT_SCHEMA, withWarnings } from './helpers/output-contract.js';
34
10
  import { COMPACT_OUTPUT_SCHEMA, limitList, parseCompactOptions, } from './helpers/compact-output.js';
@@ -75,6 +51,28 @@ function toTemplateHosts(edges) {
75
51
  }
76
52
  /**
77
53
  * MCP tool for analyzing build impact before transformations.
54
+ * Estimates affected files, modules, build time, and gives a recommendation.
55
+ *
56
+ * @remarks
57
+ * Uses `IncrementalAnalyzer.getBuildScope()` with the target files as the
58
+ * changed set. The underlying `DependencyGraphBuilder` follows
59
+ * `export ... from`, resolves tsconfig path aliases, splits value vs type-only
60
+ * dependents and does not let barrels inflate the radius. Optional `symbols`
61
+ * restrict the impact to consumers of specific exported symbols.
62
+ *
63
+ * External templates (`.html`) are not part of the TypeScript program; they
64
+ * are mapped to the component files that own them (`templateUrl`, then same
65
+ * basename) instead of failing. Such a component is recompiled, but its
66
+ * dependents are not counted, because a template edit does not change the
67
+ * component's TypeScript API. Files that cannot be mapped are listed in
68
+ * `unresolvedFiles`. `summaryOnly` and `maxResults` shorten the file lists;
69
+ * counts always describe the full result.
70
+ *
71
+ * Host components that use a changed component, directive or pipe only in
72
+ * their template (NgModule declarations, no import of the class) are listed
73
+ * as `templateDependentFiles` and, with the used classes, in `templateHosts`.
74
+ * They are recompiled and template type-checked; their own dependents are not
75
+ * counted.
78
76
  */
79
77
  export class AnalyzeBuildImpactTool {
80
78
  projects;
@@ -98,6 +96,10 @@ export class AnalyzeBuildImpactTool {
98
96
  'directive or pipe only in their template (NgModule declarations) are listed as templateHosts. ' +
99
97
  'The recommendation and counts come first, summary repeats them as text; ' +
100
98
  'use summaryOnly to skip the file lists or maxResults to cap them.';
99
+ /**
100
+ * JSON Schema of the tool arguments.
101
+ * @hidden
102
+ */
101
103
  inputSchema = {
102
104
  type: 'object',
103
105
  additionalProperties: false,
@@ -124,6 +126,10 @@ export class AnalyzeBuildImpactTool {
124
126
  },
125
127
  required: ['projectPath', 'filesToChange'],
126
128
  };
129
+ /**
130
+ * JSON Schema of the tool result (`structuredContent`).
131
+ * @hidden
132
+ */
127
133
  outputSchema = {
128
134
  type: 'object',
129
135
  properties: {
@@ -223,7 +229,7 @@ export class AnalyzeBuildImpactTool {
223
229
  'summary',
224
230
  ],
225
231
  };
226
- async execute(args) {
232
+ async execute(args, ctx = {}) {
227
233
  const params = args;
228
234
  if (!params.projectPath) {
229
235
  throw new Error('projectPath is required');
@@ -247,11 +253,12 @@ export class AnalyzeBuildImpactTool {
247
253
  : [];
248
254
  // Initialize ts-morph project
249
255
  // Shared cache in the server (one parse per workspace); a fresh Project otherwise
250
- const project = this.projects?.get(tsConfigPath) ??
251
- new Project({
256
+ const project = this.projects === undefined
257
+ ? new Project({
252
258
  tsConfigFilePath: tsConfigPath,
253
259
  skipAddingFilesFromTsConfig: false,
254
- });
260
+ })
261
+ : await acquireProject(this.projects, tsConfigPath, ctx);
255
262
  // Normalize file paths to absolute paths
256
263
  const requestedFiles = filesToChange.map((file) => {
257
264
  if (file.startsWith('/')) {
@@ -1,45 +1,66 @@
1
- /**
2
- * @angular-modernizer/adapter-mcp - Analyze Core-to-Shared Tool
3
- *
4
- * MCP tool for analyzing core-to-shared dependency violations with impact assessment.
5
- * Detects when core layer imports from shared layer and provides detailed refactoring guidance.
6
- */
7
1
  import type { MCPTool, ToolAnnotations } from '../types.js';
8
2
  /**
9
3
  * Result from the analyze-core-to-shared tool.
10
4
  */
11
- interface AnalyzeCoreToSharedResult {
5
+ export interface AnalyzeCoreToSharedResult {
12
6
  /**
13
7
  * Core-to-shared violations found.
14
8
  */
15
9
  violations: {
10
+ /** Violation id: `<filePath>:<line>:<importedModule>:<importedItem>`. */
16
11
  id: string;
12
+ /** Core file that imports from the shared layer. */
17
13
  filePath: string;
14
+ /** Line of the import declaration. */
18
15
  line: number;
16
+ /** Module specifier of the shared module. */
19
17
  importedModule: string;
18
+ /** Imported name, with `as <alias>` when aliased. */
20
19
  importedItem: string;
20
+ /**
21
+ * `error` without impact assessment or with HIGH risk, `warning` with
22
+ * MEDIUM or LOW risk.
23
+ */
21
24
  severity: 'error' | 'warning';
25
+ /** Violation message. */
22
26
  message: string;
27
+ /** Impact of changing the import; only with `includeImpactAssessment`. */
23
28
  impactAssessment?: {
29
+ /** Risk of a breaking change, derived from the reverse dependencies. */
24
30
  breakingChangeRisk: 'LOW' | 'MEDIUM' | 'HIGH';
31
+ /** Reasons for the risk level. */
25
32
  riskFactors: string[];
33
+ /** Files under `src/` that import the core file. */
26
34
  reverseDependencies: {
35
+ /** Importing file, relative to `src/`. */
27
36
  file: string;
37
+ /** Names imported by that file. */
28
38
  imports: string[];
29
39
  }[];
40
+ /**
41
+ * Non-relative imports of the core file, without `@angular` and
42
+ * `@shared` modules.
43
+ */
30
44
  transitiveDependencies: string[];
31
45
  };
46
+ /** Suggested refactoring. */
32
47
  suggestedFix: string;
48
+ /** Violation type and the imported name and alias. */
33
49
  metadata?: Record<string, unknown>;
34
50
  }[];
35
51
  /**
36
52
  * Counts over all violations.
37
53
  */
38
54
  counts: {
55
+ /** Number of all violations. */
39
56
  totalViolations: number;
57
+ /** Number of analyzed core files. */
40
58
  analyzedFiles: number;
59
+ /** Violations per severity. */
41
60
  bySeverity: Record<string, number>;
61
+ /** Core files with at least one violation. */
42
62
  affectedCoreFiles: number;
63
+ /** Distinct shared modules imported. */
43
64
  uniqueSharedModules: number;
44
65
  };
45
66
  /**
@@ -50,22 +71,28 @@ interface AnalyzeCoreToSharedResult {
50
71
  * Analysis metadata.
51
72
  */
52
73
  metadata: {
74
+ /** Duration of the analysis in milliseconds. */
53
75
  duration: number;
76
+ /** Root path of the analyzed project. */
54
77
  projectRoot: string;
78
+ /** Whether the impact assessment ran. */
55
79
  impactAssessmentEnabled: boolean;
56
80
  };
57
81
  }
58
82
  /**
59
- * Analyze Core-to-Shared Tool
60
- *
61
- * Provides core-to-shared dependency analysis with impact assessment through MCP.
62
- * Detects architectural violations where core layer imports from shared layer.
83
+ * MCP tool `analyze-core-to-shared`: finds imports from the shared layer in
84
+ * core files, with an optional impact assessment (reverse dependencies,
85
+ * breaking change risk), and suggests a refactoring.
63
86
  */
64
87
  export declare class AnalyzeCoreToSharedTool implements MCPTool {
65
88
  readonly name = "analyze-core-to-shared";
66
89
  readonly title = "Analyze Core-to-Shared Candidates";
67
90
  readonly annotations: ToolAnnotations;
68
91
  readonly description: string;
92
+ /**
93
+ * JSON Schema of the tool arguments.
94
+ * @hidden
95
+ */
69
96
  readonly inputSchema: {
70
97
  type: string;
71
98
  additionalProperties: boolean;
@@ -116,6 +143,10 @@ export declare class AnalyzeCoreToSharedTool implements MCPTool {
116
143
  };
117
144
  required: string[];
118
145
  };
146
+ /**
147
+ * JSON Schema of the tool result (`structuredContent`).
148
+ * @hidden
149
+ */
119
150
  readonly outputSchema: {
120
151
  type: string;
121
152
  properties: {
@@ -289,5 +320,4 @@ export declare class AnalyzeCoreToSharedTool implements MCPTool {
289
320
  */
290
321
  private escapeRegExp;
291
322
  }
292
- export {};
293
323
  //# sourceMappingURL=analyze-core-to-shared.d.ts.map
@@ -1,9 +1,3 @@
1
- /**
2
- * @angular-modernizer/adapter-mcp - Analyze Core-to-Shared Tool
3
- *
4
- * MCP tool for analyzing core-to-shared dependency violations with impact assessment.
5
- * Detects when core layer imports from shared layer and provides detailed refactoring guidance.
6
- */
7
1
  import { findTsConfig } from './helpers/find-ts-config.js';
8
2
  import { Kernel } from '@angular-modernizer/core';
9
3
  import { glob } from 'glob';
@@ -44,10 +38,9 @@ function describeCoreToShared(violations, counts, maxFilesReached) {
44
38
  return lines.join('\n');
45
39
  }
46
40
  /**
47
- * Analyze Core-to-Shared Tool
48
- *
49
- * Provides core-to-shared dependency analysis with impact assessment through MCP.
50
- * Detects architectural violations where core layer imports from shared layer.
41
+ * MCP tool `analyze-core-to-shared`: finds imports from the shared layer in
42
+ * core files, with an optional impact assessment (reverse dependencies,
43
+ * breaking change risk), and suggests a refactoring.
51
44
  */
52
45
  export class AnalyzeCoreToSharedTool {
53
46
  name = 'analyze-core-to-shared';
@@ -60,6 +53,10 @@ export class AnalyzeCoreToSharedTool {
60
53
  };
61
54
  description = 'Analyze core-to-shared dependency violations with impact assessment. counts cover all violations, ' +
62
55
  'summary is a short text with the most imported shared modules and the first violations.';
56
+ /**
57
+ * JSON Schema of the tool arguments.
58
+ * @hidden
59
+ */
63
60
  inputSchema = {
64
61
  type: 'object',
65
62
  additionalProperties: false,
@@ -110,6 +107,10 @@ export class AnalyzeCoreToSharedTool {
110
107
  },
111
108
  required: ['rootPath'],
112
109
  };
110
+ /**
111
+ * JSON Schema of the tool result (`structuredContent`).
112
+ * @hidden
113
+ */
113
114
  outputSchema = {
114
115
  type: 'object',
115
116
  properties: {