@angular-modernizer/adapter-mcp 0.2.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +188 -235
- package/dist/cli.js +77 -27
- package/dist/index.d.ts +11 -3
- package/dist/index.js +10 -2
- package/dist/mcp-watcher.d.ts +6 -1
- package/dist/mcp-watcher.js +14 -10
- package/dist/server/limited-stdio-transport.d.ts +68 -0
- package/dist/server/limited-stdio-transport.js +115 -0
- package/dist/server/mcp-server.d.ts +41 -12
- package/dist/server/mcp-server.js +113 -94
- package/dist/server/package-version.d.ts +16 -0
- package/dist/server/package-version.js +37 -0
- package/dist/server/sdk-server.d.ts +70 -0
- package/dist/server/sdk-server.js +113 -0
- package/dist/server/stdio-guard.d.ts +20 -0
- package/dist/server/stdio-guard.js +48 -0
- package/dist/server/tool-registry.d.ts +3 -2
- package/dist/server/tool-registry.js +5 -5
- package/dist/tools/analyze-build-impact.d.ts +346 -14
- package/dist/tools/analyze-build-impact.js +315 -31
- package/dist/tools/analyze-core-to-shared.d.ts +134 -4
- package/dist/tools/analyze-core-to-shared.js +113 -9
- package/dist/tools/analyze-parser-performance.d.ts +200 -7
- package/dist/tools/analyze-parser-performance.js +108 -47
- package/dist/tools/analyze-project.d.ts +267 -5
- package/dist/tools/analyze-project.js +196 -8
- package/dist/tools/check-incremental-compatibility.d.ts +61 -1
- package/dist/tools/check-incremental-compatibility.js +58 -2
- package/dist/tools/collect-feedback.d.ts +199 -10
- package/dist/tools/collect-feedback.js +171 -99
- package/dist/tools/compare-health.d.ts +356 -0
- package/dist/tools/compare-health.js +472 -0
- package/dist/tools/extract-libraries.d.ts +156 -4
- package/dist/tools/extract-libraries.js +115 -10
- package/dist/tools/find-angular-symbol.d.ts +98 -9
- package/dist/tools/find-angular-symbol.js +104 -12
- package/dist/tools/find-component-hosts.d.ts +684 -0
- package/dist/tools/find-component-hosts.js +441 -0
- package/dist/tools/find-usages.d.ts +99 -4
- package/dist/tools/find-usages.js +131 -11
- package/dist/tools/get-bootstrap-execution.d.ts +258 -0
- package/dist/tools/get-bootstrap-execution.js +324 -0
- package/dist/tools/get-call-graph.d.ts +139 -4
- package/dist/tools/get-call-graph.js +123 -13
- package/dist/tools/get-operation-progress-tool.d.ts +114 -2
- package/dist/tools/get-operation-progress-tool.js +114 -7
- package/dist/tools/get-operation-progress.d.ts +1 -1
- package/dist/tools/get-operation-progress.js +5 -5
- package/dist/tools/helpers/analysis-output.d.ts +177 -0
- package/dist/tools/helpers/analysis-output.js +165 -0
- package/dist/tools/helpers/build-schemas.d.ts +36 -0
- package/dist/tools/helpers/build-schemas.js +23 -0
- package/dist/tools/helpers/citation-file-source.d.ts +10 -0
- package/dist/tools/helpers/citation-file-source.js +82 -0
- package/dist/tools/helpers/compact-output.d.ts +61 -0
- package/dist/tools/helpers/compact-output.js +83 -0
- package/dist/tools/helpers/finding-window.d.ts +43 -0
- package/dist/tools/helpers/finding-window.js +64 -0
- package/dist/tools/helpers/health-delta.d.ts +86 -0
- package/dist/tools/helpers/health-delta.js +239 -0
- package/dist/tools/helpers/investigation-schemas.d.ts +93 -0
- package/dist/tools/helpers/investigation-schemas.js +48 -0
- package/dist/tools/helpers/library-imports.d.ts +57 -0
- package/dist/tools/helpers/library-imports.js +151 -0
- package/dist/tools/helpers/load-source-files.d.ts +30 -0
- package/dist/tools/helpers/load-source-files.js +34 -0
- package/dist/tools/helpers/output-contract.d.ts +32 -0
- package/dist/tools/helpers/output-contract.js +32 -0
- package/dist/tools/helpers/platform-root-resolver.d.ts +55 -25
- package/dist/tools/helpers/platform-root-resolver.js +75 -48
- package/dist/tools/helpers/process-output.d.ts +19 -0
- package/dist/tools/helpers/process-output.js +31 -0
- package/dist/tools/helpers/project-cache.d.ts +184 -0
- package/dist/tools/helpers/project-cache.js +331 -0
- package/dist/tools/helpers/project-decorators.d.ts +14 -0
- package/dist/tools/helpers/project-decorators.js +22 -0
- package/dist/tools/helpers/rule-matcher.js +5 -0
- package/dist/tools/helpers/rule-runner.d.ts +72 -0
- package/dist/tools/helpers/rule-runner.js +131 -0
- package/dist/tools/helpers/scan-cache.d.ts +22 -0
- package/dist/tools/helpers/scan-cache.js +34 -0
- package/dist/tools/helpers/scan-plan.d.ts +48 -0
- package/dist/tools/helpers/scan-plan.js +166 -0
- package/dist/tools/helpers/scope-paths.d.ts +17 -0
- package/dist/tools/helpers/scope-paths.js +32 -0
- package/dist/tools/helpers/stack-frame-file-index.d.ts +10 -0
- package/dist/tools/helpers/stack-frame-file-index.js +71 -0
- package/dist/tools/helpers/tool-context.d.ts +60 -0
- package/dist/tools/helpers/tool-context.js +82 -0
- package/dist/tools/helpers/transform-safety.d.ts +40 -0
- package/dist/tools/helpers/transform-safety.js +87 -0
- package/dist/tools/helpers/validation-output.d.ts +53 -0
- package/dist/tools/helpers/validation-output.js +48 -0
- package/dist/tools/inspect-form-group.d.ts +324 -0
- package/dist/tools/inspect-form-group.js +279 -0
- package/dist/tools/inspect-i18n.d.ts +466 -0
- package/dist/tools/inspect-i18n.js +400 -0
- package/dist/tools/inspect-template.d.ts +320 -0
- package/dist/tools/inspect-template.js +324 -0
- package/dist/tools/learn-patterns.d.ts +122 -1
- package/dist/tools/learn-patterns.js +97 -2
- package/dist/tools/list-imports.d.ts +128 -11
- package/dist/tools/list-imports.js +128 -8
- package/dist/tools/orchestrate-migration.d.ts +129 -5
- package/dist/tools/orchestrate-migration.js +166 -12
- package/dist/tools/parse-stack-trace.d.ts +59 -2
- package/dist/tools/parse-stack-trace.js +52 -4
- package/dist/tools/plan-migration.d.ts +418 -1
- package/dist/tools/plan-migration.js +355 -8
- package/dist/tools/resolve-type.d.ts +42 -1
- package/dist/tools/resolve-type.js +37 -4
- package/dist/tools/review-feedback.d.ts +206 -11
- package/dist/tools/review-feedback.js +132 -51
- package/dist/tools/rollback-changes.d.ts +79 -2
- package/dist/tools/rollback-changes.js +66 -14
- package/dist/tools/run-angular-cli.d.ts +45 -2
- package/dist/tools/run-angular-cli.js +67 -7
- package/dist/tools/run-build.d.ts +114 -2
- package/dist/tools/run-build.js +117 -8
- package/dist/tools/run-schematic.d.ts +70 -2
- package/dist/tools/run-schematic.js +104 -10
- package/dist/tools/scan-all.d.ts +24 -16
- package/dist/tools/scan-all.js +145 -137
- package/dist/tools/scan-angular.d.ts +20 -11
- package/dist/tools/scan-angular.js +52 -24
- package/dist/tools/scan-architecture.d.ts +42 -14
- package/dist/tools/scan-architecture.js +206 -163
- package/dist/tools/scan-solid.d.ts +20 -11
- package/dist/tools/scan-solid.js +52 -24
- package/dist/tools/search-codebase.d.ts +85 -1
- package/dist/tools/search-codebase.js +61 -4
- package/dist/tools/server-status.d.ts +370 -0
- package/dist/tools/server-status.js +369 -0
- package/dist/tools/suggest-improvements.d.ts +97 -5
- package/dist/tools/suggest-improvements.js +80 -44
- package/dist/tools/trace-output-flow.d.ts +791 -0
- package/dist/tools/trace-output-flow.js +668 -0
- package/dist/tools/transform-code-batch.d.ts +3 -0
- package/dist/tools/transform-code-batch.js +10 -5
- package/dist/tools/transform-code.d.ts +335 -12
- package/dist/tools/transform-code.js +649 -608
- package/dist/tools/validate-before-transform.d.ts +116 -2
- package/dist/tools/validate-before-transform.js +55 -2
- package/dist/tools/validate-project-compatibility.d.ts +64 -2
- package/dist/tools/validate-project-compatibility.js +67 -4
- package/dist/tools/validate-transformation.d.ts +220 -2
- package/dist/tools/validate-transformation.js +113 -15
- package/dist/tools/verify-citations.d.ts +181 -0
- package/dist/tools/verify-citations.js +218 -0
- package/dist/types.d.ts +45 -1
- package/dist/utils/format-tool-response.d.ts +22 -59
- package/dist/utils/format-tool-response.js +25 -134
- package/package.json +30 -13
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/core/project-analyzer.d.ts.map +0 -1
- package/dist/core/project-analyzer.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/mcp-watcher.d.ts.map +0 -1
- package/dist/mcp-watcher.js.map +0 -1
- package/dist/server/json-rpc-handler.d.ts +0 -57
- package/dist/server/json-rpc-handler.d.ts.map +0 -1
- package/dist/server/json-rpc-handler.js +0 -222
- package/dist/server/json-rpc-handler.js.map +0 -1
- package/dist/server/mcp-server.d.ts.map +0 -1
- package/dist/server/mcp-server.js.map +0 -1
- package/dist/server/tool-registry.d.ts.map +0 -1
- package/dist/server/tool-registry.js.map +0 -1
- package/dist/streaming/progress-store.d.ts.map +0 -1
- package/dist/streaming/progress-store.js.map +0 -1
- package/dist/tools/analyze-build-impact.d.ts.map +0 -1
- package/dist/tools/analyze-build-impact.js.map +0 -1
- package/dist/tools/analyze-core-to-shared.d.ts.map +0 -1
- package/dist/tools/analyze-core-to-shared.js.map +0 -1
- package/dist/tools/analyze-parser-performance.d.ts.map +0 -1
- package/dist/tools/analyze-parser-performance.js.map +0 -1
- package/dist/tools/analyze-project.d.ts.map +0 -1
- package/dist/tools/analyze-project.js.map +0 -1
- package/dist/tools/check-incremental-compatibility.d.ts.map +0 -1
- package/dist/tools/check-incremental-compatibility.js.map +0 -1
- package/dist/tools/collect-feedback.d.ts.map +0 -1
- package/dist/tools/collect-feedback.js.map +0 -1
- package/dist/tools/extract-libraries.d.ts.map +0 -1
- package/dist/tools/extract-libraries.js.map +0 -1
- package/dist/tools/find-angular-symbol.d.ts.map +0 -1
- package/dist/tools/find-angular-symbol.js.map +0 -1
- package/dist/tools/find-usages.d.ts.map +0 -1
- package/dist/tools/find-usages.js.map +0 -1
- package/dist/tools/get-call-graph.d.ts.map +0 -1
- package/dist/tools/get-call-graph.js.map +0 -1
- package/dist/tools/get-operation-progress-tool.d.ts.map +0 -1
- package/dist/tools/get-operation-progress-tool.js.map +0 -1
- package/dist/tools/get-operation-progress.d.ts.map +0 -1
- package/dist/tools/get-operation-progress.js.map +0 -1
- package/dist/tools/helpers/feedback-analyzer.d.ts.map +0 -1
- package/dist/tools/helpers/feedback-analyzer.js.map +0 -1
- package/dist/tools/helpers/find-ts-config.d.ts.map +0 -1
- package/dist/tools/helpers/find-ts-config.js.map +0 -1
- package/dist/tools/helpers/platform-root-resolver.d.ts.map +0 -1
- package/dist/tools/helpers/platform-root-resolver.js.map +0 -1
- package/dist/tools/helpers/rule-matcher.d.ts.map +0 -1
- package/dist/tools/helpers/rule-matcher.js.map +0 -1
- package/dist/tools/helpers/suggestion-generator.d.ts.map +0 -1
- package/dist/tools/helpers/suggestion-generator.js.map +0 -1
- package/dist/tools/learn-patterns.d.ts.map +0 -1
- package/dist/tools/learn-patterns.js.map +0 -1
- package/dist/tools/list-imports.d.ts.map +0 -1
- package/dist/tools/list-imports.js.map +0 -1
- package/dist/tools/orchestrate-migration.d.ts.map +0 -1
- package/dist/tools/orchestrate-migration.js.map +0 -1
- package/dist/tools/parse-stack-trace.d.ts.map +0 -1
- package/dist/tools/parse-stack-trace.js.map +0 -1
- package/dist/tools/plan-migration.d.ts.map +0 -1
- package/dist/tools/plan-migration.js.map +0 -1
- package/dist/tools/resolve-type.d.ts.map +0 -1
- package/dist/tools/resolve-type.js.map +0 -1
- package/dist/tools/review-feedback.d.ts.map +0 -1
- package/dist/tools/review-feedback.js.map +0 -1
- package/dist/tools/rollback-changes.d.ts.map +0 -1
- package/dist/tools/rollback-changes.js.map +0 -1
- package/dist/tools/run-angular-cli.d.ts.map +0 -1
- package/dist/tools/run-angular-cli.js.map +0 -1
- package/dist/tools/run-build.d.ts.map +0 -1
- package/dist/tools/run-build.js.map +0 -1
- package/dist/tools/run-schematic.d.ts.map +0 -1
- package/dist/tools/run-schematic.js.map +0 -1
- package/dist/tools/scan-all.d.ts.map +0 -1
- package/dist/tools/scan-all.js.map +0 -1
- package/dist/tools/scan-angular.d.ts.map +0 -1
- package/dist/tools/scan-angular.js.map +0 -1
- package/dist/tools/scan-architecture.d.ts.map +0 -1
- package/dist/tools/scan-architecture.js.map +0 -1
- package/dist/tools/scan-solid.d.ts.map +0 -1
- package/dist/tools/scan-solid.js.map +0 -1
- package/dist/tools/search-codebase.d.ts.map +0 -1
- package/dist/tools/search-codebase.js.map +0 -1
- package/dist/tools/shared/scan-types.d.ts.map +0 -1
- package/dist/tools/shared/scan-types.js.map +0 -1
- package/dist/tools/suggest-improvements.d.ts.map +0 -1
- package/dist/tools/suggest-improvements.js.map +0 -1
- package/dist/tools/transform-code-batch.d.ts.map +0 -1
- package/dist/tools/transform-code-batch.js.map +0 -1
- package/dist/tools/transform-code.d.ts.map +0 -1
- package/dist/tools/transform-code.js.map +0 -1
- package/dist/tools/validate-before-transform.d.ts.map +0 -1
- package/dist/tools/validate-before-transform.js.map +0 -1
- package/dist/tools/validate-project-compatibility.d.ts.map +0 -1
- package/dist/tools/validate-project-compatibility.js.map +0 -1
- package/dist/tools/validate-transformation.d.ts.map +0 -1
- package/dist/tools/validate-transformation.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/utils/format-tool-response.d.ts.map +0 -1
- package/dist/utils/format-tool-response.js.map +0 -1
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/adapter-mcp - Rule runner for scan tools
|
|
3
|
+
*
|
|
4
|
+
* Runs analysis rules over a file list with a time budget:
|
|
5
|
+
* - all files are added to the project first, so project-wide rules
|
|
6
|
+
* (library extraction, circular dependencies, type resolution) see the same,
|
|
7
|
+
* complete project for every file instead of a prefix that grows per file;
|
|
8
|
+
* the load yields and checks the signal per file as well
|
|
9
|
+
* - the budget and the abort signal are checked between files; a rule that
|
|
10
|
+
* is running cannot be interrupted (analysis is synchronous CPU work), so
|
|
11
|
+
* the overrun is at most one file. With a signal the loop yields to the
|
|
12
|
+
* event loop once per file, otherwise `notifications/cancelled` is not read
|
|
13
|
+
* before the scan ends
|
|
14
|
+
* - time per rule is recorded so slow rules show up in the result
|
|
15
|
+
*/
|
|
16
|
+
import { ContextFactory, } from '@angular-modernizer/plugin-system';
|
|
17
|
+
import { yieldIfCancellable } from './tool-context.js';
|
|
18
|
+
import { loadSourceFiles } from './load-source-files.js';
|
|
19
|
+
/** Default scan time budget: 5 minutes. */
|
|
20
|
+
export const DEFAULT_MAX_DURATION_MS = 300_000;
|
|
21
|
+
/**
|
|
22
|
+
* Parse the `maxDurationMs` tool parameter.
|
|
23
|
+
*/
|
|
24
|
+
export function parseMaxDurationMs(value) {
|
|
25
|
+
if (value === undefined) {
|
|
26
|
+
return DEFAULT_MAX_DURATION_MS;
|
|
27
|
+
}
|
|
28
|
+
if (typeof value !== 'number' || !Number.isFinite(value) || value < 0) {
|
|
29
|
+
throw new Error('maxDurationMs must be a number >= 0 (0 disables the time budget)');
|
|
30
|
+
}
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
export async function runRulesOverFiles(options) {
|
|
34
|
+
const startTime = options.startTime ?? Date.now();
|
|
35
|
+
const budget = options.maxDurationMs ?? DEFAULT_MAX_DURATION_MS;
|
|
36
|
+
const deadline = budget > 0 ? startTime + budget : Number.POSITIVE_INFINITY;
|
|
37
|
+
const { project, rules } = options;
|
|
38
|
+
const loaded = await loadSourceFiles(project, options.files, {
|
|
39
|
+
signal: options.signal,
|
|
40
|
+
isCancelled: options.isCancelled,
|
|
41
|
+
reuseExisting: true,
|
|
42
|
+
});
|
|
43
|
+
if (loaded.cancelled) {
|
|
44
|
+
return {
|
|
45
|
+
violations: [],
|
|
46
|
+
filesAnalyzed: 0,
|
|
47
|
+
incomplete: true,
|
|
48
|
+
stopReason: 'cancelled',
|
|
49
|
+
skippedFiles: options.files.length,
|
|
50
|
+
ruleTimings: [],
|
|
51
|
+
durationMs: Date.now() - startTime,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const sourceFiles = loaded.sourceFiles;
|
|
55
|
+
const violations = [];
|
|
56
|
+
const timings = new Map();
|
|
57
|
+
let filesAnalyzed = 0;
|
|
58
|
+
let stopReason;
|
|
59
|
+
for (const sourceFile of sourceFiles) {
|
|
60
|
+
await yieldIfCancellable(options.signal);
|
|
61
|
+
if (options.signal?.aborted === true || options.isCancelled?.() === true) {
|
|
62
|
+
stopReason = 'cancelled';
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
if (Date.now() >= deadline) {
|
|
66
|
+
stopReason = 'time-budget';
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
for (const rule of rules) {
|
|
71
|
+
const ruleStart = Date.now();
|
|
72
|
+
const results = await rule.analyze(ContextFactory.createAnalysisContext({
|
|
73
|
+
sourceFile,
|
|
74
|
+
project,
|
|
75
|
+
api: options.api,
|
|
76
|
+
config: options.config,
|
|
77
|
+
}));
|
|
78
|
+
timings.set(rule.id, (timings.get(rule.id) ?? 0) + Date.now() - ruleStart);
|
|
79
|
+
for (const result of results) {
|
|
80
|
+
violations.push(toViolation(rule, result));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
console.warn(`Error analyzing ${sourceFile.getFilePath()}:`, error);
|
|
86
|
+
}
|
|
87
|
+
filesAnalyzed++;
|
|
88
|
+
options.onFileAnalyzed?.(filesAnalyzed, sourceFiles.length, violations.length);
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
violations,
|
|
92
|
+
filesAnalyzed,
|
|
93
|
+
incomplete: stopReason !== undefined,
|
|
94
|
+
...(stopReason ? { stopReason } : {}),
|
|
95
|
+
skippedFiles: sourceFiles.length - filesAnalyzed,
|
|
96
|
+
ruleTimings: Array.from(timings, ([ruleId, ms]) => ({ ruleId, ms })).sort((a, b) => b.ms - a.ms),
|
|
97
|
+
durationMs: Date.now() - startTime,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function toViolation(rule, result) {
|
|
101
|
+
return {
|
|
102
|
+
id: `${result.ruleId}-${result.filePath}-${result.line ?? 0}-${result.column ?? 0}`,
|
|
103
|
+
ruleId: result.ruleId,
|
|
104
|
+
severity: result.severity ?? rule.severity,
|
|
105
|
+
message: result.message,
|
|
106
|
+
filePath: result.filePath,
|
|
107
|
+
line: result.line,
|
|
108
|
+
column: result.column,
|
|
109
|
+
category: rule.category,
|
|
110
|
+
suggestedFix: result.suggestedFix,
|
|
111
|
+
metadata: result.metadata,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Human-readable note for an incomplete run.
|
|
116
|
+
*/
|
|
117
|
+
export function incompleteNote(result, budgetMs) {
|
|
118
|
+
if (!result.incomplete) {
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
const slowest = result.ruleTimings
|
|
122
|
+
.slice(0, 3)
|
|
123
|
+
.map((t) => `${t.ruleId} ${(t.ms / 1000).toFixed(1)}s`)
|
|
124
|
+
.join(', ');
|
|
125
|
+
const reason = result.stopReason === 'cancelled'
|
|
126
|
+
? 'cancelled'
|
|
127
|
+
: `stopped at the time budget (maxDurationMs ${budgetMs})`;
|
|
128
|
+
return (`Scan ${reason} after ${result.filesAnalyzed} file(s); ${result.skippedFiles} file(s) not analyzed. ` +
|
|
129
|
+
`Slowest rules: ${slowest || 'n/a'}. Narrow the scope, pass rules, or raise maxDurationMs (0 = no limit).`);
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=rule-runner.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/adapter-mcp - scan-all cache entries
|
|
3
|
+
*
|
|
4
|
+
* scan-all caches the findings of each analyzed `.ts` file under that file,
|
|
5
|
+
* including findings reported on its template (`.html`) and files without any
|
|
6
|
+
* finding. Template files are stored as dependencies so an edit to the
|
|
7
|
+
* template alone invalidates the entry.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Template files a cache entry depends on: `templateUrl` targets in the
|
|
11
|
+
* source text and every other file a finding of this source points at.
|
|
12
|
+
*
|
|
13
|
+
* @param exists - filters out paths that do not exist; the cache treats a
|
|
14
|
+
* missing dependency as invalidation, so it would never hit.
|
|
15
|
+
*/
|
|
16
|
+
export declare function templateDependencies(sourcePath: string, sourceText: string, findingPaths: readonly string[], exists: (path: string) => boolean): string[];
|
|
17
|
+
/**
|
|
18
|
+
* Whether a cache entry is still current for its dependencies: none of them
|
|
19
|
+
* was modified after the entry was written.
|
|
20
|
+
*/
|
|
21
|
+
export declare function dependenciesUnchanged(dependencies: readonly string[], cachedAt: number, modifiedAt: (path: string) => number | undefined): boolean;
|
|
22
|
+
//# sourceMappingURL=scan-cache.d.ts.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/adapter-mcp - scan-all cache entries
|
|
3
|
+
*
|
|
4
|
+
* scan-all caches the findings of each analyzed `.ts` file under that file,
|
|
5
|
+
* including findings reported on its template (`.html`) and files without any
|
|
6
|
+
* finding. Template files are stored as dependencies so an edit to the
|
|
7
|
+
* template alone invalidates the entry.
|
|
8
|
+
*/
|
|
9
|
+
import { dirname, resolve } from 'node:path';
|
|
10
|
+
const TEMPLATE_URL = /templateUrl\s*:\s*['"`]([^'"`]+)['"`]/g;
|
|
11
|
+
/**
|
|
12
|
+
* Template files a cache entry depends on: `templateUrl` targets in the
|
|
13
|
+
* source text and every other file a finding of this source points at.
|
|
14
|
+
*
|
|
15
|
+
* @param exists - filters out paths that do not exist; the cache treats a
|
|
16
|
+
* missing dependency as invalidation, so it would never hit.
|
|
17
|
+
*/
|
|
18
|
+
export function templateDependencies(sourcePath, sourceText, findingPaths, exists) {
|
|
19
|
+
const fromTemplateUrl = [...sourceText.matchAll(TEMPLATE_URL)].map((m) => resolve(dirname(sourcePath), m[1] ?? ''));
|
|
20
|
+
const candidates = new Set([...fromTemplateUrl, ...findingPaths]);
|
|
21
|
+
candidates.delete(sourcePath);
|
|
22
|
+
return [...candidates].filter(exists).sort();
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Whether a cache entry is still current for its dependencies: none of them
|
|
26
|
+
* was modified after the entry was written.
|
|
27
|
+
*/
|
|
28
|
+
export function dependenciesUnchanged(dependencies, cachedAt, modifiedAt) {
|
|
29
|
+
return dependencies.every((dep) => {
|
|
30
|
+
const mtime = modifiedAt(dep);
|
|
31
|
+
return mtime !== undefined && mtime <= cachedAt;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=scan-cache.js.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/adapter-mcp - Scan-based migration plan
|
|
3
|
+
*
|
|
4
|
+
* Wiring for plan-migration when violations carry file paths: reads a saved
|
|
5
|
+
* scan-architecture result, builds the project import graph (plus template
|
|
6
|
+
* edges: a host depends on the components, directives and pipes its template
|
|
7
|
+
* uses by selector or pipe name) and the layer lookup, and hands both to core
|
|
8
|
+
* `buildViolationPlan`.
|
|
9
|
+
*/
|
|
10
|
+
import { Project } from 'ts-morph';
|
|
11
|
+
import { type ViolationPlan } from '@angular-modernizer/core';
|
|
12
|
+
/** A violation as plan-migration accepts it (scan fields optional). */
|
|
13
|
+
export interface ScanViolationInput {
|
|
14
|
+
ruleId: string;
|
|
15
|
+
severity: string;
|
|
16
|
+
category: string;
|
|
17
|
+
filePath?: string;
|
|
18
|
+
line?: number;
|
|
19
|
+
message?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface ScanPlanResult {
|
|
22
|
+
plan: ViolationPlan;
|
|
23
|
+
/** Where the layers came from. */
|
|
24
|
+
layerSource: 'layersSource' | 'layers' | 'none';
|
|
25
|
+
/** Files of the import graph (size of the analyzed program). */
|
|
26
|
+
graphFiles: number;
|
|
27
|
+
warnings: string[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Read violations from a saved scan-architecture result. Accepts the tool
|
|
31
|
+
* result object (`{ violations: [...] }`), the MCP tool result with
|
|
32
|
+
* `structuredContent`, a bare violation array, or an MCP content array
|
|
33
|
+
* (`[{ type: 'text', text: '<json>' }]`) as clients persist it. A content
|
|
34
|
+
* array whose text is no JSON (the text summary of a structured result) is
|
|
35
|
+
* rejected like any other file without violations.
|
|
36
|
+
*/
|
|
37
|
+
export declare function readScanResultFile(filePath: string): ScanViolationInput[];
|
|
38
|
+
/**
|
|
39
|
+
* Build the file-level plan for violations that carry a file path.
|
|
40
|
+
*/
|
|
41
|
+
export declare function buildScanPlan(options: {
|
|
42
|
+
projectRoot: string;
|
|
43
|
+
violations: readonly ScanViolationInput[];
|
|
44
|
+
maxPhases?: number;
|
|
45
|
+
/** Project for a tsconfig, e.g. from the shared ProjectCache; a fresh Project otherwise. */
|
|
46
|
+
loadProject?: (tsConfigPath: string) => Project;
|
|
47
|
+
}): Promise<ScanPlanResult>;
|
|
48
|
+
//# sourceMappingURL=scan-plan.d.ts.map
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/adapter-mcp - Scan-based migration plan
|
|
3
|
+
*
|
|
4
|
+
* Wiring for plan-migration when violations carry file paths: reads a saved
|
|
5
|
+
* scan-architecture result, builds the project import graph (plus template
|
|
6
|
+
* edges: a host depends on the components, directives and pipes its template
|
|
7
|
+
* uses by selector or pipe name) and the layer lookup, and hands both to core
|
|
8
|
+
* `buildViolationPlan`.
|
|
9
|
+
*/
|
|
10
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
11
|
+
import { isAbsolute, relative, resolve } from 'node:path';
|
|
12
|
+
import { Project } from 'ts-morph';
|
|
13
|
+
import { ConfigLoader, DependencyGraphBuilder, buildViolationPlan, } from '@angular-modernizer/core';
|
|
14
|
+
import { LayerPathMatcher, loadLayersFromSource, } from '@angular-modernizer/plugin-architecture';
|
|
15
|
+
import { findTsConfig } from './find-ts-config.js';
|
|
16
|
+
function isRecord(value) {
|
|
17
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Read violations from a saved scan-architecture result. Accepts the tool
|
|
21
|
+
* result object (`{ violations: [...] }`), the MCP tool result with
|
|
22
|
+
* `structuredContent`, a bare violation array, or an MCP content array
|
|
23
|
+
* (`[{ type: 'text', text: '<json>' }]`) as clients persist it. A content
|
|
24
|
+
* array whose text is no JSON (the text summary of a structured result) is
|
|
25
|
+
* rejected like any other file without violations.
|
|
26
|
+
*/
|
|
27
|
+
export function readScanResultFile(filePath) {
|
|
28
|
+
if (!existsSync(filePath)) {
|
|
29
|
+
throw new Error(`scanResultFile does not exist: ${filePath}`);
|
|
30
|
+
}
|
|
31
|
+
let parsed;
|
|
32
|
+
try {
|
|
33
|
+
parsed = JSON.parse(readFileSync(filePath, 'utf8'));
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
throw new Error(`scanResultFile is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
37
|
+
}
|
|
38
|
+
const violations = extractViolations(parsed);
|
|
39
|
+
if (!violations) {
|
|
40
|
+
throw new Error('scanResultFile must contain a scan-architecture result ({ violations: [...] }) or a violation array');
|
|
41
|
+
}
|
|
42
|
+
return violations;
|
|
43
|
+
}
|
|
44
|
+
function extractViolations(value) {
|
|
45
|
+
if (Array.isArray(value)) {
|
|
46
|
+
const first = value[0];
|
|
47
|
+
if (isRecord(first) && first['type'] === 'text' && typeof first['text'] === 'string') {
|
|
48
|
+
return extractViolations(parseJson(first['text']));
|
|
49
|
+
}
|
|
50
|
+
return value.filter(isScanViolation);
|
|
51
|
+
}
|
|
52
|
+
if (isRecord(value) && Array.isArray(value['violations'])) {
|
|
53
|
+
return value['violations'].filter(isScanViolation);
|
|
54
|
+
}
|
|
55
|
+
if (isRecord(value) && isRecord(value['structuredContent'])) {
|
|
56
|
+
return extractViolations(value['structuredContent']);
|
|
57
|
+
}
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
/** Parsed JSON, or `undefined` for text that is no JSON. */
|
|
61
|
+
function parseJson(text) {
|
|
62
|
+
try {
|
|
63
|
+
return JSON.parse(text);
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function isScanViolation(value) {
|
|
70
|
+
return (isRecord(value) &&
|
|
71
|
+
typeof value['ruleId'] === 'string' &&
|
|
72
|
+
typeof value['severity'] === 'string');
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Build the file-level plan for violations that carry a file path.
|
|
76
|
+
*/
|
|
77
|
+
export async function buildScanPlan(options) {
|
|
78
|
+
const { projectRoot } = options;
|
|
79
|
+
const warnings = [];
|
|
80
|
+
const tsConfigPath = findTsConfig(projectRoot);
|
|
81
|
+
if (!tsConfigPath) {
|
|
82
|
+
throw new Error(`tsconfig.json not found in project: ${projectRoot}`);
|
|
83
|
+
}
|
|
84
|
+
const project = options.loadProject?.(tsConfigPath) ?? new Project({ tsConfigFilePath: tsConfigPath });
|
|
85
|
+
const graph = new DependencyGraphBuilder(project, { templateEdges: true });
|
|
86
|
+
await graph.buildGraph();
|
|
87
|
+
const { layers, source } = await loadLayers(projectRoot, warnings);
|
|
88
|
+
const matcher = layers.length > 0
|
|
89
|
+
? new LayerPathMatcher(layers, project.getCompilerOptions(), projectRoot)
|
|
90
|
+
: undefined;
|
|
91
|
+
const planViolations = [];
|
|
92
|
+
for (const violation of options.violations) {
|
|
93
|
+
if (!violation.filePath) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const filePath = isAbsolute(violation.filePath)
|
|
97
|
+
? violation.filePath
|
|
98
|
+
: resolve(projectRoot, violation.filePath);
|
|
99
|
+
planViolations.push({
|
|
100
|
+
filePath,
|
|
101
|
+
ruleId: violation.ruleId,
|
|
102
|
+
severity: violation.severity,
|
|
103
|
+
category: violation.category,
|
|
104
|
+
...(violation.line !== undefined ? { line: violation.line } : {}),
|
|
105
|
+
...(violation.message !== undefined ? { message: violation.message } : {}),
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
const graphNodes = graph.getGraph();
|
|
109
|
+
const outsideProgram = new Set(planViolations.map((v) => v.filePath).filter((file) => !graphNodes.has(file)));
|
|
110
|
+
if (outsideProgram.size > 0) {
|
|
111
|
+
warnings.push(`${outsideProgram.size} file(s) are not part of the TypeScript program (${tsConfigPath}); they are ordered without dependencies.`);
|
|
112
|
+
}
|
|
113
|
+
const plan = buildViolationPlan(planViolations, {
|
|
114
|
+
// Template edges order a child before the hosts that use it by selector
|
|
115
|
+
dependenciesOf: (file) => [
|
|
116
|
+
...graph.getDirectDependencies(file),
|
|
117
|
+
...graph.getTemplateDependencies(file),
|
|
118
|
+
],
|
|
119
|
+
layerOf: (file) => {
|
|
120
|
+
const layer = matcher?.match(file);
|
|
121
|
+
return layer ? layer.alias || layer.name : undefined;
|
|
122
|
+
},
|
|
123
|
+
...(options.maxPhases !== undefined ? { maxPhases: options.maxPhases } : {}),
|
|
124
|
+
});
|
|
125
|
+
return {
|
|
126
|
+
plan: relativizePlan(plan, projectRoot),
|
|
127
|
+
layerSource: source,
|
|
128
|
+
graphFiles: project.getSourceFiles().length,
|
|
129
|
+
warnings,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
async function loadLayers(projectRoot, warnings) {
|
|
133
|
+
try {
|
|
134
|
+
const config = new ConfigLoader().load(projectRoot);
|
|
135
|
+
if (config.layersSource) {
|
|
136
|
+
return {
|
|
137
|
+
layers: await loadLayersFromSource(projectRoot, config.layersSource),
|
|
138
|
+
source: 'layersSource',
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
if (config.layers && config.layers.length > 0) {
|
|
142
|
+
return { layers: config.layers, source: 'layers' };
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
warnings.push(`Layers unavailable, files are not grouped by layer: ${error instanceof Error ? error.message : String(error)}`);
|
|
147
|
+
}
|
|
148
|
+
return { layers: [], source: 'none' };
|
|
149
|
+
}
|
|
150
|
+
/** Project-relative paths keep the plan readable and portable. */
|
|
151
|
+
function relativizePlan(plan, projectRoot) {
|
|
152
|
+
const rel = (file) => relative(projectRoot, file);
|
|
153
|
+
return {
|
|
154
|
+
...plan,
|
|
155
|
+
cycles: plan.cycles.map((cycle) => ({ ...cycle, files: cycle.files.map(rel) })),
|
|
156
|
+
phases: plan.phases.map((phase) => ({
|
|
157
|
+
...phase,
|
|
158
|
+
files: phase.files.map((file) => ({
|
|
159
|
+
...file,
|
|
160
|
+
filePath: rel(file.filePath),
|
|
161
|
+
dependsOn: file.dependsOn.map(rel),
|
|
162
|
+
})),
|
|
163
|
+
})),
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=scan-plan.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/adapter-mcp - Scope path matching
|
|
3
|
+
*
|
|
4
|
+
* A file belongs to a scope path when it is that path or lies below it. A
|
|
5
|
+
* bare `startsWith` also matched sibling folders sharing the prefix
|
|
6
|
+
* (`features/orders` took in `features/orders-shared`).
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Whether `file` is `scopePath` itself or lies inside the folder
|
|
10
|
+
* `scopePath`. Both are compared with `/` separators.
|
|
11
|
+
*/
|
|
12
|
+
export declare function isInScopePath(file: string, scopePath: string): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* The files inside at least one of `scopePaths`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function filterFilesByScopePaths(files: readonly string[], scopePaths: readonly string[]): string[];
|
|
17
|
+
//# sourceMappingURL=scope-paths.d.ts.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/adapter-mcp - Scope path matching
|
|
3
|
+
*
|
|
4
|
+
* A file belongs to a scope path when it is that path or lies below it. A
|
|
5
|
+
* bare `startsWith` also matched sibling folders sharing the prefix
|
|
6
|
+
* (`features/orders` took in `features/orders-shared`).
|
|
7
|
+
*/
|
|
8
|
+
/** `/` separators and no trailing separator. */
|
|
9
|
+
function normalizePath(path) {
|
|
10
|
+
const slashes = path.replaceAll('\\', '/');
|
|
11
|
+
return slashes.length > 1 ? slashes.replace(/\/+$/, '') : slashes;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Whether `file` is `scopePath` itself or lies inside the folder
|
|
15
|
+
* `scopePath`. Both are compared with `/` separators.
|
|
16
|
+
*/
|
|
17
|
+
export function isInScopePath(file, scopePath) {
|
|
18
|
+
const normalizedFile = normalizePath(file);
|
|
19
|
+
const normalizedScope = normalizePath(scopePath);
|
|
20
|
+
if (normalizedFile === normalizedScope) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
const folder = normalizedScope.endsWith('/') ? normalizedScope : `${normalizedScope}/`;
|
|
24
|
+
return normalizedFile.startsWith(folder);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The files inside at least one of `scopePaths`.
|
|
28
|
+
*/
|
|
29
|
+
export function filterFilesByScopePaths(files, scopePaths) {
|
|
30
|
+
return files.filter((file) => scopePaths.some((scopePath) => isInScopePath(file, scopePath)));
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=scope-paths.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node file system implementation of the api `StackFrameFileIndex`.
|
|
3
|
+
*
|
|
4
|
+
* `exists` stats a single path. The basename index walks `projectRoot` once, on
|
|
5
|
+
* the first basename lookup, so stacks with absolute or URL frames never pay
|
|
6
|
+
* for the walk. Build output, caches and `node_modules` are skipped.
|
|
7
|
+
*/
|
|
8
|
+
import { type StackFrameFileIndex } from '@angular-modernizer/api';
|
|
9
|
+
export declare function createNodeStackFrameFileIndex(projectRoot: string): StackFrameFileIndex;
|
|
10
|
+
//# sourceMappingURL=stack-frame-file-index.d.ts.map
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node file system implementation of the api `StackFrameFileIndex`.
|
|
3
|
+
*
|
|
4
|
+
* `exists` stats a single path. The basename index walks `projectRoot` once, on
|
|
5
|
+
* the first basename lookup, so stacks with absolute or URL frames never pay
|
|
6
|
+
* for the walk. Build output, caches and `node_modules` are skipped.
|
|
7
|
+
*/
|
|
8
|
+
import { readdirSync, statSync } from 'node:fs';
|
|
9
|
+
import { join } from 'node:path';
|
|
10
|
+
const SKIPPED_DIRECTORIES = new Set([
|
|
11
|
+
'node_modules',
|
|
12
|
+
'.git',
|
|
13
|
+
'.angular',
|
|
14
|
+
'.nx',
|
|
15
|
+
'.cache',
|
|
16
|
+
'dist',
|
|
17
|
+
'coverage',
|
|
18
|
+
'out-tsc',
|
|
19
|
+
]);
|
|
20
|
+
/** Stops the walk on a mistaken root such as `/`. */
|
|
21
|
+
const MAX_WALKED_FILES = 200_000;
|
|
22
|
+
export function createNodeStackFrameFileIndex(projectRoot) {
|
|
23
|
+
let byBasename;
|
|
24
|
+
const index = () => (byBasename ??= walk(projectRoot));
|
|
25
|
+
return {
|
|
26
|
+
exists: (path) => {
|
|
27
|
+
try {
|
|
28
|
+
return statSync(path).isFile();
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
findByBasename: (name) => index().get(name) ?? [],
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function walk(root) {
|
|
38
|
+
const byBasename = new Map();
|
|
39
|
+
const stack = [root];
|
|
40
|
+
let seen = 0;
|
|
41
|
+
while (stack.length > 0 && seen < MAX_WALKED_FILES) {
|
|
42
|
+
const current = stack.pop();
|
|
43
|
+
if (current === undefined) {
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
let entries;
|
|
47
|
+
try {
|
|
48
|
+
entries = readdirSync(current, { withFileTypes: true });
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
for (const entry of entries) {
|
|
54
|
+
if (entry.isDirectory()) {
|
|
55
|
+
if (!SKIPPED_DIRECTORIES.has(entry.name)) {
|
|
56
|
+
stack.push(join(current, entry.name));
|
|
57
|
+
}
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (!entry.isFile()) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
seen++;
|
|
64
|
+
const list = byBasename.get(entry.name) ?? [];
|
|
65
|
+
list.push(join(current, entry.name));
|
|
66
|
+
byBasename.set(entry.name, list);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return byBasename;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=stack-frame-file-index.js.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/adapter-mcp - Helpers for the per-call tool context
|
|
3
|
+
*
|
|
4
|
+
* Analysis is synchronous CPU work: while a loop runs, the server does not
|
|
5
|
+
* read stdin, so `notifications/cancelled` only arrives once the loop gives
|
|
6
|
+
* the event loop a turn. Long loops therefore yield once per file when the
|
|
7
|
+
* call can be cancelled ({@link yieldIfCancellable}).
|
|
8
|
+
*/
|
|
9
|
+
import { type ProgressFn } from '../../types.js';
|
|
10
|
+
/** Minimum gap between two progress notifications. */
|
|
11
|
+
export declare const PROGRESS_INTERVAL_MS = 250;
|
|
12
|
+
/**
|
|
13
|
+
* Wraps `send` so it fires for the first value, for the last value
|
|
14
|
+
* (`progress >= total`) and otherwise at most once per `intervalMs`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function throttleProgress(send: ProgressFn, intervalMs?: number, now?: () => number): ProgressFn;
|
|
17
|
+
/**
|
|
18
|
+
* Gives the event loop one turn when the call can be cancelled, so a pending
|
|
19
|
+
* `notifications/cancelled` is read and `signal` aborts. Without a signal
|
|
20
|
+
* (direct calls, tests) it returns at once.
|
|
21
|
+
*/
|
|
22
|
+
export declare function yieldIfCancellable(signal: AbortSignal | undefined): Promise<void>;
|
|
23
|
+
/** Progress message of a file loop: `12/40 files, 3 violations`. */
|
|
24
|
+
export declare function fileProgressMessage(analyzed: number, total: number, violations: number): string;
|
|
25
|
+
/**
|
|
26
|
+
* `onFileAnalyzed` callback of a file loop that reports to `progress`;
|
|
27
|
+
* `undefined` without progress, so the loop does no extra work.
|
|
28
|
+
*/
|
|
29
|
+
export declare function fileProgress(progress: ProgressFn | undefined): ((analyzed: number, total: number, violations: number) => void) | undefined;
|
|
30
|
+
/** Execution details of a scan the client cancelled. */
|
|
31
|
+
export interface CancelledExecution {
|
|
32
|
+
maxDurationMs?: number;
|
|
33
|
+
incomplete: true;
|
|
34
|
+
stopReason: 'cancelled';
|
|
35
|
+
skippedFiles: number;
|
|
36
|
+
ruleTimings: [];
|
|
37
|
+
note: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Execution details of a scan the client cancelled after `analyzed` files.
|
|
41
|
+
* The SDK does not send the result of a cancelled request; it still has to
|
|
42
|
+
* be complete for direct callers (compare-health, tests).
|
|
43
|
+
*/
|
|
44
|
+
export declare function cancelledExecution(analyzed: number, skippedFiles: number, maxDurationMs?: number): CancelledExecution;
|
|
45
|
+
/** The part of the kernel's `ProgressReporter` the forwarding needs. */
|
|
46
|
+
interface KernelProgressSource {
|
|
47
|
+
on(event: 'progress', listener: (event: {
|
|
48
|
+
current: number;
|
|
49
|
+
total: number;
|
|
50
|
+
message?: string;
|
|
51
|
+
}) => void): unknown;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Forwards the kernel's progress events (parallel and incremental analysis)
|
|
55
|
+
* to `progress`. The reporter belongs to the call's own kernel, so the
|
|
56
|
+
* listener goes away with it.
|
|
57
|
+
*/
|
|
58
|
+
export declare function forwardKernelProgress(reporter: KernelProgressSource | undefined, progress: ProgressFn): void;
|
|
59
|
+
export {};
|
|
60
|
+
//# sourceMappingURL=tool-context.d.ts.map
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/adapter-mcp - Helpers for the per-call tool context
|
|
3
|
+
*
|
|
4
|
+
* Analysis is synchronous CPU work: while a loop runs, the server does not
|
|
5
|
+
* read stdin, so `notifications/cancelled` only arrives once the loop gives
|
|
6
|
+
* the event loop a turn. Long loops therefore yield once per file when the
|
|
7
|
+
* call can be cancelled ({@link yieldIfCancellable}).
|
|
8
|
+
*/
|
|
9
|
+
/** Minimum gap between two progress notifications. */
|
|
10
|
+
export const PROGRESS_INTERVAL_MS = 250;
|
|
11
|
+
/**
|
|
12
|
+
* Wraps `send` so it fires for the first value, for the last value
|
|
13
|
+
* (`progress >= total`) and otherwise at most once per `intervalMs`.
|
|
14
|
+
*/
|
|
15
|
+
export function throttleProgress(send, intervalMs = PROGRESS_INTERVAL_MS, now = Date.now) {
|
|
16
|
+
let last;
|
|
17
|
+
return (progress, total, message) => {
|
|
18
|
+
const time = now();
|
|
19
|
+
const isLast = total !== undefined && progress >= total;
|
|
20
|
+
if (last !== undefined && !isLast && time - last < intervalMs) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
last = time;
|
|
24
|
+
send(progress, total, message);
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Gives the event loop one turn when the call can be cancelled, so a pending
|
|
29
|
+
* `notifications/cancelled` is read and `signal` aborts. Without a signal
|
|
30
|
+
* (direct calls, tests) it returns at once.
|
|
31
|
+
*/
|
|
32
|
+
export async function yieldIfCancellable(signal) {
|
|
33
|
+
if (signal === undefined) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
37
|
+
}
|
|
38
|
+
/** Progress message of a file loop: `12/40 files, 3 violations`. */
|
|
39
|
+
export function fileProgressMessage(analyzed, total, violations) {
|
|
40
|
+
return `${analyzed}/${total} files, ${violations} violation${violations === 1 ? '' : 's'}`;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* `onFileAnalyzed` callback of a file loop that reports to `progress`;
|
|
44
|
+
* `undefined` without progress, so the loop does no extra work.
|
|
45
|
+
*/
|
|
46
|
+
export function fileProgress(progress) {
|
|
47
|
+
if (progress === undefined) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
return (analyzed, total, violations) => {
|
|
51
|
+
progress(analyzed, total, fileProgressMessage(analyzed, total, violations));
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Execution details of a scan the client cancelled after `analyzed` files.
|
|
56
|
+
* The SDK does not send the result of a cancelled request; it still has to
|
|
57
|
+
* be complete for direct callers (compare-health, tests).
|
|
58
|
+
*/
|
|
59
|
+
export function cancelledExecution(analyzed, skippedFiles, maxDurationMs) {
|
|
60
|
+
return {
|
|
61
|
+
...(maxDurationMs === undefined ? {} : { maxDurationMs }),
|
|
62
|
+
incomplete: true,
|
|
63
|
+
stopReason: 'cancelled',
|
|
64
|
+
skippedFiles,
|
|
65
|
+
ruleTimings: [],
|
|
66
|
+
note: `Scan cancelled after ${analyzed} file(s); ${skippedFiles} file(s) not analyzed.`,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Forwards the kernel's progress events (parallel and incremental analysis)
|
|
71
|
+
* to `progress`. The reporter belongs to the call's own kernel, so the
|
|
72
|
+
* listener goes away with it.
|
|
73
|
+
*/
|
|
74
|
+
export function forwardKernelProgress(reporter, progress) {
|
|
75
|
+
if (reporter === undefined) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
reporter.on('progress', (event) => {
|
|
79
|
+
progress(event.current, event.total, `${event.current}/${event.total} files`);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=tool-context.js.map
|