@angular-modernizer/adapter-mcp 1.1.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/CHANGELOG.md +662 -0
  2. package/README.md +86 -445
  3. package/dist/cli.js +9 -1
  4. package/dist/core/project-analyzer.js +2 -2
  5. package/dist/index.d.ts +10 -1
  6. package/dist/index.js +1 -0
  7. package/dist/scan-host/scan-host.d.ts +7 -0
  8. package/dist/scan-host/scan-host.js +73 -10
  9. package/dist/scan-host/scan-protocol.d.ts +2 -0
  10. package/dist/scan-host/scan-worker.js +14 -8
  11. package/dist/server/limited-stdio-transport.d.ts +6 -3
  12. package/dist/server/limited-stdio-transport.js +26 -9
  13. package/dist/server/mcp-server.js +1 -1
  14. package/dist/server/sdk-server.d.ts +14 -3
  15. package/dist/server/sdk-server.js +54 -6
  16. package/dist/server/tool-registry.d.ts +3 -1
  17. package/dist/server/tool-registry.js +8 -3
  18. package/dist/streaming/progress-store.d.ts +19 -7
  19. package/dist/streaming/progress-store.js +19 -8
  20. package/dist/tools/analyze-build-impact.d.ts +9 -6
  21. package/dist/tools/analyze-build-impact.js +14 -7
  22. package/dist/tools/analyze-core-to-shared.d.ts +10 -6
  23. package/dist/tools/analyze-core-to-shared.js +63 -60
  24. package/dist/tools/analyze-parser-performance.d.ts +57 -13
  25. package/dist/tools/analyze-parser-performance.js +67 -6
  26. package/dist/tools/analyze-project.d.ts +35 -6
  27. package/dist/tools/analyze-project.js +141 -36
  28. package/dist/tools/check-incremental-compatibility.d.ts +30 -41
  29. package/dist/tools/check-incremental-compatibility.js +32 -264
  30. package/dist/tools/collect-feedback.js +15 -2
  31. package/dist/tools/extract-libraries.js +42 -27
  32. package/dist/tools/find-angular-symbol.d.ts +2 -2
  33. package/dist/tools/find-angular-symbol.js +6 -5
  34. package/dist/tools/find-component-hosts.d.ts +2 -2
  35. package/dist/tools/find-component-hosts.js +6 -5
  36. package/dist/tools/find-usages.d.ts +2 -2
  37. package/dist/tools/find-usages.js +24 -15
  38. package/dist/tools/get-bootstrap-execution.d.ts +2 -2
  39. package/dist/tools/get-bootstrap-execution.js +3 -3
  40. package/dist/tools/get-call-graph.d.ts +2 -2
  41. package/dist/tools/get-call-graph.js +18 -5
  42. package/dist/tools/get-operation-progress-tool.d.ts +1 -1
  43. package/dist/tools/get-operation-progress-tool.js +2 -2
  44. package/dist/tools/get-operation-progress.d.ts +4 -1
  45. package/dist/tools/get-operation-progress.js +6 -2
  46. package/dist/tools/helpers/analysis-output.d.ts +32 -1
  47. package/dist/tools/helpers/analysis-output.js +22 -1
  48. package/dist/tools/helpers/build-cache.d.ts +27 -0
  49. package/dist/tools/helpers/build-cache.js +86 -0
  50. package/dist/tools/helpers/class-filter.d.ts +18 -0
  51. package/dist/tools/helpers/class-filter.js +30 -0
  52. package/dist/tools/helpers/cli-arguments.d.ts +23 -0
  53. package/dist/tools/helpers/cli-arguments.js +35 -0
  54. package/dist/tools/helpers/feedback-catalog.d.ts +38 -0
  55. package/dist/tools/helpers/feedback-catalog.js +196 -0
  56. package/dist/tools/helpers/feedback-sidecar.d.ts +201 -0
  57. package/dist/tools/helpers/feedback-sidecar.js +381 -0
  58. package/dist/tools/helpers/file-type-check.d.ts +34 -0
  59. package/dist/tools/helpers/file-type-check.js +56 -0
  60. package/dist/tools/helpers/output-contract.d.ts +42 -0
  61. package/dist/tools/helpers/output-contract.js +54 -0
  62. package/dist/tools/helpers/pattern-anonymizer.d.ts +27 -0
  63. package/dist/tools/helpers/pattern-anonymizer.js +159 -0
  64. package/dist/tools/helpers/project-cache.d.ts +78 -6
  65. package/dist/tools/helpers/project-cache.js +205 -15
  66. package/dist/tools/helpers/project-decorators.d.ts +11 -4
  67. package/dist/tools/helpers/project-decorators.js +13 -6
  68. package/dist/tools/helpers/refresh-apply.d.ts +94 -0
  69. package/dist/tools/helpers/refresh-apply.js +460 -0
  70. package/dist/tools/helpers/refresh-inventory.d.ts +106 -0
  71. package/dist/tools/helpers/refresh-inventory.js +610 -0
  72. package/dist/tools/helpers/rule-runner.js +3 -1
  73. package/dist/tools/helpers/scan-cache.d.ts +74 -5
  74. package/dist/tools/helpers/scan-cache.js +134 -6
  75. package/dist/tools/helpers/scan-engine.d.ts +30 -6
  76. package/dist/tools/helpers/scan-engine.js +131 -22
  77. package/dist/tools/helpers/scan-plan.d.ts +1 -1
  78. package/dist/tools/helpers/scan-plan.js +16 -2
  79. package/dist/tools/helpers/source-map-loader.d.ts +55 -0
  80. package/dist/tools/helpers/source-map-loader.js +226 -0
  81. package/dist/tools/helpers/template-check.d.ts +76 -0
  82. package/dist/tools/helpers/template-check.js +158 -0
  83. package/dist/tools/helpers/tool-cache.d.ts +7 -2
  84. package/dist/tools/helpers/tool-cache.js +9 -3
  85. package/dist/tools/helpers/tool-context.d.ts +18 -0
  86. package/dist/tools/helpers/tool-context.js +29 -0
  87. package/dist/tools/helpers/transform-safety.d.ts +151 -1
  88. package/dist/tools/helpers/transform-safety.js +357 -4
  89. package/dist/tools/inspect-form-group.d.ts +2 -2
  90. package/dist/tools/inspect-form-group.js +8 -3
  91. package/dist/tools/inspect-i18n.d.ts +2 -2
  92. package/dist/tools/inspect-i18n.js +3 -3
  93. package/dist/tools/inspect-template.d.ts +2 -2
  94. package/dist/tools/inspect-template.js +11 -5
  95. package/dist/tools/learn-patterns.d.ts +43 -28
  96. package/dist/tools/learn-patterns.js +83 -161
  97. package/dist/tools/list-imports.d.ts +2 -2
  98. package/dist/tools/list-imports.js +3 -3
  99. package/dist/tools/orchestrate-migration.d.ts +19 -1
  100. package/dist/tools/orchestrate-migration.js +52 -10
  101. package/dist/tools/parse-stack-trace.d.ts +48 -1
  102. package/dist/tools/parse-stack-trace.js +108 -9
  103. package/dist/tools/plan-migration.d.ts +2 -2
  104. package/dist/tools/plan-migration.js +25 -12
  105. package/dist/tools/refresh-state.d.ts +378 -0
  106. package/dist/tools/refresh-state.js +370 -0
  107. package/dist/tools/resolve-type.d.ts +2 -2
  108. package/dist/tools/resolve-type.js +13 -6
  109. package/dist/tools/review-feedback.d.ts +42 -7
  110. package/dist/tools/review-feedback.js +24 -17
  111. package/dist/tools/rollback-changes.d.ts +5 -0
  112. package/dist/tools/rollback-changes.js +7 -2
  113. package/dist/tools/run-angular-cli.js +36 -22
  114. package/dist/tools/run-build.d.ts +33 -28
  115. package/dist/tools/run-build.js +136 -438
  116. package/dist/tools/run-schematic.d.ts +8 -2
  117. package/dist/tools/run-schematic.js +80 -50
  118. package/dist/tools/scan-all.d.ts +31 -15
  119. package/dist/tools/scan-all.js +75 -109
  120. package/dist/tools/scan-angular.d.ts +27 -14
  121. package/dist/tools/scan-angular.js +70 -92
  122. package/dist/tools/scan-architecture.d.ts +29 -12
  123. package/dist/tools/scan-architecture.js +205 -135
  124. package/dist/tools/scan-solid.d.ts +27 -14
  125. package/dist/tools/scan-solid.js +73 -89
  126. package/dist/tools/search-codebase.d.ts +8 -3
  127. package/dist/tools/search-codebase.js +16 -10
  128. package/dist/tools/suggest-improvements.d.ts +34 -3
  129. package/dist/tools/suggest-improvements.js +34 -9
  130. package/dist/tools/trace-output-flow.d.ts +2 -2
  131. package/dist/tools/trace-output-flow.js +6 -5
  132. package/dist/tools/transform-code-batch.d.ts +9 -9
  133. package/dist/tools/transform-code.d.ts +161 -12
  134. package/dist/tools/transform-code.js +782 -197
  135. package/dist/tools/validate-before-transform.js +2 -1
  136. package/dist/tools/validate-project-compatibility.d.ts +28 -55
  137. package/dist/tools/validate-project-compatibility.js +33 -225
  138. package/dist/tools/validate-transformation.d.ts +40 -26
  139. package/dist/tools/validate-transformation.js +115 -294
  140. package/dist/tools/verify-citations.js +8 -2
  141. package/dist/types.d.ts +9 -9
  142. package/dist/utils/format-tool-response.d.ts +3 -1
  143. package/dist/utils/format-tool-response.js +8 -3
  144. package/package.json +14 -13
