@angular-modernizer/adapter-mcp 0.2.0 → 0.3.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 +103 -35
- package/dist/cli.js +64 -14
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp-watcher.d.ts.map +1 -1
- package/dist/mcp-watcher.js +3 -0
- package/dist/mcp-watcher.js.map +1 -1
- package/dist/server/json-rpc-handler.d.ts +41 -0
- package/dist/server/json-rpc-handler.d.ts.map +1 -1
- package/dist/server/json-rpc-handler.js +85 -6
- package/dist/server/json-rpc-handler.js.map +1 -1
- package/dist/server/mcp-server.d.ts +31 -0
- package/dist/server/mcp-server.d.ts.map +1 -1
- package/dist/server/mcp-server.js +76 -23
- package/dist/server/mcp-server.js.map +1 -1
- package/dist/server/stdio-guard.d.ts +20 -0
- package/dist/server/stdio-guard.d.ts.map +1 -0
- package/dist/server/stdio-guard.js +48 -0
- package/dist/server/stdio-guard.js.map +1 -0
- package/dist/tools/analyze-build-impact.d.ts +126 -13
- package/dist/tools/analyze-build-impact.d.ts.map +1 -1
- package/dist/tools/analyze-build-impact.js +172 -30
- package/dist/tools/analyze-build-impact.js.map +1 -1
- package/dist/tools/find-angular-symbol.d.ts +29 -6
- package/dist/tools/find-angular-symbol.d.ts.map +1 -1
- package/dist/tools/find-angular-symbol.js +51 -6
- package/dist/tools/find-angular-symbol.js.map +1 -1
- package/dist/tools/find-component-hosts.d.ts +114 -0
- package/dist/tools/find-component-hosts.d.ts.map +1 -0
- package/dist/tools/find-component-hosts.js +240 -0
- package/dist/tools/find-component-hosts.js.map +1 -0
- package/dist/tools/find-usages.d.ts +20 -3
- package/dist/tools/find-usages.d.ts.map +1 -1
- package/dist/tools/find-usages.js +71 -8
- package/dist/tools/find-usages.js.map +1 -1
- package/dist/tools/get-bootstrap-execution.d.ts +108 -0
- package/dist/tools/get-bootstrap-execution.d.ts.map +1 -0
- package/dist/tools/get-bootstrap-execution.js +243 -0
- package/dist/tools/get-bootstrap-execution.js.map +1 -0
- package/dist/tools/get-call-graph.d.ts +28 -3
- package/dist/tools/get-call-graph.d.ts.map +1 -1
- package/dist/tools/get-call-graph.js +55 -7
- package/dist/tools/get-call-graph.js.map +1 -1
- package/dist/tools/helpers/compact-output.d.ts +61 -0
- package/dist/tools/helpers/compact-output.d.ts.map +1 -0
- package/dist/tools/helpers/compact-output.js +83 -0
- package/dist/tools/helpers/compact-output.js.map +1 -0
- package/dist/tools/helpers/project-cache.d.ts +177 -0
- package/dist/tools/helpers/project-cache.d.ts.map +1 -0
- package/dist/tools/helpers/project-cache.js +313 -0
- package/dist/tools/helpers/project-cache.js.map +1 -0
- package/dist/tools/helpers/rule-runner.d.ts +67 -0
- package/dist/tools/helpers/rule-runner.d.ts.map +1 -0
- package/dist/tools/helpers/rule-runner.js +117 -0
- package/dist/tools/helpers/rule-runner.js.map +1 -0
- package/dist/tools/helpers/scan-plan.d.ts +45 -0
- package/dist/tools/helpers/scan-plan.d.ts.map +1 -0
- package/dist/tools/helpers/scan-plan.js +151 -0
- package/dist/tools/helpers/scan-plan.js.map +1 -0
- package/dist/tools/helpers/stack-frame-file-index.d.ts +10 -0
- package/dist/tools/helpers/stack-frame-file-index.d.ts.map +1 -0
- package/dist/tools/helpers/stack-frame-file-index.js +71 -0
- package/dist/tools/helpers/stack-frame-file-index.js.map +1 -0
- package/dist/tools/inspect-form-group.d.ts +93 -0
- package/dist/tools/inspect-form-group.d.ts.map +1 -0
- package/dist/tools/inspect-form-group.js +161 -0
- package/dist/tools/inspect-form-group.js.map +1 -0
- package/dist/tools/inspect-i18n.d.ts +85 -0
- package/dist/tools/inspect-i18n.d.ts.map +1 -0
- package/dist/tools/inspect-i18n.js +203 -0
- package/dist/tools/inspect-i18n.js.map +1 -0
- package/dist/tools/inspect-template.d.ts +89 -0
- package/dist/tools/inspect-template.d.ts.map +1 -0
- package/dist/tools/inspect-template.js +166 -0
- package/dist/tools/inspect-template.js.map +1 -0
- package/dist/tools/list-imports.d.ts +17 -1
- package/dist/tools/list-imports.d.ts.map +1 -1
- package/dist/tools/list-imports.js +22 -5
- package/dist/tools/list-imports.js.map +1 -1
- package/dist/tools/orchestrate-migration.d.ts +1 -0
- package/dist/tools/orchestrate-migration.d.ts.map +1 -1
- package/dist/tools/orchestrate-migration.js +33 -1
- package/dist/tools/orchestrate-migration.js.map +1 -1
- package/dist/tools/parse-stack-trace.d.ts +3 -1
- package/dist/tools/parse-stack-trace.d.ts.map +1 -1
- package/dist/tools/parse-stack-trace.js +18 -4
- package/dist/tools/parse-stack-trace.js.map +1 -1
- package/dist/tools/plan-migration.d.ts +89 -1
- package/dist/tools/plan-migration.d.ts.map +1 -1
- package/dist/tools/plan-migration.js +203 -7
- package/dist/tools/plan-migration.js.map +1 -1
- package/dist/tools/resolve-type.d.ts +3 -0
- package/dist/tools/resolve-type.d.ts.map +1 -1
- package/dist/tools/resolve-type.js +6 -2
- package/dist/tools/resolve-type.js.map +1 -1
- package/dist/tools/scan-all.d.ts +6 -6
- package/dist/tools/scan-all.d.ts.map +1 -1
- package/dist/tools/scan-all.js +7 -7
- package/dist/tools/scan-all.js.map +1 -1
- package/dist/tools/scan-angular.d.ts +1 -1
- package/dist/tools/scan-angular.js +1 -1
- package/dist/tools/scan-architecture.d.ts +25 -4
- package/dist/tools/scan-architecture.d.ts.map +1 -1
- package/dist/tools/scan-architecture.js +115 -134
- package/dist/tools/scan-architecture.js.map +1 -1
- package/dist/tools/scan-solid.d.ts +1 -1
- package/dist/tools/scan-solid.js +1 -1
- package/dist/tools/search-codebase.d.ts +3 -0
- package/dist/tools/search-codebase.d.ts.map +1 -1
- package/dist/tools/search-codebase.js +6 -2
- package/dist/tools/search-codebase.js.map +1 -1
- package/dist/tools/server-status.d.ts +96 -0
- package/dist/tools/server-status.d.ts.map +1 -0
- package/dist/tools/server-status.js +195 -0
- package/dist/tools/server-status.js.map +1 -0
- package/dist/tools/trace-output-flow.d.ts +111 -0
- package/dist/tools/trace-output-flow.d.ts.map +1 -0
- package/dist/tools/trace-output-flow.js +308 -0
- package/dist/tools/trace-output-flow.js.map +1 -0
- package/dist/types.d.ts +7 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +11 -11
|
@@ -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,21 +24,31 @@
|
|
|
19
24
|
* // projectRoot: '/project', direction: 'down', depth: 4 }
|
|
20
25
|
* ```
|
|
21
26
|
*/
|
|
22
|
-
import { Project } from 'ts-morph';
|
|
23
27
|
import { CallGraphBuilder, } from '@angular-modernizer/api';
|
|
24
28
|
import { existsSync } from 'node:fs';
|
|
25
29
|
import { findTsConfig } from './helpers/find-ts-config.js';
|
|
30
|
+
import { ProjectCache } from './helpers/project-cache.js';
|
|
26
31
|
/**
|
|
27
32
|
* MCP tool that builds a call graph for a named method or function.
|
|
28
33
|
*/
|
|
29
34
|
export class GetCallGraphTool {
|
|
35
|
+
projects;
|
|
30
36
|
name = 'get-call-graph';
|
|
37
|
+
constructor(projects = new ProjectCache()) {
|
|
38
|
+
this.projects = projects;
|
|
39
|
+
}
|
|
31
40
|
description = 'Build a caller/callee graph for a named method, function, constructor, ' +
|
|
32
41
|
'get/set accessor or arrow-function property. ' +
|
|
33
42
|
'Direction "up" shows who calls it, "down" shows what it calls, ' +
|
|
34
43
|
'"both" returns the full call tree. Configurable depth (default: 2). ' +
|
|
44
|
+
'Prefer "ClassName.method" and the narrowest direction you need. ' +
|
|
45
|
+
'The graph is capped at maxNodes (default 200); a capped result has truncated: true. ' +
|
|
46
|
+
'Callers are not expanded through Angular lifecycle hooks or interface members of foreign classes ' +
|
|
47
|
+
'(set includeLifecycleHooks to override). summaryOnly returns counts and direct neighbours only. ' +
|
|
35
48
|
'Callees are resolved via the type checker and include new X() (constructor incl. field initializers), ' +
|
|
36
49
|
'super(), and property reads that resolve to getters. ' +
|
|
50
|
+
'Callers of component members include calls from the component template as leaf nodes ' +
|
|
51
|
+
'(kind "template", template file and line, snippet). ' +
|
|
37
52
|
'Use method "ClassName.constructor" to see what runs transitively during construction. ' +
|
|
38
53
|
'Use after parse-stack-trace to trace error propagation through the call hierarchy.';
|
|
39
54
|
inputSchema = {
|
|
@@ -63,6 +78,23 @@ export class GetCallGraphTool {
|
|
|
63
78
|
description: 'How many levels deep to traverse. Default: 2.',
|
|
64
79
|
default: 2,
|
|
65
80
|
},
|
|
81
|
+
maxNodes: {
|
|
82
|
+
type: 'number',
|
|
83
|
+
description: 'Maximum number of nodes across callers and callees. Traversal stops at the cap and the ' +
|
|
84
|
+
'result is marked truncated. Default: 200.',
|
|
85
|
+
default: 200,
|
|
86
|
+
},
|
|
87
|
+
includeLifecycleHooks: {
|
|
88
|
+
type: 'boolean',
|
|
89
|
+
description: 'Expand callers through Angular lifecycle hooks and implements-interface members of other ' +
|
|
90
|
+
'classes (e.g. every ngOnInit in the program). Default: false.',
|
|
91
|
+
default: false,
|
|
92
|
+
},
|
|
93
|
+
summaryOnly: {
|
|
94
|
+
type: 'boolean',
|
|
95
|
+
description: 'Return target, counts and the text summary without the callers/callees trees. Default: false.',
|
|
96
|
+
default: false,
|
|
97
|
+
},
|
|
66
98
|
},
|
|
67
99
|
required: ['method', 'file', 'projectRoot'],
|
|
68
100
|
};
|
|
@@ -84,17 +116,24 @@ export class GetCallGraphTool {
|
|
|
84
116
|
if (!tsConfigPath) {
|
|
85
117
|
throw new Error(`tsconfig.json not found in projectRoot: ${params.projectRoot}`);
|
|
86
118
|
}
|
|
87
|
-
|
|
88
|
-
|
|
119
|
+
if (params.maxNodes !== undefined &&
|
|
120
|
+
(!Number.isInteger(params.maxNodes) || params.maxNodes < 1)) {
|
|
121
|
+
throw new Error('maxNodes must be a positive integer');
|
|
122
|
+
}
|
|
123
|
+
const graphBuilder = new CallGraphBuilder(this.projects.get(tsConfigPath));
|
|
89
124
|
const options = {
|
|
90
125
|
direction: params.direction ?? 'both',
|
|
91
126
|
depth: params.depth ?? 2,
|
|
127
|
+
maxNodes: params.maxNodes ?? 200,
|
|
128
|
+
includeLifecycleHooks: params.includeLifecycleHooks ?? false,
|
|
92
129
|
};
|
|
93
130
|
const result = graphBuilder.buildCallGraph(params.method, params.file, options);
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
131
|
+
const summary = this.buildSummary(params.method, result);
|
|
132
|
+
if (params.summaryOnly) {
|
|
133
|
+
const { callers: _callers, callees: _callees, ...rest } = result;
|
|
134
|
+
return { ...rest, summary };
|
|
135
|
+
}
|
|
136
|
+
return { ...result, summary };
|
|
98
137
|
}
|
|
99
138
|
buildSummary(method, result) {
|
|
100
139
|
if (!result.target) {
|
|
@@ -102,7 +141,13 @@ export class GetCallGraphTool {
|
|
|
102
141
|
}
|
|
103
142
|
const lines = [
|
|
104
143
|
`Call graph for '${method}' at ${result.target.file}:${result.target.line}`,
|
|
144
|
+
`Nodes: ${result.nodeCount}`,
|
|
105
145
|
];
|
|
146
|
+
if (result.truncated) {
|
|
147
|
+
lines.push(`\nTRUNCATED at ${result.truncatedAt ?? result.nodeCount} nodes (maxNodes). The trees are a valid ` +
|
|
148
|
+
'but incomplete prefix. Narrow the query: class-qualified method, direction "up" or "down", ' +
|
|
149
|
+
'lower depth, or raise maxNodes.');
|
|
150
|
+
}
|
|
106
151
|
if (result.callers.length > 0) {
|
|
107
152
|
lines.push(`\nCallers (${result.callers.length}):`);
|
|
108
153
|
for (const c of result.callers) {
|
|
@@ -124,6 +169,9 @@ export class GetCallGraphTool {
|
|
|
124
169
|
return lines.join('\n');
|
|
125
170
|
}
|
|
126
171
|
label(node) {
|
|
172
|
+
if (node.kind === 'template') {
|
|
173
|
+
return `template of ${node.className ?? 'component'}: ${node.snippet ?? ''}`;
|
|
174
|
+
}
|
|
127
175
|
const qualified = node.className
|
|
128
176
|
? `${node.className}.${node.name}`
|
|
129
177
|
: node.name;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-call-graph.js","sourceRoot":"","sources":["../../src/tools/get-call-graph.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"get-call-graph.js","sourceRoot":"","sources":["../../src/tools/get-call-graph.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAGH,OAAO,EACL,gBAAgB,GAIjB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAuD1D;;GAEG;AACH,MAAM,OAAO,gBAAgB;IAGE;IAFpB,IAAI,GAAG,gBAAgB,CAAC;IAEjC,YAA6B,WAAyB,IAAI,YAAY,EAAE;QAA3C,aAAQ,GAAR,QAAQ,CAAmC;IAAG,CAAC;IAEnE,WAAW,GAClB,yEAAyE;QACzE,+CAA+C;QAC/C,iEAAiE;QACjE,sEAAsE;QACtE,kEAAkE;QAClE,sFAAsF;QACtF,mGAAmG;QACnG,kGAAkG;QAClG,wGAAwG;QACxG,uDAAuD;QACvD,uFAAuF;QACvF,sDAAsD;QACtD,wFAAwF;QACxF,oFAAoF,CAAC;IAE9E,WAAW,GAAG;QACrB,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,MAAM,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E,CAAC;YAC9B,KAAK,CAAC,IAAI,CAAC,cAAc,MAAM,CAAC,OAAO,CAAC,MAAM,IAAI,CAAC,CAAC;YACpD,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;gBAC/B,KAAK,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC;YAC3D,CAAC;QACH,CAAC;aAAM,CAAC;YACN,KAAK,CAAC,IAAI,CAAC,iDAAiD,CAAC,CAAC;QAChE,CAAC;QAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAEO,KAAK,CAAC,IAAc;QAC1B,IAAI,IAAI,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;YAC7B,OAAO,eAAe,IAAI,CAAC,SAAS,IAAI,WAAW,KAAK,IAAI,CAAC,OAAO,IAAI,EAAE,EAAE,CAAC;QAC/E,CAAC;QACD,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS;YAC9B,CAAC,CAAC,GAAG,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,IAAI,EAAE;YAClC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;QACd,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QAC1E,OAAO,GAAG,SAAS,GAAG,IAAI,EAAE,CAAC;IAC/B,CAAC;CACF"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/adapter-mcp - Compact output
|
|
3
|
+
*
|
|
4
|
+
* Shared `summaryOnly` / `maxResults` handling for tools that return long
|
|
5
|
+
* lists (find-usages, find-angular-symbol, list-imports, analyze-build-impact).
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Contract for every tool that uses it:
|
|
9
|
+
* - `summaryOnly: true` omits the list fields and keeps counts and the text
|
|
10
|
+
* summary, so an agent can decide whether the full list is worth loading.
|
|
11
|
+
* - `maxResults: n` keeps the first `n` entries of each list and sets
|
|
12
|
+
* `truncated: true` when anything was cut. Counts always describe the full
|
|
13
|
+
* result, never the shortened list.
|
|
14
|
+
* Both are opt-in; without them the tools return everything, as before. The
|
|
15
|
+
* JSON-RPC handler's 4 MB limit stays the last line of defence.
|
|
16
|
+
*/
|
|
17
|
+
/** JSON schema entries for the two shared parameters. */
|
|
18
|
+
export declare const COMPACT_OUTPUT_SCHEMA: {
|
|
19
|
+
readonly summaryOnly: {
|
|
20
|
+
readonly type: "boolean";
|
|
21
|
+
readonly description: "Return counts and the text summary only, without the result list. Default: false.";
|
|
22
|
+
readonly default: false;
|
|
23
|
+
};
|
|
24
|
+
readonly maxResults: {
|
|
25
|
+
readonly type: "number";
|
|
26
|
+
readonly description: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
/** Parsed compact-output options. */
|
|
30
|
+
export interface CompactOptions {
|
|
31
|
+
summaryOnly: boolean;
|
|
32
|
+
maxResults: number | undefined;
|
|
33
|
+
}
|
|
34
|
+
/** A list shortened to `maxResults`. */
|
|
35
|
+
export interface LimitedList<T> {
|
|
36
|
+
items: T[];
|
|
37
|
+
truncated: boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Validates and reads `summaryOnly` and `maxResults` from raw tool arguments.
|
|
41
|
+
*
|
|
42
|
+
* @throws Error when `summaryOnly` is not a boolean or `maxResults` is not a
|
|
43
|
+
* positive integer.
|
|
44
|
+
*/
|
|
45
|
+
export declare function parseCompactOptions(args: Record<string, unknown>): CompactOptions;
|
|
46
|
+
/** Keeps the first `maxResults` entries of `items`. */
|
|
47
|
+
export declare function limitList<T>(items: readonly T[], maxResults: number | undefined): LimitedList<T>;
|
|
48
|
+
/** Summary line for a list cut by `maxResults`, or `undefined` if nothing was cut. */
|
|
49
|
+
export declare function truncationNote(shown: number, total: number, noun: string): string | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Counts files per directory prefix of at most `depth` segments, relative to
|
|
52
|
+
* `root`, sorted by count (descending) and then by name.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* countByDirectory(['/p/src/app/a/x.ts', '/p/src/app/a/y.ts'], '/p', 3);
|
|
57
|
+
* // { 'src/app/a': 2 }
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare function countByDirectory(files: readonly string[], root: string, depth: number): Record<string, number>;
|
|
61
|
+
//# sourceMappingURL=compact-output.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compact-output.d.ts","sourceRoot":"","sources":["../../../src/tools/helpers/compact-output.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,yDAAyD;AACzD,eAAO,MAAM,qBAAqB;;;;;;;;;;CAaxB,CAAC;AAEX,qCAAqC;AACrC,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,OAAO,CAAC;IACrB,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;CAChC;AAED,wCAAwC;AACxC,MAAM,WAAW,WAAW,CAAC,CAAC;IAC5B,KAAK,EAAE,CAAC,EAAE,CAAC;IACX,SAAS,EAAE,OAAO,CAAC;CACpB;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,cAAc,CAchB;AAED,uDAAuD;AACvD,wBAAgB,SAAS,CAAC,CAAC,EACzB,KAAK,EAAE,SAAS,CAAC,EAAE,EACnB,UAAU,EAAE,MAAM,GAAG,SAAS,GAC7B,WAAW,CAAC,CAAC,CAAC,CAKhB;AAED,sFAAsF;AACtF,wBAAgB,cAAc,CAC5B,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,GACX,MAAM,GAAG,SAAS,CAIpB;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,GACZ,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAYxB"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/adapter-mcp - Compact output
|
|
3
|
+
*
|
|
4
|
+
* Shared `summaryOnly` / `maxResults` handling for tools that return long
|
|
5
|
+
* lists (find-usages, find-angular-symbol, list-imports, analyze-build-impact).
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Contract for every tool that uses it:
|
|
9
|
+
* - `summaryOnly: true` omits the list fields and keeps counts and the text
|
|
10
|
+
* summary, so an agent can decide whether the full list is worth loading.
|
|
11
|
+
* - `maxResults: n` keeps the first `n` entries of each list and sets
|
|
12
|
+
* `truncated: true` when anything was cut. Counts always describe the full
|
|
13
|
+
* result, never the shortened list.
|
|
14
|
+
* Both are opt-in; without them the tools return everything, as before. The
|
|
15
|
+
* JSON-RPC handler's 4 MB limit stays the last line of defence.
|
|
16
|
+
*/
|
|
17
|
+
import { relative, sep } from 'node:path';
|
|
18
|
+
/** JSON schema entries for the two shared parameters. */
|
|
19
|
+
export const COMPACT_OUTPUT_SCHEMA = {
|
|
20
|
+
summaryOnly: {
|
|
21
|
+
type: 'boolean',
|
|
22
|
+
description: 'Return counts and the text summary only, without the result list. Default: false.',
|
|
23
|
+
default: false,
|
|
24
|
+
},
|
|
25
|
+
maxResults: {
|
|
26
|
+
type: 'number',
|
|
27
|
+
description: 'Return at most this many list entries; the result is then marked truncated and counts still ' +
|
|
28
|
+
'describe the full result. Default: no limit.',
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Validates and reads `summaryOnly` and `maxResults` from raw tool arguments.
|
|
33
|
+
*
|
|
34
|
+
* @throws Error when `summaryOnly` is not a boolean or `maxResults` is not a
|
|
35
|
+
* positive integer.
|
|
36
|
+
*/
|
|
37
|
+
export function parseCompactOptions(args) {
|
|
38
|
+
const { summaryOnly, maxResults } = args;
|
|
39
|
+
if (summaryOnly !== undefined && typeof summaryOnly !== 'boolean') {
|
|
40
|
+
throw new Error('summaryOnly must be a boolean');
|
|
41
|
+
}
|
|
42
|
+
if (maxResults !== undefined &&
|
|
43
|
+
(typeof maxResults !== 'number' ||
|
|
44
|
+
!Number.isInteger(maxResults) ||
|
|
45
|
+
maxResults < 1)) {
|
|
46
|
+
throw new Error('maxResults must be a positive integer');
|
|
47
|
+
}
|
|
48
|
+
return { summaryOnly: summaryOnly ?? false, maxResults };
|
|
49
|
+
}
|
|
50
|
+
/** Keeps the first `maxResults` entries of `items`. */
|
|
51
|
+
export function limitList(items, maxResults) {
|
|
52
|
+
if (maxResults === undefined || items.length <= maxResults) {
|
|
53
|
+
return { items: [...items], truncated: false };
|
|
54
|
+
}
|
|
55
|
+
return { items: items.slice(0, maxResults), truncated: true };
|
|
56
|
+
}
|
|
57
|
+
/** Summary line for a list cut by `maxResults`, or `undefined` if nothing was cut. */
|
|
58
|
+
export function truncationNote(shown, total, noun) {
|
|
59
|
+
return shown < total
|
|
60
|
+
? `Showing ${shown} of ${total} ${noun} (maxResults). Counts cover all ${total}.`
|
|
61
|
+
: undefined;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Counts files per directory prefix of at most `depth` segments, relative to
|
|
65
|
+
* `root`, sorted by count (descending) and then by name.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* countByDirectory(['/p/src/app/a/x.ts', '/p/src/app/a/y.ts'], '/p', 3);
|
|
70
|
+
* // { 'src/app/a': 2 }
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export function countByDirectory(files, root, depth) {
|
|
74
|
+
const counts = new Map();
|
|
75
|
+
for (const file of files) {
|
|
76
|
+
const segments = relative(root, file).split(sep).slice(0, -1);
|
|
77
|
+
const key = segments.slice(0, depth).join('/') || '.';
|
|
78
|
+
counts.set(key, (counts.get(key) ?? 0) + 1);
|
|
79
|
+
}
|
|
80
|
+
const sorted = [...counts].sort(([nameA, countA], [nameB, countB]) => countB - countA || nameA.localeCompare(nameB));
|
|
81
|
+
return Object.fromEntries(sorted);
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=compact-output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compact-output.js","sourceRoot":"","sources":["../../../src/tools/helpers/compact-output.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAE1C,yDAAyD;AACzD,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,WAAW,EAAE;QACX,IAAI,EAAE,SAAS;QACf,WAAW,EACT,mFAAmF;QACrF,OAAO,EAAE,KAAK;KACf;IACD,UAAU,EAAE;QACV,IAAI,EAAE,QAAQ;QACd,WAAW,EACT,8FAA8F;YAC9F,8CAA8C;KACjD;CACO,CAAC;AAcX;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CACjC,IAA6B;IAE7B,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;IACzC,IAAI,WAAW,KAAK,SAAS,IAAI,OAAO,WAAW,KAAK,SAAS,EAAE,CAAC;QAClE,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;IACnD,CAAC;IACD,IACE,UAAU,KAAK,SAAS;QACxB,CAAC,OAAO,UAAU,KAAK,QAAQ;YAC7B,CAAC,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC;YAC7B,UAAU,GAAG,CAAC,CAAC,EACjB,CAAC;QACD,MAAM,IAAI,KAAK,C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AAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAC9C,CAAC;IACD,MAAM,MAAM,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC,IAAI,CAC7B,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,EAAE,CACnC,MAAM,GAAG,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAChD,CAAC;IACF,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/adapter-mcp - Project Cache
|
|
3
|
+
*
|
|
4
|
+
* Keeps ts-morph `Project` instances alive across tool calls, keyed by the
|
|
5
|
+
* tsconfig path, so repeated investigation calls on the same workspace do not
|
|
6
|
+
* re-parse the whole program each time (seconds on a large Angular app).
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* Same idea as `SharedProjectManager` in core (one long-lived Project instead
|
|
10
|
+
* of one per call), but keyed per tsconfig because the MCP server can serve
|
|
11
|
+
* several workspaces in one session. An entry is rebuilt when the tsconfig
|
|
12
|
+
* mtime changes. Source files are kept current file by file: the mtime of
|
|
13
|
+
* every program file is recorded at load and compared on each `get()` (about
|
|
14
|
+
* 6 ms for ngUWI's 3939 files); changed files are re-read, deleted ones
|
|
15
|
+
* removed. The type checker then rebuilds lazily on the next query. Files
|
|
16
|
+
* that were not in the program at load (new files) need a tsconfig touch or a
|
|
17
|
+
* server restart.
|
|
18
|
+
*
|
|
19
|
+
* Two limits bound the cache: `maxEntries` projects, and `maxHeapMb` of V8
|
|
20
|
+
* heap, checked on every `get()` because a project keeps growing after the
|
|
21
|
+
* load as the type checker resolves more of it, and on a miss also before
|
|
22
|
+
* the load. Over either limit the least recently used project is evicted;
|
|
23
|
+
* the project being requested never is.
|
|
24
|
+
* The heap is the signal, not the RSS: dropping a Project frees its heap
|
|
25
|
+
* (the TypeScript program, checker and ts-morph wrappers hang off it and
|
|
26
|
+
* nothing else keeps them), but V8 does not reliably unmap the pages, so the
|
|
27
|
+
* RSS can stay at its peak after an eviction and an RSS limit would then
|
|
28
|
+
* evict everything on every call. Freed pages are reused by the next load.
|
|
29
|
+
* When node runs with `--expose-gc` the cache collects once the raw heap
|
|
30
|
+
* reading passes the limit and after each eviction, so garbage does not count
|
|
31
|
+
* against the cache; otherwise it subtracts the heap growth recorded when the
|
|
32
|
+
* evicted project was loaded, and garbage makes it evict earlier.
|
|
33
|
+
*/
|
|
34
|
+
import { Project } from 'ts-morph';
|
|
35
|
+
/** A cached project as reported by `server-status`. */
|
|
36
|
+
export interface CachedProjectInfo {
|
|
37
|
+
tsConfigPath: string;
|
|
38
|
+
sourceFiles: number;
|
|
39
|
+
loadedAt: string;
|
|
40
|
+
lastUsedAt: string;
|
|
41
|
+
/** Heap growth while the project was loaded, an estimate of its size. */
|
|
42
|
+
loadHeapMB: number;
|
|
43
|
+
/** Source files re-read or removed because they changed on disk. */
|
|
44
|
+
refreshedFiles: number;
|
|
45
|
+
lastRefreshAt?: string;
|
|
46
|
+
}
|
|
47
|
+
/** Why a project left the cache. */
|
|
48
|
+
export type EvictionReason = 'max-entries' | 'max-heap';
|
|
49
|
+
/** One eviction with the memory around it. */
|
|
50
|
+
export interface ProjectEviction {
|
|
51
|
+
tsConfigPath: string;
|
|
52
|
+
reason: EvictionReason;
|
|
53
|
+
at: string;
|
|
54
|
+
sourceFiles: number;
|
|
55
|
+
heapMB: {
|
|
56
|
+
before: number;
|
|
57
|
+
after: number;
|
|
58
|
+
};
|
|
59
|
+
rssMB: {
|
|
60
|
+
before: number;
|
|
61
|
+
after: number;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/** Evictions since the server started. */
|
|
65
|
+
export interface EvictionStats {
|
|
66
|
+
count: number;
|
|
67
|
+
last?: ProjectEviction;
|
|
68
|
+
}
|
|
69
|
+
/** Heap and RSS reader, plus a full collection when node exposes one. */
|
|
70
|
+
export interface MemoryProbe {
|
|
71
|
+
usage(): {
|
|
72
|
+
heapUsed: number;
|
|
73
|
+
rss: number;
|
|
74
|
+
};
|
|
75
|
+
collect?: () => void;
|
|
76
|
+
}
|
|
77
|
+
/** Limits of a project cache. */
|
|
78
|
+
export interface ProjectCacheLimits {
|
|
79
|
+
/** Most projects kept at once, at least 1. */
|
|
80
|
+
maxEntries: number;
|
|
81
|
+
/** Heap limit in MB checked after each load; 0 switches it off. */
|
|
82
|
+
maxHeapMb: number;
|
|
83
|
+
}
|
|
84
|
+
export interface ProjectCacheOptions extends Partial<ProjectCacheLimits> {
|
|
85
|
+
createProject?: (tsConfigFilePath: string) => Project;
|
|
86
|
+
memory?: MemoryProbe;
|
|
87
|
+
/** mtime of a file in ms, undefined when it cannot be read. */
|
|
88
|
+
statFile?: (filePath: string) => number | undefined;
|
|
89
|
+
}
|
|
90
|
+
/** Default number of workspaces kept in memory at once. */
|
|
91
|
+
export declare const DEFAULT_MAX_ENTRIES = 3;
|
|
92
|
+
/**
|
|
93
|
+
* Default heap limit. ngUWI (3939 files) takes 1.0 to 1.3 GB of heap once
|
|
94
|
+
* loaded and queried; V8's heap limit on the dev machines is about 4.1 GB.
|
|
95
|
+
* 2048 MB keeps ngUWI together with small workspaces, and evicts it before a
|
|
96
|
+
* second workspace of its size drives the process towards the V8 limit.
|
|
97
|
+
*/
|
|
98
|
+
export declare const DEFAULT_MAX_HEAP_MB = 2048;
|
|
99
|
+
/** Bytes to MB, one decimal. */
|
|
100
|
+
export declare function toMB(bytes: number): number;
|
|
101
|
+
/** LRU cache of ts-morph Projects keyed by tsconfig path. */
|
|
102
|
+
export declare class ProjectCache {
|
|
103
|
+
private readonly entries;
|
|
104
|
+
private readonly maxEntries;
|
|
105
|
+
private readonly maxHeapMb;
|
|
106
|
+
private readonly createProject;
|
|
107
|
+
private readonly memory;
|
|
108
|
+
private readonly statFile;
|
|
109
|
+
private evictionCount;
|
|
110
|
+
private lastEviction;
|
|
111
|
+
/**
|
|
112
|
+
* @param options - Limits, project factory and memory probe; tests inject
|
|
113
|
+
* the last two.
|
|
114
|
+
*/
|
|
115
|
+
constructor(options?: ProjectCacheOptions);
|
|
116
|
+
/** Returns the cached Project for `tsConfigPath`, building it on a miss. */
|
|
117
|
+
get(tsConfigPath: string): Project;
|
|
118
|
+
/** Number of cached projects. */
|
|
119
|
+
get size(): number;
|
|
120
|
+
/** Most projects kept at once. */
|
|
121
|
+
get capacity(): number;
|
|
122
|
+
/** Limits in effect. */
|
|
123
|
+
get limits(): ProjectCacheLimits;
|
|
124
|
+
/** Eviction count and the most recent eviction. */
|
|
125
|
+
get evictions(): EvictionStats;
|
|
126
|
+
/** Cached projects, least recently used first. */
|
|
127
|
+
describe(): CachedProjectInfo[];
|
|
128
|
+
/**
|
|
129
|
+
* Moves a fresh entry to the most recently used end and returns its
|
|
130
|
+
* project; drops a stale one. Kept apart from `get()` so no reference to a
|
|
131
|
+
* dropped entry is alive while `evictOverHeap` collects.
|
|
132
|
+
*/
|
|
133
|
+
private touch;
|
|
134
|
+
/** Re-reads program files whose mtime changed and removes deleted ones. */
|
|
135
|
+
private refreshChangedFiles;
|
|
136
|
+
private recordMtimes;
|
|
137
|
+
private load;
|
|
138
|
+
private evictOverCount;
|
|
139
|
+
/**
|
|
140
|
+
* Evicts least recently used projects, never `current`, until the heap is
|
|
141
|
+
* back under `maxHeapMb`. Under the limit this is one `memoryUsage()` call;
|
|
142
|
+
* over it, a collection runs first so garbage does not count.
|
|
143
|
+
*/
|
|
144
|
+
private evictOverHeap;
|
|
145
|
+
/** Drops `key`, records the eviction, returns the heap estimate after it. */
|
|
146
|
+
private evict;
|
|
147
|
+
/**
|
|
148
|
+
* Deletes `key` and returns the figures the eviction record needs. A
|
|
149
|
+
* separate frame, so the entry is unreachable once it returns and the
|
|
150
|
+
* following collection can free the project.
|
|
151
|
+
*/
|
|
152
|
+
private remove;
|
|
153
|
+
}
|
|
154
|
+
/** Command-line flags and environment variables for the cache limits. */
|
|
155
|
+
export declare const PROJECT_CACHE_FLAGS: {
|
|
156
|
+
readonly maxEntries: {
|
|
157
|
+
readonly flag: "--max-projects";
|
|
158
|
+
readonly env: "ANGULAR_MODERNIZER_MAX_PROJECTS";
|
|
159
|
+
};
|
|
160
|
+
readonly maxHeapMb: {
|
|
161
|
+
readonly flag: "--max-heap-mb";
|
|
162
|
+
readonly env: "ANGULAR_MODERNIZER_MAX_HEAP_MB";
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
/** Limits read from argv and env, plus warnings for rejected values. */
|
|
166
|
+
export interface ParsedProjectCacheLimits {
|
|
167
|
+
options: Partial<ProjectCacheLimits>;
|
|
168
|
+
warnings: string[];
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Reads the cache limits from `--max-projects` / `--max-heap-mb` (either
|
|
172
|
+
* `--flag=N` or `--flag N`) or their environment variables; the flag wins.
|
|
173
|
+
* `--max-heap-mb 0` switches the heap limit off. Invalid values are dropped
|
|
174
|
+
* with a warning so a typo does not stop the server.
|
|
175
|
+
*/
|
|
176
|
+
export declare function parseProjectCacheLimits(argv: readonly string[], env: Readonly<Record<string, string | undefined>>): ParsedProjectCacheLimits;
|
|
177
|
+
//# sourceMappingURL=project-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project-cache.d.ts","sourceRoot":"","sources":["../../../src/tools/helpers/project-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAenC,uDAAuD;AACvD,MAAM,WAAW,iBAAiB;IAChC,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IAEnB,yEAAyE;IACzE,UAAU,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