@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,324 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/adapter-mcp - Get Bootstrap Execution Tool
|
|
3
|
+
*
|
|
4
|
+
* MCP tool that lists what an Angular app runs at startup (initializers,
|
|
5
|
+
* bootstrap component/module), on the first HTTP request (interceptors) and
|
|
6
|
+
* on first injection (provider factories), including everything reached
|
|
7
|
+
* through calls and dependency injection, and where a watched expression
|
|
8
|
+
* such as `AppConfig.settings` is read or written on the way.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* Logic lives in `BootstrapExecutionAnalyzer` (`@angular-modernizer/api`);
|
|
12
|
+
* this tool resolves the project, validates arguments and applies the
|
|
13
|
+
* compact output contract.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* // Via MCP:
|
|
18
|
+
* // tool: get-bootstrap-execution
|
|
19
|
+
* // args: { projectRoot: '/project', watch: ['AppConfig.settings'], summaryOnly: true }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
import { BootstrapExecutionAnalyzer, normalizeWatchExpression, } from '@angular-modernizer/api';
|
|
23
|
+
import { existsSync } from 'node:fs';
|
|
24
|
+
import { isAbsolute, relative, resolve } from 'node:path';
|
|
25
|
+
import { findTsConfig } from './helpers/find-ts-config.js';
|
|
26
|
+
import { ProjectCache } from './helpers/project-cache.js';
|
|
27
|
+
import { COMPACT_OUTPUT_SCHEMA, limitList, parseCompactOptions, } from './helpers/compact-output.js';
|
|
28
|
+
import { WARNINGS_OUTPUT_SCHEMA, withWarnings, } from './helpers/output-contract.js';
|
|
29
|
+
import { COUNT_OBJECT, STRING_ARRAY } from './helpers/investigation-schemas.js';
|
|
30
|
+
const TIMINGS = [
|
|
31
|
+
'initializer',
|
|
32
|
+
'bootstrap',
|
|
33
|
+
'first-http-request',
|
|
34
|
+
'first-injection',
|
|
35
|
+
'custom',
|
|
36
|
+
];
|
|
37
|
+
/** Watched access sites listed in the text summary. */
|
|
38
|
+
const SUMMARY_MAX_SITES = 10;
|
|
39
|
+
/**
|
|
40
|
+
* Summary order: accesses that can run before the app is fully initialized
|
|
41
|
+
* first (initializers, and interceptors an initializer may construct).
|
|
42
|
+
*/
|
|
43
|
+
const TIMING_RANK = {
|
|
44
|
+
initializer: 0,
|
|
45
|
+
'first-http-request': 1,
|
|
46
|
+
custom: 2,
|
|
47
|
+
'first-injection': 3,
|
|
48
|
+
bootstrap: 4,
|
|
49
|
+
};
|
|
50
|
+
function earliestFirst(a, b) {
|
|
51
|
+
return TIMING_RANK[a.timing] - TIMING_RANK[b.timing] || a.path.length - b.path.length;
|
|
52
|
+
}
|
|
53
|
+
function positiveInteger(value, name) {
|
|
54
|
+
if (value === undefined) {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
if (typeof value !== 'number' || !Number.isInteger(value) || value < 1) {
|
|
58
|
+
throw new Error(`${name} must be a positive integer`);
|
|
59
|
+
}
|
|
60
|
+
return value;
|
|
61
|
+
}
|
|
62
|
+
function stringList(value, name) {
|
|
63
|
+
if (value === undefined) {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
const valid = Array.isArray(value) && value.every((v) => typeof v === 'string');
|
|
67
|
+
if (!valid) {
|
|
68
|
+
throw new Error(`${name} must be an array of strings`);
|
|
69
|
+
}
|
|
70
|
+
return value;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* MCP tool that reports what runs at application startup.
|
|
74
|
+
*/
|
|
75
|
+
export class GetBootstrapExecutionTool {
|
|
76
|
+
projects;
|
|
77
|
+
name = 'get-bootstrap-execution';
|
|
78
|
+
title = 'Get Bootstrap Execution';
|
|
79
|
+
annotations = {
|
|
80
|
+
readOnlyHint: true,
|
|
81
|
+
destructiveHint: false,
|
|
82
|
+
idempotentHint: true,
|
|
83
|
+
openWorldHint: false,
|
|
84
|
+
};
|
|
85
|
+
constructor(projects = new ProjectCache()) {
|
|
86
|
+
this.projects = projects;
|
|
87
|
+
}
|
|
88
|
+
description = 'List what an Angular app executes at startup and whether it touches a given expression. Roots: ' +
|
|
89
|
+
'provideAppInitializer/provideEnvironmentInitializer/providePlatformInitializer and APP_INITIALIZER-style ' +
|
|
90
|
+
'provider literals (timing "initializer", finish before "bootstrap"), bootstrapApplication/bootstrapModule ' +
|
|
91
|
+
'("bootstrap"), HTTP_INTERCEPTORS classes and withInterceptors functions ("first-http-request", can happen ' +
|
|
92
|
+
'inside an initializer that uses HttpClient), other useFactory providers ("first-injection"). From each root ' +
|
|
93
|
+
'it walks calls (incl. constructors, field initializers, getters) and DI: inject(X), constructor parameters, ' +
|
|
94
|
+
'@Inject(TOKEN) and factory deps, with tokens resolved to the providers registered in the project. watch ' +
|
|
95
|
+
'(e.g. ["AppConfig.settings"]) reports every reachable read/write with the call path from the root, which ' +
|
|
96
|
+
'catches reads hidden behind constructors and getters that search-codebase cannot see. method + file start ' +
|
|
97
|
+
'from one callable instead (e.g. "AuthInterceptor.constructor"). Roots are found by scanning source files, ' +
|
|
98
|
+
'not by evaluating which providers are registered; spec files are skipped. Start with summaryOnly; ' +
|
|
99
|
+
'maxResults caps the reached list per root and the watch hits.';
|
|
100
|
+
inputSchema = {
|
|
101
|
+
type: 'object',
|
|
102
|
+
additionalProperties: false,
|
|
103
|
+
properties: {
|
|
104
|
+
projectRoot: {
|
|
105
|
+
type: 'string',
|
|
106
|
+
description: 'Absolute path to the project root. Must contain a tsconfig.json.',
|
|
107
|
+
},
|
|
108
|
+
watch: {
|
|
109
|
+
type: 'array',
|
|
110
|
+
items: { type: 'string' },
|
|
111
|
+
description: 'Expressions whose reads and writes to report, matched by text (optional chaining ignored), e.g. ["AppConfig.settings"].',
|
|
112
|
+
},
|
|
113
|
+
timings: {
|
|
114
|
+
type: 'array',
|
|
115
|
+
items: { type: 'string', enum: [...TIMINGS] },
|
|
116
|
+
description: 'Only roots with these timings. Default: all.',
|
|
117
|
+
},
|
|
118
|
+
file: {
|
|
119
|
+
type: 'string',
|
|
120
|
+
description: 'Only roots registered in this file; with method, the file declaring it (absolute, or relative to projectRoot).',
|
|
121
|
+
},
|
|
122
|
+
method: {
|
|
123
|
+
type: 'string',
|
|
124
|
+
description: 'Start from this callable instead of the discovered roots: "Class.constructor", "Class.member" or a function name. Needs file.',
|
|
125
|
+
},
|
|
126
|
+
depth: {
|
|
127
|
+
type: 'number',
|
|
128
|
+
description: 'Maximum call/injection distance from a root. Default: 8.',
|
|
129
|
+
},
|
|
130
|
+
maxNodes: {
|
|
131
|
+
type: 'number',
|
|
132
|
+
description: 'Maximum callables walked per root; a capped root is marked truncated. Default: 300.',
|
|
133
|
+
},
|
|
134
|
+
includeReached: {
|
|
135
|
+
type: 'boolean',
|
|
136
|
+
description: 'Include the reached callables per root. Default: true.',
|
|
137
|
+
default: true,
|
|
138
|
+
},
|
|
139
|
+
...COMPACT_OUTPUT_SCHEMA,
|
|
140
|
+
},
|
|
141
|
+
required: ['projectRoot'],
|
|
142
|
+
};
|
|
143
|
+
outputSchema = {
|
|
144
|
+
type: 'object',
|
|
145
|
+
properties: {
|
|
146
|
+
roots: {
|
|
147
|
+
type: 'array',
|
|
148
|
+
items: {
|
|
149
|
+
type: 'object',
|
|
150
|
+
properties: {
|
|
151
|
+
kind: { type: 'string' },
|
|
152
|
+
timing: { type: 'string' },
|
|
153
|
+
label: { type: 'string' },
|
|
154
|
+
file: { type: 'string' },
|
|
155
|
+
line: { type: 'integer' },
|
|
156
|
+
unresolvedInjections: STRING_ARRAY,
|
|
157
|
+
truncated: { type: 'boolean' },
|
|
158
|
+
reached: {
|
|
159
|
+
type: 'array',
|
|
160
|
+
items: {
|
|
161
|
+
type: 'object',
|
|
162
|
+
properties: {
|
|
163
|
+
name: { type: 'string' },
|
|
164
|
+
kind: { type: 'string' },
|
|
165
|
+
file: { type: 'string' },
|
|
166
|
+
line: { type: 'integer' },
|
|
167
|
+
depth: { type: 'integer' },
|
|
168
|
+
via: { type: 'string' },
|
|
169
|
+
},
|
|
170
|
+
required: ['name', 'kind', 'file', 'line', 'depth', 'via'],
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
reachedCount: { type: 'integer' },
|
|
174
|
+
},
|
|
175
|
+
required: ['kind', 'timing', 'label', 'file', 'line', 'unresolvedInjections', 'truncated', 'reachedCount'],
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
watchHits: {
|
|
179
|
+
type: 'array',
|
|
180
|
+
items: {
|
|
181
|
+
type: 'object',
|
|
182
|
+
properties: {
|
|
183
|
+
watch: { type: 'string' },
|
|
184
|
+
access: { type: 'string' },
|
|
185
|
+
root: { type: 'string' },
|
|
186
|
+
timing: { type: 'string' },
|
|
187
|
+
path: STRING_ARRAY,
|
|
188
|
+
file: { type: 'string' },
|
|
189
|
+
line: { type: 'integer' },
|
|
190
|
+
snippet: { type: 'string' },
|
|
191
|
+
},
|
|
192
|
+
required: ['watch', 'access', 'root', 'timing', 'path', 'file', 'line', 'snippet'],
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
counts: {
|
|
196
|
+
type: 'object',
|
|
197
|
+
properties: {
|
|
198
|
+
roots: { type: 'integer' },
|
|
199
|
+
rootsByTiming: COUNT_OBJECT,
|
|
200
|
+
reached: { type: 'integer' },
|
|
201
|
+
watchHits: { type: 'integer' },
|
|
202
|
+
truncatedRoots: { type: 'integer' },
|
|
203
|
+
},
|
|
204
|
+
required: ['roots', 'rootsByTiming', 'reached', 'watchHits', 'truncatedRoots'],
|
|
205
|
+
},
|
|
206
|
+
truncated: { type: 'boolean' },
|
|
207
|
+
summary: { type: 'string' },
|
|
208
|
+
tsConfigPath: { type: 'string' },
|
|
209
|
+
...WARNINGS_OUTPUT_SCHEMA,
|
|
210
|
+
},
|
|
211
|
+
required: ['counts', 'truncated', 'summary', 'tsConfigPath'],
|
|
212
|
+
};
|
|
213
|
+
async execute(args) {
|
|
214
|
+
const params = args;
|
|
215
|
+
if (!params.projectRoot) {
|
|
216
|
+
throw new Error('projectRoot is required');
|
|
217
|
+
}
|
|
218
|
+
const compact = parseCompactOptions(args);
|
|
219
|
+
const watch = stringList(params.watch, 'watch');
|
|
220
|
+
const timings = stringList(params.timings, 'timings');
|
|
221
|
+
const unknownTiming = timings?.find((t) => !TIMINGS.includes(t));
|
|
222
|
+
if (unknownTiming !== undefined) {
|
|
223
|
+
throw new Error(`unknown timing: ${unknownTiming}`);
|
|
224
|
+
}
|
|
225
|
+
const depth = positiveInteger(params.depth, 'depth');
|
|
226
|
+
const maxNodes = positiveInteger(params.maxNodes, 'maxNodes');
|
|
227
|
+
if (params.method !== undefined && params.file === undefined) {
|
|
228
|
+
throw new Error('method needs file');
|
|
229
|
+
}
|
|
230
|
+
if (!existsSync(params.projectRoot)) {
|
|
231
|
+
throw new Error(`projectRoot does not exist: ${params.projectRoot}`);
|
|
232
|
+
}
|
|
233
|
+
const tsConfigPath = findTsConfig(params.projectRoot);
|
|
234
|
+
if (!tsConfigPath) {
|
|
235
|
+
throw new Error(`tsconfig.json not found in projectRoot: ${params.projectRoot}`);
|
|
236
|
+
}
|
|
237
|
+
const file = params.file === undefined || isAbsolute(params.file)
|
|
238
|
+
? params.file
|
|
239
|
+
: resolve(params.projectRoot, params.file);
|
|
240
|
+
const result = new BootstrapExecutionAnalyzer(this.projects.get(tsConfigPath)).analyze({
|
|
241
|
+
...(watch === undefined ? {} : { watch }),
|
|
242
|
+
...(timings === undefined ? {} : { timings: timings }),
|
|
243
|
+
...(file === undefined ? {} : { file }),
|
|
244
|
+
...(params.method === undefined ? {} : { method: params.method }),
|
|
245
|
+
...(depth === undefined ? {} : { depth }),
|
|
246
|
+
...(maxNodes === undefined ? {} : { maxNodes }),
|
|
247
|
+
});
|
|
248
|
+
const summary = this.buildSummary(result, params.projectRoot, watch ?? [], params.method);
|
|
249
|
+
const warnings = this.projects.warnings(tsConfigPath);
|
|
250
|
+
if (compact.summaryOnly) {
|
|
251
|
+
return withWarnings({ counts: result.counts, truncated: false, summary, tsConfigPath }, warnings);
|
|
252
|
+
}
|
|
253
|
+
const includeReached = params.includeReached !== false;
|
|
254
|
+
let truncated = false;
|
|
255
|
+
const roots = result.roots.map((root) => {
|
|
256
|
+
const { reached, ...rest } = root;
|
|
257
|
+
if (!includeReached) {
|
|
258
|
+
return { ...rest, reachedCount: reached.length };
|
|
259
|
+
}
|
|
260
|
+
const shown = limitList(reached, compact.maxResults);
|
|
261
|
+
truncated ||= shown.truncated;
|
|
262
|
+
return { ...rest, reached: shown.items, reachedCount: reached.length };
|
|
263
|
+
});
|
|
264
|
+
const hits = limitList(result.watchHits, compact.maxResults);
|
|
265
|
+
truncated ||= hits.truncated;
|
|
266
|
+
return withWarnings({
|
|
267
|
+
roots,
|
|
268
|
+
watchHits: hits.items,
|
|
269
|
+
counts: result.counts,
|
|
270
|
+
truncated,
|
|
271
|
+
summary,
|
|
272
|
+
tsConfigPath,
|
|
273
|
+
}, warnings);
|
|
274
|
+
}
|
|
275
|
+
buildSummary(result, projectRoot, watch, method) {
|
|
276
|
+
if (result.roots.length === 0) {
|
|
277
|
+
return method !== undefined
|
|
278
|
+
? `Callable '${method}' not found in the given file.`
|
|
279
|
+
: 'No bootstrap roots found (no initializers, bootstrapApplication/bootstrapModule, interceptors or factory providers in the tsconfig program).';
|
|
280
|
+
}
|
|
281
|
+
const rel = (f) => relative(projectRoot, f);
|
|
282
|
+
const timings = Object.entries(result.counts.rootsByTiming)
|
|
283
|
+
.map(([t, n]) => `${t} ${n}`)
|
|
284
|
+
.join(', ');
|
|
285
|
+
const lines = [
|
|
286
|
+
`${result.counts.roots} root(s) (${timings}), ${result.counts.reached} callables reached` +
|
|
287
|
+
(result.counts.truncatedRoots > 0 ? `, ${result.counts.truncatedRoots} root(s) truncated by maxNodes` : '') +
|
|
288
|
+
'.',
|
|
289
|
+
];
|
|
290
|
+
for (const expression of watch) {
|
|
291
|
+
const hits = result.watchHits.filter((h) => h.watch === normalizeWatchExpression(expression));
|
|
292
|
+
if (hits.length === 0) {
|
|
293
|
+
lines.push(`${expression}: not accessed from any root.`);
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
const sites = new Map();
|
|
297
|
+
for (const h of [...hits].sort(earliestFirst)) {
|
|
298
|
+
const key = `${rel(h.file)}:${h.line}`;
|
|
299
|
+
sites.set(key, [...(sites.get(key) ?? []), h]);
|
|
300
|
+
}
|
|
301
|
+
const early = hits.filter((h) => h.timing === 'initializer' || h.timing === 'first-http-request');
|
|
302
|
+
lines.push(`${expression}: ${sites.size} access site(s) reachable, ${early.length} path(s) from initializer or interceptor roots.`);
|
|
303
|
+
const ordered = [...sites].sort(([, a], [, b]) => {
|
|
304
|
+
const [firstA] = a;
|
|
305
|
+
const [firstB] = b;
|
|
306
|
+
return firstA === undefined || firstB === undefined ? 0 : earliestFirst(firstA, firstB);
|
|
307
|
+
});
|
|
308
|
+
for (const [site, siteHits] of ordered.slice(0, SUMMARY_MAX_SITES)) {
|
|
309
|
+
const first = siteHits[0];
|
|
310
|
+
if (first === undefined) {
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
const roots = [...new Set(siteHits.map((h) => h.timing))].join('/');
|
|
314
|
+
// siteHits is sorted earliest first, so this is the path that runs soonest.
|
|
315
|
+
lines.push(` ${first.access} ${site} [${roots}] via ${first.path.join(' > ')}`);
|
|
316
|
+
}
|
|
317
|
+
if (sites.size > SUMMARY_MAX_SITES) {
|
|
318
|
+
lines.push(` ... ${sites.size - SUMMARY_MAX_SITES} more site(s) in watchHits`);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
return lines.join('\n');
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
//# sourceMappingURL=get-bootstrap-execution.js.map
|
|
@@ -10,6 +10,11 @@
|
|
|
10
10
|
* propagates through the call hierarchy. Useful for determining blast radius
|
|
11
11
|
* before proposing a bug fix.
|
|
12
12
|
*
|
|
13
|
+
* The graph is capped at `maxNodes` (default 200); a capped result carries
|
|
14
|
+
* `truncated: true` and a hint in the summary. Callers are not expanded
|
|
15
|
+
* through lifecycle hooks or interface members of foreign classes unless
|
|
16
|
+
* `includeLifecycleHooks` is set. Projects are cached per tsconfig.
|
|
17
|
+
*
|
|
13
18
|
* @example
|
|
14
19
|
* ```typescript
|
|
15
20
|
* // Via MCP:
|
|
@@ -19,16 +24,27 @@
|
|
|
19
24
|
* // projectRoot: '/project', direction: 'down', depth: 4 }
|
|
20
25
|
* ```
|
|
21
26
|
*/
|
|
22
|
-
import { type MCPTool } from '../types.js';
|
|
27
|
+
import { type MCPTool, type ToolAnnotations } from '../types.js';
|
|
23
28
|
import { type CallGraphResult } from '@angular-modernizer/api';
|
|
29
|
+
import { ProjectCache } from './helpers/project-cache.js';
|
|
30
|
+
/** Tool output: the call graph (trees omitted with `summaryOnly`) plus a text summary. */
|
|
31
|
+
export type GetCallGraphOutput = Omit<CallGraphResult, 'callers' | 'callees'> & Partial<Pick<CallGraphResult, 'callers' | 'callees'>> & {
|
|
32
|
+
summary: string;
|
|
33
|
+
warnings?: string[];
|
|
34
|
+
};
|
|
24
35
|
/**
|
|
25
36
|
* MCP tool that builds a call graph for a named method or function.
|
|
26
37
|
*/
|
|
27
38
|
export declare class GetCallGraphTool implements MCPTool {
|
|
39
|
+
private readonly projects;
|
|
28
40
|
readonly name = "get-call-graph";
|
|
41
|
+
readonly title = "Get Call Graph";
|
|
42
|
+
readonly annotations: ToolAnnotations;
|
|
43
|
+
constructor(projects?: ProjectCache);
|
|
29
44
|
readonly description: string;
|
|
30
45
|
readonly inputSchema: {
|
|
31
46
|
type: string;
|
|
47
|
+
additionalProperties: boolean;
|
|
32
48
|
properties: {
|
|
33
49
|
method: {
|
|
34
50
|
type: string;
|
|
@@ -53,13 +69,132 @@ export declare class GetCallGraphTool implements MCPTool {
|
|
|
53
69
|
description: string;
|
|
54
70
|
default: number;
|
|
55
71
|
};
|
|
72
|
+
maxNodes: {
|
|
73
|
+
type: string;
|
|
74
|
+
description: string;
|
|
75
|
+
default: number;
|
|
76
|
+
};
|
|
77
|
+
includeLifecycleHooks: {
|
|
78
|
+
type: string;
|
|
79
|
+
description: string;
|
|
80
|
+
default: boolean;
|
|
81
|
+
};
|
|
82
|
+
summaryOnly: {
|
|
83
|
+
type: string;
|
|
84
|
+
description: string;
|
|
85
|
+
default: boolean;
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
required: string[];
|
|
89
|
+
};
|
|
90
|
+
readonly outputSchema: {
|
|
91
|
+
type: string;
|
|
92
|
+
$defs: {
|
|
93
|
+
callNode: {
|
|
94
|
+
type: string;
|
|
95
|
+
properties: {
|
|
96
|
+
children: {
|
|
97
|
+
type: string;
|
|
98
|
+
items: {
|
|
99
|
+
$ref: string;
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
name: {
|
|
103
|
+
readonly type: "string";
|
|
104
|
+
};
|
|
105
|
+
file: {
|
|
106
|
+
readonly type: "string";
|
|
107
|
+
};
|
|
108
|
+
line: {
|
|
109
|
+
readonly type: "integer";
|
|
110
|
+
};
|
|
111
|
+
kind: {
|
|
112
|
+
readonly type: "string";
|
|
113
|
+
};
|
|
114
|
+
className: {
|
|
115
|
+
readonly type: "string";
|
|
116
|
+
};
|
|
117
|
+
snippet: {
|
|
118
|
+
readonly type: "string";
|
|
119
|
+
};
|
|
120
|
+
inheritedFrom: {
|
|
121
|
+
readonly type: "string";
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
required: string[];
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
properties: {
|
|
128
|
+
warnings: {
|
|
129
|
+
readonly type: "array";
|
|
130
|
+
readonly items: {
|
|
131
|
+
readonly type: "string";
|
|
132
|
+
};
|
|
133
|
+
readonly description: "Conditions that can make the result incomplete, e.g. library imports that do not resolve because node_modules is missing.";
|
|
134
|
+
};
|
|
135
|
+
target: {
|
|
136
|
+
type: string[];
|
|
137
|
+
properties: {
|
|
138
|
+
readonly name: {
|
|
139
|
+
readonly type: "string";
|
|
140
|
+
};
|
|
141
|
+
readonly file: {
|
|
142
|
+
readonly type: "string";
|
|
143
|
+
};
|
|
144
|
+
readonly line: {
|
|
145
|
+
readonly type: "integer";
|
|
146
|
+
};
|
|
147
|
+
readonly kind: {
|
|
148
|
+
readonly type: "string";
|
|
149
|
+
};
|
|
150
|
+
readonly className: {
|
|
151
|
+
readonly type: "string";
|
|
152
|
+
};
|
|
153
|
+
readonly snippet: {
|
|
154
|
+
readonly type: "string";
|
|
155
|
+
};
|
|
156
|
+
readonly inheritedFrom: {
|
|
157
|
+
readonly type: "string";
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
required: string[];
|
|
161
|
+
};
|
|
162
|
+
callers: {
|
|
163
|
+
type: string;
|
|
164
|
+
items: {
|
|
165
|
+
$ref: string;
|
|
166
|
+
};
|
|
167
|
+
};
|
|
168
|
+
callees: {
|
|
169
|
+
type: string;
|
|
170
|
+
items: {
|
|
171
|
+
$ref: string;
|
|
172
|
+
};
|
|
173
|
+
};
|
|
174
|
+
nodeCount: {
|
|
175
|
+
type: string;
|
|
176
|
+
};
|
|
177
|
+
truncated: {
|
|
178
|
+
type: string;
|
|
179
|
+
};
|
|
180
|
+
truncatedAt: {
|
|
181
|
+
type: string;
|
|
182
|
+
};
|
|
183
|
+
summary: {
|
|
184
|
+
type: string;
|
|
185
|
+
};
|
|
56
186
|
};
|
|
57
187
|
required: string[];
|
|
58
188
|
};
|
|
59
|
-
execute(args: Record<string, unknown>): Promise<
|
|
60
|
-
summary: string;
|
|
61
|
-
}>;
|
|
189
|
+
execute(args: Record<string, unknown>): Promise<GetCallGraphOutput>;
|
|
62
190
|
private buildSummary;
|
|
191
|
+
/**
|
|
192
|
+
* Summary lines for the direct callers or callees, at most
|
|
193
|
+
* {@link SUMMARY_MAX_NODES}: a wide fan-in (500 callers on a large app)
|
|
194
|
+
* made the summary about as large as the tree itself, and the summary is
|
|
195
|
+
* sent as text next to `structuredContent`.
|
|
196
|
+
*/
|
|
197
|
+
private listNodes;
|
|
63
198
|
private label;
|
|
64
199
|
}
|
|
65
200
|
//# sourceMappingURL=get-call-graph.d.ts.map
|