@@ -32,14 +32,23 @@ export interface OrchestrateMigrationResult {
32
32
  stepResults: {
33
33
  /** Step id from the workflow definition. */
34
34
  stepId: string;
35
- /** Step name (the step id). */
35
+ /** Step name from the workflow definition. */
36
36
  name: string;
37
+ /** Tool the step called. */
38
+ tool?: string;
37
39
  /** Step status reported by the workflow engine. */
38
40
  status: string;
39
41
  /** Duration of the step in milliseconds. */
40
42
  durationMs: number;
41
43
  /** Error message of a failed step. */
42
44
  error?: string;
45
+ /**
46
+ * Whether the tool reported success (`false` for `success: false` or
47
+ * `status: 'failed'`); absent when the tool did not answer.
48
+ */
49
+ toolSuccess?: boolean;
50
+ /** The tool's own summary of the step. */
51
+ toolSummary?: string;
43
52
  }[];
44
53
  /**
45
54
  * Checkpoints created during execution
@@ -245,6 +254,9 @@ export declare class OrchestrateMigrationTool implements MCPTool {
245
254
  name: {
246
255
  type: string;
247
256
  };
257
+ tool: {
258
+ type: string;
259
+ };
248
260
  status: {
249
261
  type: string;
250
262
  };
@@ -254,6 +266,12 @@ export declare class OrchestrateMigrationTool implements MCPTool {
254
266
  error: {
255
267
  type: string;
256
268
  };
269
+ toolSuccess: {
270
+ type: string;
271
+ };
272
+ toolSummary: {
273
+ type: string;
274
+ };
257
275
  };
258
276
  required: string[];
259
277
  };
@@ -1,4 +1,5 @@
1
1
  import { yieldIfCancellable } from './helpers/tool-context.js';
2
+ import { reportsFailure } from '../utils/format-tool-response.js';
2
3
  import { WorkflowEngine, } from '@angular-modernizer/orchestration';
3
4
  /** Errors spelled out in the summary; the rest is in `errors`. */
4
5
  const SUMMARY_ERRORS = 5;
@@ -53,9 +54,36 @@ class MCPToolExecutor {
53
54
  if (this.signal?.aborted === true) {
54
55
  throw new Error('Workflow cancelled by the client');
55
56
  }
56
- return tool.execute(args, this.signal === undefined ? {} : { signal: this.signal });
57
+ const result = await tool.execute(args, this.signal === undefined ? {} : { signal: this.signal });
58
+ // A tool that reports its own failure fails the step like a thrown
59
+ // error, so dependent steps do not run on a rolled-back change
60
+ if (typeof result === 'object' && result !== null && reportsFailure(result)) {
61
+ throw new StepToolFailure(toolName, result);
62
+ }
63
+ return result;
64
+ }
65
+ }
66
+ /** A step's tool answered, but reported a failure (`success: false`, `status: 'failed'`). */
67
+ class StepToolFailure extends Error {
68
+ toolResult;
69
+ constructor(toolName, toolResult) {
70
+ super(`${toolName} reported a failure: ${summaryOf(toolResult) ?? 'no summary'}`);
71
+ this.toolResult = toolResult;
57
72
  }
58
73
  }
