@angular-modernizer/adapter-mcp 1.2.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +688 -0
- package/README.md +84 -445
- package/dist/cli.js +9 -1
- package/dist/core/project-analyzer.js +2 -2
- package/dist/index.d.ts +10 -0
- package/dist/index.js +1 -0
- package/dist/scan-host/scan-host.d.ts +7 -0
- package/dist/scan-host/scan-host.js +73 -10
- package/dist/scan-host/scan-protocol.d.ts +2 -0
- package/dist/scan-host/scan-worker.js +14 -8
- package/dist/server/limited-stdio-transport.d.ts +6 -3
- package/dist/server/limited-stdio-transport.js +26 -9
- package/dist/server/mcp-server.js +1 -1
- package/dist/server/sdk-server.d.ts +14 -3
- package/dist/server/sdk-server.js +54 -6
- package/dist/server/tool-registry.d.ts +3 -1
- package/dist/server/tool-registry.js +8 -3
- package/dist/streaming/progress-store.d.ts +19 -7
- package/dist/streaming/progress-store.js +19 -8
- package/dist/tools/analyze-build-impact.d.ts +7 -4
- package/dist/tools/analyze-build-impact.js +8 -3
- package/dist/tools/analyze-core-to-shared.d.ts +10 -6
- package/dist/tools/analyze-core-to-shared.js +63 -60
- package/dist/tools/analyze-parser-performance.d.ts +57 -13
- package/dist/tools/analyze-parser-performance.js +67 -6
- package/dist/tools/analyze-project.d.ts +55 -4
- package/dist/tools/analyze-project.js +104 -15
- package/dist/tools/check-incremental-compatibility.d.ts +30 -41
- package/dist/tools/check-incremental-compatibility.js +32 -264
- package/dist/tools/collect-feedback.js +15 -2
- package/dist/tools/compare-health.d.ts +40 -4
- package/dist/tools/compare-health.js +22 -5
- package/dist/tools/extract-libraries.js +42 -27
- package/dist/tools/find-angular-symbol.js +3 -2
- package/dist/tools/find-component-hosts.js +3 -2
- package/dist/tools/find-usages.js +21 -12
- package/dist/tools/get-call-graph.js +15 -2
- package/dist/tools/get-operation-progress-tool.d.ts +1 -1
- package/dist/tools/get-operation-progress-tool.js +2 -2
- package/dist/tools/get-operation-progress.d.ts +4 -1
- package/dist/tools/get-operation-progress.js +6 -2
- package/dist/tools/helpers/analysis-output.d.ts +32 -1
- package/dist/tools/helpers/analysis-output.js +25 -1
- package/dist/tools/helpers/build-cache.d.ts +27 -0
- package/dist/tools/helpers/build-cache.js +86 -0
- package/dist/tools/helpers/class-filter.d.ts +18 -0
- package/dist/tools/helpers/class-filter.js +30 -0
- package/dist/tools/helpers/cli-arguments.d.ts +23 -0
- package/dist/tools/helpers/cli-arguments.js +35 -0
- package/dist/tools/helpers/feedback-catalog.d.ts +38 -0
- package/dist/tools/helpers/feedback-catalog.js +196 -0
- package/dist/tools/helpers/feedback-sidecar.d.ts +201 -0
- package/dist/tools/helpers/feedback-sidecar.js +381 -0
- package/dist/tools/helpers/file-type-check.d.ts +34 -0
- package/dist/tools/helpers/file-type-check.js +56 -0
- package/dist/tools/helpers/health-delta.d.ts +6 -0
- package/dist/tools/helpers/health-delta.js +4 -1
- package/dist/tools/helpers/library-import-warning.d.ts +33 -0
- package/dist/tools/helpers/library-import-warning.js +38 -0
- package/dist/tools/helpers/library-imports.d.ts +38 -14
- package/dist/tools/helpers/library-imports.js +128 -23
- package/dist/tools/helpers/output-contract.d.ts +64 -0
- package/dist/tools/helpers/output-contract.js +67 -0
- package/dist/tools/helpers/pattern-anonymizer.d.ts +27 -0
- package/dist/tools/helpers/pattern-anonymizer.js +159 -0
- package/dist/tools/helpers/project-cache.d.ts +5 -4
- package/dist/tools/helpers/project-cache.js +21 -16
- package/dist/tools/helpers/project-decorators.d.ts +11 -4
- package/dist/tools/helpers/project-decorators.js +13 -6
- package/dist/tools/helpers/refresh-apply.d.ts +94 -0
- package/dist/tools/helpers/refresh-apply.js +460 -0
- package/dist/tools/helpers/refresh-inventory.d.ts +106 -0
- package/dist/tools/helpers/refresh-inventory.js +631 -0
- package/dist/tools/helpers/rule-runner.js +3 -1
- package/dist/tools/helpers/scan-cache.d.ts +117 -5
- package/dist/tools/helpers/scan-cache.js +179 -6
- package/dist/tools/helpers/scan-engine.d.ts +43 -6
- package/dist/tools/helpers/scan-engine.js +141 -22
- package/dist/tools/helpers/scan-plan.js +16 -2
- package/dist/tools/helpers/source-map-loader.d.ts +55 -0
- package/dist/tools/helpers/source-map-loader.js +226 -0
- package/dist/tools/helpers/template-check.d.ts +76 -0
- package/dist/tools/helpers/template-check.js +158 -0
- package/dist/tools/helpers/tool-cache.d.ts +7 -2
- package/dist/tools/helpers/tool-cache.js +9 -3
- package/dist/tools/helpers/tool-context.d.ts +18 -0
- package/dist/tools/helpers/tool-context.js +29 -0
- package/dist/tools/helpers/transform-safety.d.ts +151 -1
- package/dist/tools/helpers/transform-safety.js +357 -4
- package/dist/tools/inspect-form-group.js +5 -0
- package/dist/tools/inspect-i18n.d.ts +1 -1
- package/dist/tools/inspect-template.js +8 -2
- package/dist/tools/learn-patterns.d.ts +43 -28
- package/dist/tools/learn-patterns.js +83 -161
- package/dist/tools/list-imports.d.ts +1 -1
- package/dist/tools/orchestrate-migration.d.ts +19 -1
- package/dist/tools/orchestrate-migration.js +52 -10
- package/dist/tools/parse-stack-trace.d.ts +48 -1
- package/dist/tools/parse-stack-trace.js +108 -9
- package/dist/tools/plan-migration.js +22 -10
- package/dist/tools/refresh-state.d.ts +378 -0
- package/dist/tools/refresh-state.js +370 -0
- package/dist/tools/resolve-type.js +10 -3
- package/dist/tools/review-feedback.d.ts +42 -7
- package/dist/tools/review-feedback.js +24 -17
- package/dist/tools/rollback-changes.d.ts +5 -0
- package/dist/tools/rollback-changes.js +7 -2
- package/dist/tools/run-angular-cli.js +36 -22
- package/dist/tools/run-build.d.ts +33 -28
- package/dist/tools/run-build.js +136 -438
- package/dist/tools/run-schematic.d.ts +8 -2
- package/dist/tools/run-schematic.js +80 -50
- package/dist/tools/scan-all.d.ts +37 -15
- package/dist/tools/scan-all.js +76 -115
- package/dist/tools/scan-angular.d.ts +33 -14
- package/dist/tools/scan-angular.js +77 -94
- package/dist/tools/scan-architecture.d.ts +37 -12
- package/dist/tools/scan-architecture.js +220 -139
- package/dist/tools/scan-solid.d.ts +33 -14
- package/dist/tools/scan-solid.js +80 -91
- package/dist/tools/search-codebase.d.ts +6 -1
- package/dist/tools/search-codebase.js +13 -7
- package/dist/tools/suggest-improvements.d.ts +34 -3
- package/dist/tools/suggest-improvements.js +34 -9
- package/dist/tools/trace-output-flow.js +3 -2
- package/dist/tools/transform-code-batch.d.ts +9 -9
- package/dist/tools/transform-code.d.ts +161 -12
- package/dist/tools/transform-code.js +715 -206
- package/dist/tools/validate-before-transform.js +2 -1
- package/dist/tools/validate-project-compatibility.d.ts +28 -55
- package/dist/tools/validate-project-compatibility.js +33 -225
- package/dist/tools/validate-transformation.d.ts +40 -26
- package/dist/tools/validate-transformation.js +115 -294
- package/dist/tools/verify-citations.js +8 -2
- package/dist/types.d.ts +9 -9
- package/dist/utils/format-tool-response.d.ts +3 -1
- package/dist/utils/format-tool-response.js +8 -3
- package/package.json +14 -13
|
@@ -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
|
-
|
|
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
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
error
|
|
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: {
|
|
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: [
|
|
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
|
|
101
|
-
const
|
|
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 =
|
|
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
|
-
|
|
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
|
|
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
|
|
236
|
+
lines.push(` ${frame.functionName} → ${location(frame.file, frame)} could be ${(frame.candidates ?? []).join(', ')}`);
|
|
138
237
|
}
|
|
139
238
|
}
|
|
140
239
|
return lines.join('\n');
|
|
@@ -5,6 +5,18 @@ import { STRING_ARRAY } from './helpers/investigation-schemas.js';
|
|
|
5
5
|
import { WARNINGS_OUTPUT_SCHEMA, withWarnings } from './helpers/output-contract.js';
|
|
6
6
|
import { COMPACT_OUTPUT_SCHEMA, limitList, parseCompactOptions, } from './helpers/compact-output.js';
|
|
7
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
|
+
}
|
|
8
20
|
/**
|
|
9
21
|
* Default list cap for the scan-based plan: the full plan for a large project
|
|
10
22
|
* (e.g. 21k violations in 534 files) exceeds the 4 MB response limit.
|
|
@@ -604,9 +616,9 @@ export class PlanMigrationTool {
|
|
|
604
616
|
// Check for DI pattern conflicts
|
|
605
617
|
if (step.action.includes('inject') ||
|
|
606
618
|
step.action.includes('dependency-injection')) {
|
|
607
|
-
if (styleProfile
|
|
619
|
+
if (constructorInjectionRatio(styleProfile) > 0.7) {
|
|
608
620
|
score -= 0.3;
|
|
609
|
-
warnings.push(`Codebase uses constructor injection (${Math.round(styleProfile
|
|
621
|
+
warnings.push(`Codebase uses constructor injection (${Math.round(constructorInjectionRatio(styleProfile) * 100)}%)`);
|
|
610
622
|
conflictReason = 'DI pattern mismatch';
|
|
611
623
|
recommendation =
|
|
612
624
|
'Consider keeping constructor injection or full migration';
|
|
@@ -614,9 +626,9 @@ export class PlanMigrationTool {
|
|
|
614
626
|
}
|
|
615
627
|
// Check for RxJS pattern conflicts
|
|
616
628
|
if (step.action.includes('signal') || step.action.includes('observable')) {
|
|
617
|
-
if (styleProfile
|
|
629
|
+
if (behaviorSubjectRatio(styleProfile) > 0.3) {
|
|
618
630
|
score -= 0.2;
|
|
619
|
-
warnings.push(`Codebase heavily uses BehaviorSubject (${Math.round(styleProfile
|
|
631
|
+
warnings.push(`Codebase heavily uses BehaviorSubject (${Math.round(behaviorSubjectRatio(styleProfile) * 100)}%)`);
|
|
620
632
|
conflictReason = conflictReason ?? 'RxJS pattern mismatch';
|
|
621
633
|
recommendation =
|
|
622
634
|
recommendation ?? 'Consider incremental Signal adoption';
|
|
@@ -723,10 +735,10 @@ export class PlanMigrationTool {
|
|
|
723
735
|
}
|
|
724
736
|
// Generate style recommendations
|
|
725
737
|
const styleRecommendations = [];
|
|
726
|
-
if (styleProfile
|
|
738
|
+
if (constructorInjectionRatio(styleProfile) > 0.6) {
|
|
727
739
|
styleRecommendations.push('Consider keeping constructor injection for consistency');
|
|
728
740
|
}
|
|
729
|
-
if (styleProfile
|
|
741
|
+
if (behaviorSubjectRatio(styleProfile) > 0.3) {
|
|
730
742
|
styleRecommendations.push('BehaviorSubjects are prevalent - plan incremental Signal migration');
|
|
731
743
|
}
|
|
732
744
|
// Generate mitigations
|
|
@@ -770,10 +782,10 @@ export class PlanMigrationTool {
|
|
|
770
782
|
const recommendations = [];
|
|
771
783
|
// DI recommendations
|
|
772
784
|
const diSteps = strategies.flatMap((s) => s.steps.filter((step) => step.action.includes('inject') || step.action.includes('dependency')));
|
|
773
|
-
if (diSteps.length > 0 && styleProfile
|
|
785
|
+
if (diSteps.length > 0 && constructorInjectionRatio(styleProfile) > 0.6) {
|
|
774
786
|
recommendations.push({
|
|
775
787
|
category: 'di',
|
|
776
|
-
currentStyle: `Constructor injection (${Math.round(styleProfile
|
|
788
|
+
currentStyle: `Constructor injection (${Math.round(constructorInjectionRatio(styleProfile) * 100)}%)`,
|
|
777
789
|
recommendation: 'Consider keeping constructor injection for consistency, or plan full migration to inject()',
|
|
778
790
|
reasoning: 'Mixing DI patterns can confuse developers and make the codebase harder to maintain',
|
|
779
791
|
affectedSteps: diSteps.map((s) => s.name),
|
|
@@ -783,10 +795,10 @@ export class PlanMigrationTool {
|
|
|
783
795
|
const rxjsSteps = strategies.flatMap((s) => s.steps.filter((step) => step.action.includes('signal') ||
|
|
784
796
|
step.action.includes('observable') ||
|
|
785
797
|
step.action.includes('rxjs')));
|
|
786
|
-
if (rxjsSteps.length > 0 && styleProfile
|
|
798
|
+
if (rxjsSteps.length > 0 && behaviorSubjectRatio(styleProfile) > 0.3) {
|
|
787
799
|
recommendations.push({
|
|
788
800
|
category: 'rxjs',
|
|
789
|
-
currentStyle: `BehaviorSubject usage (${Math.round(styleProfile
|
|
801
|
+
currentStyle: `BehaviorSubject usage (${Math.round(behaviorSubjectRatio(styleProfile) * 100)}%)`,
|
|
790
802
|
recommendation: 'Consider incremental Signal adoption, keeping BehaviorSubjects for complex async scenarios',
|
|
791
803
|
reasoning: 'BehaviorSubjects provide features like multicasting that Signals handle differently',
|
|
792
804
|
affectedSteps: rxjsSteps.map((s) => s.name),
|