74
+ /** Whether a tool result reports success; `undefined` when there is no result. */
75
+ function toolSucceeded(result) {
76
+ return typeof result === 'object' && result !== null ? !reportsFailure(result) : undefined;
77
+ }
78
+ /** The `summary` text of a tool result, if it has one. */
79
+ function summaryOf(result) {
80
+ return typeof result === 'object' &&
81
+ result !== null &&
82
+ 'summary' in result &&
83
+ typeof result.summary === 'string'
84
+ ? result.summary
85
+ : undefined;
86
+ }
59
87
  /**
60
88
  * MCP tool for executing multi-step migration workflows with dependency
61
89
  * management, checkpoint/resume, and rollback support. Steps call the other
@@ -179,9 +207,12 @@ export class OrchestrateMigrationTool {
179
207
  properties: {
180
208
  stepId: { type: 'string' },
181
209
  name: { type: 'string' },
210
+ tool: { type: 'string' },
182
211
  status: { type: 'string' },
183
212
  durationMs: { type: 'number' },
184
213
  error: { type: 'string' },
214
+ toolSuccess: { type: 'boolean' },
215
+ toolSummary: { type: 'string' },
185
216
  },
186
217
  required: ['stepId', 'name', 'status', 'durationMs'],
187
218
  },
@@ -279,7 +310,7 @@ export class OrchestrateMigrationTool {
279
310
  },
280
311
  });
281
312
  // Build response
282
- return this.buildResult(result, dryRun);
313
+ return this.buildResult(result, dryRun, workflow);
283
314
  }
284
315
  catch (error) {
285
316
  return {
@@ -331,14 +362,25 @@ export class OrchestrateMigrationTool {
331
362
  /**
332
363
  * Build result from workflow execution
333
364
  */
334
- buildResult(result, dryRun) {
335
- const stepResults = result.stepResults.map((sr) => ({
336
- stepId: sr.stepId,
337
- name: sr.stepId,
338
- status: sr.status,
339
- durationMs: sr.metrics.durationMs,
340
- error: sr.error?.message,
341
- }));
365
+ buildResult(result, dryRun, workflow) {
366
+ const steps = new Map(workflow.steps.map((step) => [step.id, step]));
367
+ const stepResults = result.stepResults.map((sr) => {
368
+ const step = steps.get(sr.stepId);
369
+ // The tool's answer: the result of a completed step, or the failure
370
+ // a tool reported
371
+ const answer = sr.result ?? (sr.error instanceof StepToolFailure ? sr.error.toolResult : undefined);
372
+ const toolSuccess = dryRun ? undefined : toolSucceeded(answer);
373
+ return {
374
+ stepId: sr.stepId,
375
+ name: step?.name ?? sr.stepId,
376
+ tool: step?.tool,
377
+ status: sr.status,
378
+ durationMs: sr.metrics.durationMs,
379
+ error: sr.error?.message,
380
+ toolSuccess,
381
+ toolSummary: summaryOf(answer),
382
+ };
383
+ });
342
384
  const checkpoints = result.stepResults
343
385
  .filter((sr) => sr.stepId.includes('checkpoint'))
344
386
  .map((sr) => ({
@@ -1,5 +1,6 @@
1
1
  import { type MCPTool, type ToolAnnotations } from '../types.js';
2
2
  import { type StackFrame, type StackFrameFileIndex } from '@angular-modernizer/api';
3
+ import { type SourceMapFetcher, type SourceMapOrigin } from './helpers/source-map-loader.js';
3
4
  /**
4
5
  * Output of the parse-stack-trace tool.
5
6
  */
@@ -10,6 +11,13 @@ export interface ParseStackTraceOutput {
10
11
  projectFrameCount: number;
11
12
  /** Total number of frames found before any filtering. */
12
13
  totalFrameCount: number;
14
+ /**
15
+ * Number of lines that look like stack frames but have no file location
16
+ * (`at Array.forEach (<anonymous>)`). They are named in `summary`.
17
+ */
18
+ skippedLines: number;
19
+ /** Per bundle frame file (`main.js`), where its source map came from or why none was used. */
20
+ sourceMaps: SourceMapOrigin[];
13
21
  /** Human-readable summary for LLM consumption. */
14
22
  summary: string;
15
23
  }
@@ -31,10 +39,11 @@ export interface ParseStackTraceOutput {
31
39
  */
32
40
  export declare class ParseStackTraceTool implements MCPTool {
33
41
  private readonly createFileIndex;
42
+ private readonly fetchText;
34
43
  readonly name = "parse-stack-trace";
35
44
  readonly title = "Parse Stack Trace";
36
45
  readonly annotations: ToolAnnotations;
37
- constructor(createFileIndex?: (projectRoot: string) => StackFrameFileIndex);
46
+ constructor(createFileIndex?: (projectRoot: string) => StackFrameFileIndex, fetchText?: SourceMapFetcher);
38
47
  readonly description: string;
39
48
  /**
40
49
  * JSON Schema of the tool arguments.
@@ -57,6 +66,11 @@ export declare class ParseStackTraceTool implements MCPTool {
57
66
  description: string;
58
67
  default: boolean;
59
68
  };
69
+ fetchSourceMaps: {
70
+ type: string;
71
+ description: string;
72
+ default: boolean;
73
+ };
60
74
  };
61
75
  required: string[];
62
76
  };
@@ -94,6 +108,12 @@ export declare class ParseStackTraceTool implements MCPTool {
94
108
  type: string;
95
109
  enum: string[];
96
110
  };
111
+ generatedLine: {
112
+ type: string;
113
+ };
114
+ generatedCol: {
115
+ type: string;
116
+ };
97
117
  candidates: {
98
118
  type: string;
99
119
  items: {
@@ -110,6 +130,31 @@ export declare class ParseStackTraceTool implements MCPTool {
110
130
  totalFrameCount: {
111
131
  type: string;
112
132
  };
133
+ skippedLines: {
134
+ type: string;
135
+ };
136
+ sourceMaps: {
137
+ type: string;
138
+ items: {
139
+ type: string;
140
+ properties: {
141
+ bundle: {
142
+ type: string;
143
+ };
144
+ map: {
145
+ type: string;
146
+ };
147
+ from: {
148
+ type: string;
149
+ enum: string[];
150
+ };
151
+ reason: {
152
+ type: string;
153
+ };
154
+ };
155
+ required: string[];
156
+ };
157
+ };
113
158
  summary: {
114
159
  type: string;
115
160
  };
@@ -117,6 +162,8 @@ export declare class ParseStackTraceTool implements MCPTool {
117
162
  required: string[];
118
163
  };
119
164
  execute(args: Record<string, unknown>): Promise<ParseStackTraceOutput>;
165
+ private sourceMapSummary;
166
+ private skippedSummary;
120
167
  private buildSummary;
121
168
  }
122
169
  //# sourceMappingURL=parse-stack-trace.d.ts.map
@@ -1,5 +1,23 @@
1
1
  import { StackTraceParser, } from '@angular-modernizer/api';
2
2
  import { createNodeStackFrameFileIndex } from './helpers/stack-frame-file-index.js';
3
+ import { fetchLoopbackText, loadSourceMaps, } from './helpers/source-map-loader.js';
4
+ /** Skipped frame lines named in the summary; the rest is only counted. */
5
+ const MAX_SKIPPED_LINES_SHOWN = 5;
6
+ /** `file:line:col`, or `file:line` for a frame without a column (`col` 0). */
7
+ function location(file, frame) {
8
+ return frame.col > 0
9
+ ? `${file}:${frame.line}:${frame.col}`
10
+ : `${file}:${frame.line}`;
11
+ }
12
+ /** ` (main.js:191:31)` for a frame mapped through a source map. */
13
+ function generatedNote(frame) {
14
+ if (frame.resolvedFrom !== 'source-map' || frame.generatedLine === undefined) {
15
+ return '';
16
+ }
17
+ const col = frame.generatedCol ?? 0;
18
+ const position = col > 0 ? `${frame.generatedLine}:${col}` : `${frame.generatedLine}`;
19
+ return ` (from ${frame.file}:${position})`;
20
+ }
3
21
  /**
4
22
  * MCP tool for parsing Node.js/Angular/Zone.js/browser stack traces into structured frames.
5
23
  * Maps each frame to its source file and classifies it as a project file or external dependency.
@@ -18,6 +36,7 @@ import { createNodeStackFrameFileIndex } from './helpers/stack-frame-file-index.
18
36
  */
19
37
  export class ParseStackTraceTool {
20
38
  createFileIndex;
39
+ fetchText;
21
40
  name = 'parse-stack-trace';
22
41
  title = 'Parse Stack Trace';
23
42
  annotations = {
@@ -26,14 +45,20 @@ export class ParseStackTraceTool {
26
45
  idempotentHint: true,
27
46
  openWorldHint: false,
28
47
  };
29
- constructor(createFileIndex = createNodeStackFrameFileIndex) {
48
+ constructor(createFileIndex = createNodeStackFrameFileIndex, fetchText = fetchLoopbackText) {
30
49
  this.createFileIndex = createFileIndex;
50
+ this.fetchText = fetchText;
31
51
  }
32
52
  description = 'Parse a Node.js/Angular/Zone.js/browser stack trace into structured frames. ' +
33
53
  'Maps each frame to its source file, line, column, and function name. ' +
34
54
  'Classifies frames as project files or external dependencies (node_modules). ' +
55
+ 'Reads Chrome/V8 "at" frames and Firefox/Safari "fn@url:line:col" frames. ' +
35
56
  'Browser frames (http://host/src/..., webpack:///, ng:///, bare file names) are mapped ' +
36
57
  'onto project files via resolvedFile; an ambiguous file name lists candidates. ' +
58
+ 'Bundle frames (main.js) are mapped through their source map (resolvedFrom source-map, ' +
59
+ 'original line/col, bundle position in generatedLine/generatedCol): read from disk, else ' +
60
+ 'fetched as <bundle url>.map from a loopback dev server only (localhost, 127.0.0.1, ::1); ' +
61
+ 'fetchSourceMaps false disables the fetch. ' +
37
62
  'Use as the first step in bug investigation when a stack trace is available.';
38
63
  /**
39
64
  * JSON Schema of the tool arguments.
@@ -56,6 +81,15 @@ export class ParseStackTraceTool {
56
81
  description: 'When true, only project frames are returned. Defaults to false.',
57
82
  default: false,
58
83
  },
84
+ fetchSourceMaps: {
85
+ type: 'boolean',
86
+ description: 'Bundle frames (main.js) are mapped through their source map: first from disk ' +
87
+ '(the bundle under projectRoot or dist/<app>/browser, its sourceMappingURL or <bundle>.map), ' +
88
+ 'then by fetching <bundle url>.map from a loopback dev server (localhost, 127.0.0.1, ::1; ' +
89
+ '2 s timeout, one request per bundle; other hosts are never contacted). ' +
90
+ 'false skips the fetch. Defaults to true.',
91
+ default: true,
92
+ },
59
93
  },
60
94
  required: ['stackTrace', 'projectRoot'],
61
95
  };
@@ -77,7 +111,12 @@ export class ParseStackTraceTool {
77
111
  functionName: { type: 'string' },
78
112
  isProjectFile: { type: 'boolean' },
79
113
  resolvedFile: { type: 'string' },
80
- resolvedFrom: { type: 'string', enum: ['url', 'basename'] },
114
+ resolvedFrom: {
115
+ type: 'string',
116
+ enum: ['url', 'basename', 'source-map'],
117
+ },
118
+ generatedLine: { type: 'integer' },
119
+ generatedCol: { type: 'integer' },
81
120
  candidates: { type: 'array', items: { type: 'string' } },
82
121
  },
83
122
  required: ['file', 'line', 'col', 'functionName', 'isProjectFile'],
@@ -85,9 +124,30 @@ export class ParseStackTraceTool {
85
124
  },
86
125
  projectFrameCount: { type: 'integer' },
87
126
  totalFrameCount: { type: 'integer' },
127
+ skippedLines: { type: 'integer' },
128
+ sourceMaps: {
129
+ type: 'array',
130
+ items: {
131
+ type: 'object',
132
+ properties: {
133
+ bundle: { type: 'string' },
134
+ map: { type: 'string' },
135
+ from: { type: 'string', enum: ['disk', 'http'] },
136
+ reason: { type: 'string' },
137
+ },
138
+ required: ['bundle'],
139
+ },
140
+ },
88
141
  summary: { type: 'string' },
89
142
  },
90
- required: ['frames', 'projectFrameCount', 'totalFrameCount', 'summary'],
143
+ required: [
144
+ 'frames',
145
+ 'projectFrameCount',
146
+ 'totalFrameCount',
147
+ 'skippedLines',
148
+ 'sourceMaps',
149
+ 'summary',
150
+ ],
91
151
  };
92
152
  async execute(args) {
93
153
  const params = args;
@@ -97,21 +157,60 @@ export class ParseStackTraceTool {
97
157
  if (!params.projectRoot) {
98
158
  throw new Error('projectRoot is required');
99
159
  }
100
- const parser = new StackTraceParser(params.projectRoot, this.createFileIndex(params.projectRoot));
101
- const allFrames = parser.parse(params.stackTrace);
160
+ const files = this.createFileIndex(params.projectRoot);
161
+ const bundles = new StackTraceParser(params.projectRoot, files).sourceMapBundles(params.stackTrace);
162
+ const { lookup, origins } = await loadSourceMaps(bundles, {
163
+ projectRoot: params.projectRoot,
164
+ fetchSourceMaps: params.fetchSourceMaps !== false,
165
+ fetchText: this.fetchText,
166
+ });
167
+ const parser = new StackTraceParser(params.projectRoot, files, lookup);
168
+ const { frames: allFrames, skippedLines } = parser.parseDetailed(params.stackTrace);
102
169
  const projectFrameCount = allFrames.filter((f) => f.isProjectFile).length;
103
170
  const frames = params.projectFramesOnly === true
104
171
  ? allFrames.filter((f) => f.isProjectFile)
105
172
  : allFrames;
106
- const summary = this.buildSummary(allFrames, projectFrameCount, params.projectRoot);
173
+ const summary = [
174
+ this.buildSummary(allFrames, projectFrameCount, params.projectRoot, skippedLines.length),
175
+ ...this.skippedSummary(skippedLines),
176
+ ...this.sourceMapSummary(origins),
177
+ ].join('\n');
107
178
  return {
108
179
  frames,
109
180
  projectFrameCount,
110
181
  totalFrameCount: allFrames.length,
182
+ skippedLines: skippedLines.length,
183
+ sourceMaps: origins,
111
184
  summary,
112
185
  };
113
186
  }
114
- buildSummary(frames, projectFrameCount, projectRoot) {
187
+ sourceMapSummary(origins) {
188
+ if (origins.length === 0) {
189
+ return [];
190
+ }
191
+ return [
192
+ 'Source maps of bundle frames:',
193
+ ...origins.map((o) => o.map !== undefined
194
+ ? ` ${o.bundle} → ${o.map} (${o.from ?? 'disk'})`
195
+ : ` ${o.bundle}: ${o.reason ?? 'no map'}`),
196
+ ];
197
+ }
198
+ skippedSummary(skippedLines) {
199
+ if (skippedLines.length === 0) {
200
+ return [];
201
+ }
202
+ const shown = skippedLines.slice(0, MAX_SKIPPED_LINES_SHOWN);
203
+ const more = skippedLines.length - shown.length;
204
+ return [
205
+ `${skippedLines.length} line(s) look like stack frames but have no file location and are not in frames:`,
206
+ ...shown.map((line) => ` ${line}`),
207
+ ...(more > 0 ? [` ... and ${more} more`] : []),
208
+ ];
209
+ }
210
+ buildSummary(frames, projectFrameCount, projectRoot, skippedCount) {
211
+ if (frames.length === 0 && skippedCount > 0) {
212
+ return 'No stack frames with a file location found.';
213
+ }
115
214
  if (frames.length === 0) {
116
215
  return 'No stack frames found. The input may not contain a stack trace.';
117
216
  }
@@ -124,7 +223,7 @@ export class ParseStackTraceTool {
124
223
  lines.push(`Project root: ${projectRoot}`);
125
224
  lines.push('Project frames (investigate these):');
126
225
  for (const frame of projectFrames) {
127
- lines.push(` ${frame.functionName} → ${frame.resolvedFile ?? frame.file}:${frame.line}:${frame.col}`);
226
+ lines.push(` ${frame.functionName} → ${location(frame.resolvedFile ?? frame.file, frame)}${generatedNote(frame)}`);
128
227
  }
129
228
  }
130
229
  else {
@@ -134,7 +233,7 @@ export class ParseStackTraceTool {
134
233
  if (ambiguous.length > 0) {
135
234
  lines.push('Ambiguous file names (not counted as project frames):');
136
235
  for (const frame of ambiguous) {
137
- lines.push(` ${frame.functionName} → ${frame.file}:${frame.line}:${frame.col} could be ${(frame.candidates ?? []).join(', ')}`);
236
+ lines.push(` ${frame.functionName} → ${location(frame.file, frame)} could be ${(frame.candidates ?? []).join(', ')}`);
138
237
  }
139
238
  }
140
239
  return lines.join('\n');
@@ -1,4 +1,4 @@
1
- import { type MCPTool, type ToolAnnotations } from '../types.js';
1
+ import { type MCPTool, type ToolAnnotations, type ToolContext } from '../types.js';
2
2
  import { type ProjectCache } from './helpers/project-cache.js';
3
3
  import type { PlannedFile, PlannedPhase, ViolationPlan } from '@angular-modernizer/core';
4
4
  /**
@@ -790,7 +790,7 @@ export declare class PlanMigrationTool implements MCPTool {
790
790
  };
791
791
  required: string[];
792
792
  };
793
- execute(args: Record<string, unknown>): Promise<PlanMigrationResult>;
793
+ execute(args: Record<string, unknown>, ctx?: ToolContext): Promise<PlanMigrationResult>;
794
794
  /**
795
795
  * Inline violations plus the ones from scanResultFile.
796
796
  */
@@ -1,9 +1,22 @@
1
1
  import { isAbsolute, resolve } from 'node:path';
2
+ import { acquireProject } from './helpers/project-cache.js';
2
3
  import { nameList } from './helpers/analysis-output.js';
3
4
  import { STRING_ARRAY } from './helpers/investigation-schemas.js';
4
5
  import { WARNINGS_OUTPUT_SCHEMA, withWarnings } from './helpers/output-contract.js';
5
6
  import { COMPACT_OUTPUT_SCHEMA, limitList, parseCompactOptions, } from './helpers/compact-output.js';
6
7
  import { buildScanPlan, readScanResultFile, } from './helpers/scan-plan.js';
8
+ /** A ratio of the style profile, 0 when it is missing or not a number. */
9
+ function ratioOrZero(value) {
10
+ return typeof value === 'number' && Number.isFinite(value) ? value : 0;
11
+ }
12
+ /** Share of constructor injection, 0 when the profile has no DI ratio. */
13
+ function constructorInjectionRatio(styleProfile) {
14
+ return ratioOrZero(styleProfile.diRatio?.constructor);
15
+ }
16
+ /** Share of BehaviorSubject usage, 0 when the profile has no RxJS ratio. */
17
+ function behaviorSubjectRatio(styleProfile) {
18
+ return ratioOrZero(styleProfile.rxjsRatio?.behaviorSubject);
19
+ }
7
20
  /**
8
21
  * Default list cap for the scan-based plan: the full plan for a large project
9
22
  * (e.g. 21k violations in 534 files) exceeds the 4 MB response limit.
@@ -350,7 +363,7 @@ export class PlanMigrationTool {
350
363
  'summary',
351
364
  ],
352
365
  };
353
- async execute(args) {
366
+ async execute(args, ctx = {}) {
354
367
  const params = args;
355
368
  const compact = parseCompactOptions(args);
356
369
  const projectRoot = typeof params.projectRoot === 'string' ? params.projectRoot : undefined;
@@ -422,7 +435,7 @@ export class PlanMigrationTool {
422
435
  ? {
423
436
  loadProject: (path) => {
424
437
  cachedTsConfig = path;
425
- return projects.get(path);
438
+ return acquireProject(projects, path, ctx);
426
439
  },
427
440
  }
428
441
  : {}),
@@ -603,9 +616,9 @@ export class PlanMigrationTool {
603
616
  // Check for DI pattern conflicts
604
617
  if (step.action.includes('inject') ||
605
618
  step.action.includes('dependency-injection')) {
606
- if (styleProfile.diRatio.constructor > 0.7) {
619
+ if (constructorInjectionRatio(styleProfile) > 0.7) {
607
620
  score -= 0.3;
608
- warnings.push(`Codebase uses constructor injection (${Math.round(styleProfile.diRatio.constructor * 100)}%)`);
621
+ warnings.push(`Codebase uses constructor injection (${Math.round(constructorInjectionRatio(styleProfile) * 100)}%)`);
609
622
  conflictReason = 'DI pattern mismatch';
610
623
  recommendation =
611
624
  'Consider keeping constructor injection or full migration';
@@ -613,9 +626,9 @@ export class PlanMigrationTool {
613
626
  }
614
627
  // Check for RxJS pattern conflicts
615
628
  if (step.action.includes('signal') || step.action.includes('observable')) {
616
- if (styleProfile.rxjsRatio.behaviorSubject > 0.3) {
629
+ if (behaviorSubjectRatio(styleProfile) > 0.3) {
617
630
  score -= 0.2;
618
- warnings.push(`Codebase heavily uses BehaviorSubject (${Math.round(styleProfile.rxjsRatio.behaviorSubject * 100)}%)`);
631
+ warnings.push(`Codebase heavily uses BehaviorSubject (${Math.round(behaviorSubjectRatio(styleProfile) * 100)}%)`);
619
632
  conflictReason = conflictReason ?? 'RxJS pattern mismatch';
620
633
  recommendation =
621
634
  recommendation ?? 'Consider incremental Signal adoption';
@@ -722,10 +735,10 @@ export class PlanMigrationTool {
722
735
  }
723
736
  // Generate style recommendations
724
737
  const styleRecommendations = [];
725
- if (styleProfile.diRatio.constructor > 0.6) {
738
+ if (constructorInjectionRatio(styleProfile) > 0.6) {
726
739
  styleRecommendations.push('Consider keeping constructor injection for consistency');
727
740
  }
728
- if (styleProfile.rxjsRatio.behaviorSubject > 0.3) {
741
+ if (behaviorSubjectRatio(styleProfile) > 0.3) {
729
742
  styleRecommendations.push('BehaviorSubjects are prevalent - plan incremental Signal migration');
730
743
  }
731
744
  // Generate mitigations
@@ -769,10 +782,10 @@ export class PlanMigrationTool {
769
782
  const recommendations = [];
770
783
  // DI recommendations
771
784
  const diSteps = strategies.flatMap((s) => s.steps.filter((step) => step.action.includes('inject') || step.action.includes('dependency')));
772
- if (diSteps.length > 0 && styleProfile.diRatio.constructor > 0.6) {
785
+ if (diSteps.length > 0 && constructorInjectionRatio(styleProfile) > 0.6) {
773
786
  recommendations.push({
774
787
  category: 'di',
775
- currentStyle: `Constructor injection (${Math.round(styleProfile.diRatio.constructor * 100)}%)`,
788
+ currentStyle: `Constructor injection (${Math.round(constructorInjectionRatio(styleProfile) * 100)}%)`,
776
789
  recommendation: 'Consider keeping constructor injection for consistency, or plan full migration to inject()',
777
790
  reasoning: 'Mixing DI patterns can confuse developers and make the codebase harder to maintain',
778
791
  affectedSteps: diSteps.map((s) => s.name),
@@ -782,10 +795,10 @@ export class PlanMigrationTool {
782
795
  const rxjsSteps = strategies.flatMap((s) => s.steps.filter((step) => step.action.includes('signal') ||
783
796
  step.action.includes('observable') ||
784
797
  step.action.includes('rxjs')));
785
- if (rxjsSteps.length > 0 && styleProfile.rxjsRatio.behaviorSubject > 0.3) {
798
+ if (rxjsSteps.length > 0 && behaviorSubjectRatio(styleProfile) > 0.3) {
786
799
  recommendations.push({
787
800
  category: 'rxjs',
788
- currentStyle: `BehaviorSubject usage (${Math.round(styleProfile.rxjsRatio.behaviorSubject * 100)}%)`,
801
+ currentStyle: `BehaviorSubject usage (${Math.round(behaviorSubjectRatio(styleProfile) * 100)}%)`,
789
802
  recommendation: 'Consider incremental Signal adoption, keeping BehaviorSubjects for complex async scenarios',
790
803
  reasoning: 'BehaviorSubjects provide features like multicasting that Signals handle differently',
791
804
  affectedSteps: rxjsSteps.map((s) => s.name),