@angular-modernizer/adapter-mcp 1.1.0 → 1.2.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 +4 -2
- package/dist/index.d.ts +1 -1
- package/dist/tools/analyze-build-impact.d.ts +2 -2
- package/dist/tools/analyze-build-impact.js +6 -4
- package/dist/tools/analyze-project.d.ts +5 -2
- package/dist/tools/analyze-project.js +42 -21
- package/dist/tools/find-angular-symbol.d.ts +2 -2
- package/dist/tools/find-angular-symbol.js +3 -3
- package/dist/tools/find-component-hosts.d.ts +2 -2
- package/dist/tools/find-component-hosts.js +3 -3
- package/dist/tools/find-usages.d.ts +2 -2
- package/dist/tools/find-usages.js +3 -3
- package/dist/tools/get-bootstrap-execution.d.ts +2 -2
- package/dist/tools/get-bootstrap-execution.js +3 -3
- package/dist/tools/get-call-graph.d.ts +2 -2
- package/dist/tools/get-call-graph.js +3 -3
- package/dist/tools/helpers/project-cache.d.ts +73 -2
- package/dist/tools/helpers/project-cache.js +194 -9
- package/dist/tools/helpers/scan-plan.d.ts +1 -1
- package/dist/tools/helpers/scan-plan.js +1 -1
- package/dist/tools/inspect-form-group.d.ts +2 -2
- package/dist/tools/inspect-form-group.js +3 -3
- package/dist/tools/inspect-i18n.d.ts +3 -3
- package/dist/tools/inspect-i18n.js +3 -3
- package/dist/tools/inspect-template.d.ts +2 -2
- package/dist/tools/inspect-template.js +3 -3
- package/dist/tools/list-imports.d.ts +3 -3
- package/dist/tools/list-imports.js +3 -3
- package/dist/tools/plan-migration.d.ts +2 -2
- package/dist/tools/plan-migration.js +3 -2
- package/dist/tools/resolve-type.d.ts +2 -2
- package/dist/tools/resolve-type.js +3 -3
- package/dist/tools/search-codebase.d.ts +2 -2
- package/dist/tools/search-codebase.js +3 -3
- package/dist/tools/trace-output-flow.d.ts +2 -2
- package/dist/tools/trace-output-flow.js +3 -3
- package/dist/tools/transform-code.js +89 -13
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -463,7 +463,7 @@ Safety features (single file, batch and streaming alike):
|
|
|
463
463
|
- Type check of the transformed file: only errors the transformation introduced count (`validation.introducedTypeErrors`)
|
|
464
464
|
- Build validation (`validateBuild`), project lint only on request (`validateLint`)
|
|
465
465
|
- Automatic rollback when validation fails (`autoRollback`)
|
|
466
|
-
- Batch mode backs up all files first and applies `rollbackStrategy` (`all-or-nothing`, `selective`, `none`)
|
|
466
|
+
- Batch mode backs up all files first, type-checks every batch file after the last transformation against its errors before the first one (a file with an introduced error fails, `validation.introducedTypeErrors` lists `<file>: <error>`), and applies `rollbackStrategy` (`all-or-nothing`, `selective`, `none`) to failed files
|
|
467
467
|
- `rollback-changes` restores the same backups later (`strategy`: `auto`, `file-backup`, `git-stash`)
|
|
468
468
|
|
|
469
469
|
Validation parameters:
|
|
@@ -626,7 +626,8 @@ Per-tool defaults go under `tools` in `.angular-modernizer.json`; arguments of a
|
|
|
626
626
|
the configurable tools (scan-architecture, scan-all, scan-angular, scan-solid, analyze-project, transform-code,
|
|
627
627
|
transform-code-batch, run-build, validate-transformation, collect-feedback, review-feedback, suggest-improvements) and
|
|
628
628
|
their keys; `orchestration` takes a different set of keys per tool. Other tools, such as learn-patterns, take their
|
|
629
|
-
options per call only.
|
|
629
|
+
options per call only. analyze-project reads `tools.analyze-project` except `orchestration`: its `parallel` and
|
|
630
|
+
`incremental` select the deprecated WorkerPool path, which only the call argument can choose.
|
|
630
631
|
|
|
631
632
|
```json
|
|
632
633
|
{
|
|
@@ -806,6 +807,7 @@ Long-running tools report progress through MCP `notifications/progress` when the
|
|
|
806
807
|
| transform-code | single file: 3 steps (loaded, transformed, validated); batch: files | restores the backup (also with `autoRollback: false`); a batch restores every file |
|
|
807
808
|
| run-build, run-angular-cli, run-schematic, validate-transformation | none | ends the build with its process tree (SIGTERM, SIGKILL after 5 s) |
|
|
808
809
|
| orchestrate-migration | steps | passes the cancel to the running step, runs no further step |
|
|
810
|
+
| find-usages, get-call-graph, resolve-type, find-angular-symbol, search-codebase, list-imports, inspect-template, find-component-hosts, trace-output-flow, get-bootstrap-execution, inspect-form-group, inspect-i18n, analyze-build-impact, plan-migration | first call on a workspace: files loaded (`n/N files loaded`, per batch of 50) | stops the project load at the next batch, nothing is cached; program and checker build and the query are not interrupted |
|
|
809
811
|
|
|
810
812
|
A cancelled request gets no response (MCP spec). Scans also stop while they add their files to the project (checked per file). Only the kernel's own project load (`kernel.initialize()`) and transform-code's load of its file cannot be interrupted; the cancel takes effect right after them. Direct callers of a scan get the analyzed part with `execution.stopReason: 'cancelled'`.
|
|
811
813
|
|
package/dist/index.d.ts
CHANGED
|
@@ -160,7 +160,7 @@ export type { IncrementalMetadata as ValidateTransformationIncrementalMetadata }
|
|
|
160
160
|
export type { VerifiedCitation } from './tools/verify-citations.js';
|
|
161
161
|
export type { ScanCounts } from './tools/helpers/analysis-output.js';
|
|
162
162
|
export type { FileDelta, HealthViolation, RuleDelta, } from './tools/helpers/health-delta.js';
|
|
163
|
-
export type { CachedProjectInfo, EvictionReason, EvictionStats, ProjectCacheLimits, ProjectEviction, } from './tools/helpers/project-cache.js';
|
|
163
|
+
export type { AcquireControl, CachedProjectInfo, EvictionReason, EvictionStats, ProjectCacheLimits, ProjectEviction, } from './tools/helpers/project-cache.js';
|
|
164
164
|
export type { RuleTiming } from './tools/helpers/rule-runner.js';
|
|
165
165
|
export type { Performance, Suggestion } from './tools/helpers/suggestion-generator.js';
|
|
166
166
|
export type { CancelledExecution } from './tools/helpers/tool-context.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type MCPTool, type ToolAnnotations } from '../types.js';
|
|
1
|
+
import { type MCPTool, type ToolAnnotations, type ToolContext } from '../types.js';
|
|
2
2
|
import { type BuildScopeSymbolImpact } from '@angular-modernizer/core';
|
|
3
3
|
import { type TemplateEdge } from '@angular-modernizer/api';
|
|
4
4
|
import { type ProjectCache } from './helpers/project-cache.js';
|
|
@@ -492,7 +492,7 @@ export declare class AnalyzeBuildImpactTool implements MCPTool {
|
|
|
492
492
|
};
|
|
493
493
|
required: string[];
|
|
494
494
|
};
|
|
495
|
-
execute(args: Record<string, unknown
|
|
495
|
+
execute(args: Record<string, unknown>, ctx?: ToolContext): Promise<AnalyzeBuildImpactOutput>;
|
|
496
496
|
/**
|
|
497
497
|
* Splits the requested files into files of the TypeScript program, `.html`
|
|
498
498
|
* templates mapped to their component files, and files that fit neither.
|
|
@@ -4,6 +4,7 @@ import { findTemplateOwnerFiles, } from '@angular-modernizer/api';
|
|
|
4
4
|
import { existsSync } from 'node:fs';
|
|
5
5
|
import { join } from 'node:path';
|
|
6
6
|
import { findTsConfig } from './helpers/find-ts-config.js';
|
|
7
|
+
import { acquireProject } from './helpers/project-cache.js';
|
|
7
8
|
import { STRING_ARRAY } from './helpers/investigation-schemas.js';
|
|
8
9
|
import { WARNINGS_OUTPUT_SCHEMA, withWarnings } from './helpers/output-contract.js';
|
|
9
10
|
import { COMPACT_OUTPUT_SCHEMA, limitList, parseCompactOptions, } from './helpers/compact-output.js';
|
|
@@ -228,7 +229,7 @@ export class AnalyzeBuildImpactTool {
|
|
|
228
229
|
'summary',
|
|
229
230
|
],
|
|
230
231
|
};
|
|
231
|
-
async execute(args) {
|
|
232
|
+
async execute(args, ctx = {}) {
|
|
232
233
|
const params = args;
|
|
233
234
|
if (!params.projectPath) {
|
|
234
235
|
throw new Error('projectPath is required');
|
|
@@ -252,11 +253,12 @@ export class AnalyzeBuildImpactTool {
|
|
|
252
253
|
: [];
|
|
253
254
|
// Initialize ts-morph project
|
|
254
255
|
// Shared cache in the server (one parse per workspace); a fresh Project otherwise
|
|
255
|
-
const project = this.projects
|
|
256
|
-
new Project({
|
|
256
|
+
const project = this.projects === undefined
|
|
257
|
+
? new Project({
|
|
257
258
|
tsConfigFilePath: tsConfigPath,
|
|
258
259
|
skipAddingFilesFromTsConfig: false,
|
|
259
|
-
})
|
|
260
|
+
})
|
|
261
|
+
: await acquireProject(this.projects, tsConfigPath, ctx);
|
|
260
262
|
// Normalize file paths to absolute paths
|
|
261
263
|
const requestedFiles = filesToChange.map((file) => {
|
|
262
264
|
if (file.startsWith('/')) {
|
|
@@ -601,8 +601,11 @@ export declare class AnalyzeProjectTool implements MCPTool {
|
|
|
601
601
|
*/
|
|
602
602
|
private analyzeTsconfigPaths;
|
|
603
603
|
/**
|
|
604
|
-
*
|
|
605
|
-
*
|
|
604
|
+
* Settings of `tools.analyze-project` from the project's
|
|
605
|
+
* `.angular-modernizer.json` (only from the given root, never from the
|
|
606
|
+
* server's working directory). Only {@link CONFIG_KEYS} are taken; the
|
|
607
|
+
* config used to be read from a top-level `analyze-project` key, which the
|
|
608
|
+
* schema does not allow, so no setting ever applied.
|
|
606
609
|
*/
|
|
607
610
|
private loadConfig;
|
|
608
611
|
}
|
|
@@ -21,6 +21,14 @@ const NAMED_PROJECT_SCHEMA = {
|
|
|
21
21
|
},
|
|
22
22
|
required: ['name', 'root'],
|
|
23
23
|
};
|
|
24
|
+
/** Keys of `tools.analyze-project` taken from the config. */
|
|
25
|
+
const CONFIG_KEYS = [
|
|
26
|
+
'includeDetails',
|
|
27
|
+
'maxDepth',
|
|
28
|
+
'excludePatterns',
|
|
29
|
+
'maxResults',
|
|
30
|
+
'resultOffset',
|
|
31
|
+
];
|
|
24
32
|
/** Layers, projects and stack entries named in the summary. */
|
|
25
33
|
const SUMMARY_NAMES = 10;
|
|
26
34
|
/**
|
|
@@ -518,11 +526,11 @@ export class AnalyzeProjectTool {
|
|
|
518
526
|
}
|
|
519
527
|
// Apply pagination to results if includeDetails is true
|
|
520
528
|
const totalResults = results.length;
|
|
521
|
-
const maxResults =
|
|
522
|
-
const resultOffset =
|
|
529
|
+
const maxResults = mergedParams.maxResults ?? 1000;
|
|
530
|
+
const resultOffset = mergedParams.resultOffset ?? 0;
|
|
523
531
|
let paginatedResults = results;
|
|
524
532
|
let paginationMetadata;
|
|
525
|
-
if (
|
|
533
|
+
if (mergedParams.includeDetails) {
|
|
526
534
|
// Slice results for pagination
|
|
527
535
|
paginatedResults = results.slice(resultOffset, resultOffset + maxResults);
|
|
528
536
|
// Add pagination metadata
|
|
@@ -537,7 +545,7 @@ export class AnalyzeProjectTool {
|
|
|
537
545
|
framework,
|
|
538
546
|
architecture,
|
|
539
547
|
technologyStack,
|
|
540
|
-
results:
|
|
548
|
+
results: mergedParams.includeDetails ? paginatedResults : [],
|
|
541
549
|
counts: {
|
|
542
550
|
totalFiles: projectStructure.totalFiles,
|
|
543
551
|
analyzedFiles: filesAnalyzed,
|
|
@@ -1101,31 +1109,44 @@ export class AnalyzeProjectTool {
|
|
|
1101
1109
|
return layers;
|
|
1102
1110
|
}
|
|
1103
1111
|
/**
|
|
1104
|
-
*
|
|
1105
|
-
*
|
|
1112
|
+
* Settings of `tools.analyze-project` from the project's
|
|
1113
|
+
* `.angular-modernizer.json` (only from the given root, never from the
|
|
1114
|
+
* server's working directory). Only {@link CONFIG_KEYS} are taken; the
|
|
1115
|
+
* config used to be read from a top-level `analyze-project` key, which the
|
|
1116
|
+
* schema does not allow, so no setting ever applied.
|
|
1106
1117
|
*/
|
|
1107
1118
|
loadConfig(providedRootPath) {
|
|
1108
|
-
// Only load config if rootPath is explicitly provided
|
|
1109
|
-
// This prevents accidentally using process.cwd() which may point to the MCP server directory
|
|
1110
1119
|
if (!providedRootPath) {
|
|
1111
1120
|
return {};
|
|
1112
1121
|
}
|
|
1113
1122
|
const configPath = resolve(providedRootPath, '.angular-modernizer.json');
|
|
1114
|
-
if (existsSync(configPath)) {
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
}
|
|
1123
|
-
}
|
|
1124
|
-
catch (error) {
|
|
1125
|
-
console.warn(`Error loading config from ${configPath}:`, error);
|
|
1123
|
+
if (!existsSync(configPath)) {
|
|
1124
|
+
return {};
|
|
1125
|
+
}
|
|
1126
|
+
try {
|
|
1127
|
+
const config = JSON.parse(readFileSync(configPath, 'utf-8'));
|
|
1128
|
+
const section = toolSection(config, 'analyze-project');
|
|
1129
|
+
if (section === undefined) {
|
|
1130
|
+
return {};
|
|
1126
1131
|
}
|
|
1132
|
+
return Object.fromEntries(CONFIG_KEYS.filter((key) => section[key] !== undefined).map((key) => [
|
|
1133
|
+
key,
|
|
1134
|
+
section[key],
|
|
1135
|
+
]));
|
|
1136
|
+
}
|
|
1137
|
+
catch (error) {
|
|
1138
|
+
console.warn(`Error loading config from ${configPath}:`, error);
|
|
1139
|
+
return {};
|
|
1127
1140
|
}
|
|
1128
|
-
return {};
|
|
1129
1141
|
}
|
|
1130
1142
|
}
|
|
1143
|
+
/** `tools.<name>` of a parsed config, when it is an object. */
|
|
1144
|
+
function toolSection(config, name) {
|
|
1145
|
+
const tools = isRecord(config) ? config['tools'] : undefined;
|
|
1146
|
+
const section = isRecord(tools) ? tools[name] : undefined;
|
|
1147
|
+
return isRecord(section) ? section : undefined;
|
|
1148
|
+
}
|
|
1149
|
+
function isRecord(value) {
|
|
1150
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
1151
|
+
}
|
|
1131
1152
|
//# sourceMappingURL=analyze-project.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type MCPTool, type ToolAnnotations } from '../types.js';
|
|
1
|
+
import { type MCPTool, type ToolAnnotations, type ToolContext } from '../types.js';
|
|
2
2
|
import { type AngularSymbolResult, type AngularSymbolType } from '@angular-modernizer/api';
|
|
3
3
|
import { ProjectCache } from './helpers/project-cache.js';
|
|
4
4
|
/** Output of the find-angular-symbol tool. */
|
|
@@ -139,7 +139,7 @@ export declare class FindAngularSymbolTool implements MCPTool {
|
|
|
139
139
|
};
|
|
140
140
|
required: string[];
|
|
141
141
|
};
|
|
142
|
-
execute(args: Record<string, unknown
|
|
142
|
+
execute(args: Record<string, unknown>, ctx?: ToolContext): Promise<FindAngularSymbolOutput>;
|
|
143
143
|
private buildCompactSummary;
|
|
144
144
|
private buildSummary;
|
|
145
145
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AngularSymbolFinder, } from '@angular-modernizer/api';
|
|
2
2
|
import { existsSync } from 'node:fs';
|
|
3
3
|
import { findTsConfig } from './helpers/find-ts-config.js';
|
|
4
|
-
import { ProjectCache } from './helpers/project-cache.js';
|
|
4
|
+
import { ProjectCache, acquireProject } from './helpers/project-cache.js';
|
|
5
5
|
import { COMPACT_OUTPUT_SCHEMA, limitList, parseCompactOptions, truncationNote, } from './helpers/compact-output.js';
|
|
6
6
|
import { configuredComponentDecorators } from './helpers/project-decorators.js';
|
|
7
7
|
import { WARNINGS_OUTPUT_SCHEMA, withWarnings, } from './helpers/output-contract.js';
|
|
@@ -123,7 +123,7 @@ export class FindAngularSymbolTool {
|
|
|
123
123
|
},
|
|
124
124
|
required: ['totalCount', 'truncated', 'countsByType', 'summary'],
|
|
125
125
|
};
|
|
126
|
-
async execute(args) {
|
|
126
|
+
async execute(args, ctx = {}) {
|
|
127
127
|
const params = args;
|
|
128
128
|
if (!params.query) {
|
|
129
129
|
throw new Error('query is required');
|
|
@@ -139,7 +139,7 @@ export class FindAngularSymbolTool {
|
|
|
139
139
|
if (!tsConfigPath) {
|
|
140
140
|
throw new Error(`tsconfig.json not found in projectRoot: ${params.projectRoot}`);
|
|
141
141
|
}
|
|
142
|
-
const project = this.projects
|
|
142
|
+
const project = await acquireProject(this.projects, tsConfigPath, ctx);
|
|
143
143
|
const finder = new AngularSymbolFinder(project, {
|
|
144
144
|
componentDecorators: configuredComponentDecorators(params.projectRoot),
|
|
145
145
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type MCPTool, type ToolAnnotations } from '../types.js';
|
|
1
|
+
import { type MCPTool, type ToolAnnotations, type ToolContext } from '../types.js';
|
|
2
2
|
import { type BindingCoverage, type ComponentHost, type ComponentHostResult, type DynamicHost } from '@angular-modernizer/api';
|
|
3
3
|
import { ProjectCache } from './helpers/project-cache.js';
|
|
4
4
|
/** Coverage entry with the host name lists dropped (summaryOnly) or capped (maxResults). */
|
|
@@ -680,7 +680,7 @@ export declare class FindComponentHostsTool implements MCPTool {
|
|
|
680
680
|
};
|
|
681
681
|
required: string[];
|
|
682
682
|
};
|
|
683
|
-
execute(args: Record<string, unknown
|
|
683
|
+
execute(args: Record<string, unknown>, ctx?: ToolContext): Promise<FindComponentHostsOutput>;
|
|
684
684
|
private buildSummary;
|
|
685
685
|
private shapeCoverage;
|
|
686
686
|
/** `AppDialog.open 24, new AppDialogRef 2` */
|
|
@@ -2,7 +2,7 @@ import { ComponentHostFinder, } from '@angular-modernizer/api';
|
|
|
2
2
|
import { existsSync } from 'node:fs';
|
|
3
3
|
import { isAbsolute, resolve } from 'node:path';
|
|
4
4
|
import { findTsConfig } from './helpers/find-ts-config.js';
|
|
5
|
-
import { ProjectCache } from './helpers/project-cache.js';
|
|
5
|
+
import { ProjectCache, acquireProject } from './helpers/project-cache.js';
|
|
6
6
|
import { COMPACT_OUTPUT_SCHEMA, limitList, parseCompactOptions, truncationNote, } from './helpers/compact-output.js';
|
|
7
7
|
import { configuredComponentDecorators } from './helpers/project-decorators.js';
|
|
8
8
|
import { WARNINGS_OUTPUT_SCHEMA, withWarnings, } from './helpers/output-contract.js';
|
|
@@ -296,7 +296,7 @@ export class FindComponentHostsTool {
|
|
|
296
296
|
'tsConfigPath',
|
|
297
297
|
],
|
|
298
298
|
};
|
|
299
|
-
async execute(args) {
|
|
299
|
+
async execute(args, ctx = {}) {
|
|
300
300
|
const params = args;
|
|
301
301
|
if (!params.className && !params.selector) {
|
|
302
302
|
throw new Error('className or selector is required');
|
|
@@ -315,7 +315,7 @@ export class FindComponentHostsTool {
|
|
|
315
315
|
const file = params.file === undefined || isAbsolute(params.file)
|
|
316
316
|
? params.file
|
|
317
317
|
: resolve(params.projectRoot, params.file);
|
|
318
|
-
const finder = new ComponentHostFinder(this.projects
|
|
318
|
+
const finder = new ComponentHostFinder((await acquireProject(this.projects, tsConfigPath, ctx)), {
|
|
319
319
|
componentDecorators: configuredComponentDecorators(params.projectRoot),
|
|
320
320
|
includeTestHosts: params.includeTestHosts === true,
|
|
321
321
|
includeDynamic: params.includeDynamic !== false,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type MCPTool, type ToolAnnotations } from '../types.js';
|
|
1
|
+
import { type MCPTool, type ToolAnnotations, type ToolContext } from '../types.js';
|
|
2
2
|
import { type SymbolUsage, type UsageType } from '@angular-modernizer/api';
|
|
3
3
|
import { ProjectCache } from './helpers/project-cache.js';
|
|
4
4
|
/**
|
|
@@ -167,7 +167,7 @@ export declare class FindUsagesTool implements MCPTool {
|
|
|
167
167
|
};
|
|
168
168
|
required: string[];
|
|
169
169
|
};
|
|
170
|
-
execute(args: Record<string, unknown
|
|
170
|
+
execute(args: Record<string, unknown>, ctx?: ToolContext): Promise<FindUsagesOutput>;
|
|
171
171
|
private buildCompactSummary;
|
|
172
172
|
private buildSummary;
|
|
173
173
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { UsageFinder, } from '@angular-modernizer/api';
|
|
2
2
|
import { existsSync } from 'node:fs';
|
|
3
3
|
import { findTsConfig } from './helpers/find-ts-config.js';
|
|
4
|
-
import { ProjectCache } from './helpers/project-cache.js';
|
|
4
|
+
import { ProjectCache, acquireProject } from './helpers/project-cache.js';
|
|
5
5
|
import { COMPACT_OUTPUT_SCHEMA, countByDirectory, limitList, parseCompactOptions, truncationNote, } from './helpers/compact-output.js';
|
|
6
6
|
import { configuredComponentDecorators } from './helpers/project-decorators.js';
|
|
7
7
|
import { WARNINGS_OUTPUT_SCHEMA, withWarnings, } from './helpers/output-contract.js';
|
|
@@ -147,7 +147,7 @@ export class FindUsagesTool {
|
|
|
147
147
|
'tsConfigPath',
|
|
148
148
|
],
|
|
149
149
|
};
|
|
150
|
-
async execute(args) {
|
|
150
|
+
async execute(args, ctx = {}) {
|
|
151
151
|
const params = args;
|
|
152
152
|
if (!params.symbol) {
|
|
153
153
|
throw new Error('symbol is required');
|
|
@@ -165,7 +165,7 @@ export class FindUsagesTool {
|
|
|
165
165
|
}
|
|
166
166
|
// The shared ProjectCache: a fresh Project cost 4 to 6 s per call on a
|
|
167
167
|
// large workspace and sat next to the cached one while the search ran.
|
|
168
|
-
const project = this.projects
|
|
168
|
+
const project = await acquireProject(this.projects, tsConfigPath, ctx);
|
|
169
169
|
const finder = new UsageFinder(project, {
|
|
170
170
|
componentDecorators: configuredComponentDecorators(params.projectRoot),
|
|
171
171
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type MCPTool, type ToolAnnotations } from '../types.js';
|
|
1
|
+
import { type MCPTool, type ToolAnnotations, type ToolContext } from '../types.js';
|
|
2
2
|
import { type BootstrapExecutionResult, type BootstrapRoot, type BootstrapTiming, type BootstrapWatchHit } from '@angular-modernizer/api';
|
|
3
3
|
import { ProjectCache } from './helpers/project-cache.js';
|
|
4
4
|
/** A root with its reached list optionally dropped or capped. */
|
|
@@ -260,7 +260,7 @@ export declare class GetBootstrapExecutionTool implements MCPTool {
|
|
|
260
260
|
};
|
|
261
261
|
required: string[];
|
|
262
262
|
};
|
|
263
|
-
execute(args: Record<string, unknown
|
|
263
|
+
execute(args: Record<string, unknown>, ctx?: ToolContext): Promise<GetBootstrapExecutionOutput>;
|
|
264
264
|
private buildSummary;
|
|
265
265
|
}
|
|
266
266
|
//# sourceMappingURL=get-bootstrap-execution.d.ts.map
|
|
@@ -2,7 +2,7 @@ import { BootstrapExecutionAnalyzer, normalizeWatchExpression, } from '@angular-
|
|
|
2
2
|
import { existsSync } from 'node:fs';
|
|
3
3
|
import { isAbsolute, relative, resolve } from 'node:path';
|
|
4
4
|
import { findTsConfig } from './helpers/find-ts-config.js';
|
|
5
|
-
import { ProjectCache } from './helpers/project-cache.js';
|
|
5
|
+
import { ProjectCache, acquireProject } from './helpers/project-cache.js';
|
|
6
6
|
import { COMPACT_OUTPUT_SCHEMA, limitList, parseCompactOptions, } from './helpers/compact-output.js';
|
|
7
7
|
import { WARNINGS_OUTPUT_SCHEMA, withWarnings, } from './helpers/output-contract.js';
|
|
8
8
|
import { COUNT_OBJECT, STRING_ARRAY } from './helpers/investigation-schemas.js';
|
|
@@ -213,7 +213,7 @@ export class GetBootstrapExecutionTool {
|
|
|
213
213
|
},
|
|
214
214
|
required: ['counts', 'truncated', 'summary', 'tsConfigPath'],
|
|
215
215
|
};
|
|
216
|
-
async execute(args) {
|
|
216
|
+
async execute(args, ctx = {}) {
|
|
217
217
|
const params = args;
|
|
218
218
|
if (!params.projectRoot) {
|
|
219
219
|
throw new Error('projectRoot is required');
|
|
@@ -240,7 +240,7 @@ export class GetBootstrapExecutionTool {
|
|
|
240
240
|
const file = params.file === undefined || isAbsolute(params.file)
|
|
241
241
|
? params.file
|
|
242
242
|
: resolve(params.projectRoot, params.file);
|
|
243
|
-
const result = new BootstrapExecutionAnalyzer(this.projects
|
|
243
|
+
const result = new BootstrapExecutionAnalyzer((await acquireProject(this.projects, tsConfigPath, ctx))).analyze({
|
|
244
244
|
...(watch === undefined ? {} : { watch }),
|
|
245
245
|
...(timings === undefined ? {} : { timings: timings }),
|
|
246
246
|
...(file === undefined ? {} : { file }),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type MCPTool, type ToolAnnotations } from '../types.js';
|
|
1
|
+
import { type MCPTool, type ToolAnnotations, type ToolContext } from '../types.js';
|
|
2
2
|
import { type CallGraphResult } from '@angular-modernizer/api';
|
|
3
3
|
import { ProjectCache } from './helpers/project-cache.js';
|
|
4
4
|
/** Tool output: the call graph (trees omitted with `summaryOnly`) plus a text summary. */
|
|
@@ -191,7 +191,7 @@ export declare class GetCallGraphTool implements MCPTool {
|
|
|
191
191
|
};
|
|
192
192
|
required: string[];
|
|
193
193
|
};
|
|
194
|
-
execute(args: Record<string, unknown
|
|
194
|
+
execute(args: Record<string, unknown>, ctx?: ToolContext): Promise<GetCallGraphOutput>;
|
|
195
195
|
private buildSummary;
|
|
196
196
|
/**
|
|
197
197
|
* Summary lines for the direct callers or callees, at most
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CallGraphBuilder, } from '@angular-modernizer/api';
|
|
2
2
|
import { existsSync } from 'node:fs';
|
|
3
3
|
import { findTsConfig } from './helpers/find-ts-config.js';
|
|
4
|
-
import { ProjectCache } from './helpers/project-cache.js';
|
|
4
|
+
import { ProjectCache, acquireProject } from './helpers/project-cache.js';
|
|
5
5
|
import { WARNINGS_OUTPUT_SCHEMA, withWarnings, } from './helpers/output-contract.js';
|
|
6
6
|
/** Direct callers and callees spelled out per list in the summary. */
|
|
7
7
|
const SUMMARY_MAX_NODES = 50;
|
|
@@ -150,7 +150,7 @@ export class GetCallGraphTool {
|
|
|
150
150
|
},
|
|
151
151
|
required: ['target', 'nodeCount', 'truncated', 'summary'],
|
|
152
152
|
};
|
|
153
|
-
async execute(args) {
|
|
153
|
+
async execute(args, ctx = {}) {
|
|
154
154
|
const params = args;
|
|
155
155
|
if (!params.method) {
|
|
156
156
|
throw new Error('method is required');
|
|
@@ -172,7 +172,7 @@ export class GetCallGraphTool {
|
|
|
172
172
|
(!Number.isInteger(params.maxNodes) || params.maxNodes < 1)) {
|
|
173
173
|
throw new Error('maxNodes must be a positive integer');
|
|
174
174
|
}
|
|
175
|
-
const graphBuilder = new CallGraphBuilder(this.projects
|
|
175
|
+
const graphBuilder = new CallGraphBuilder((await acquireProject(this.projects, tsConfigPath, ctx)));
|
|
176
176
|
const warnings = this.projects.warnings(tsConfigPath);
|
|
177
177
|
const options = {
|
|
178
178
|
direction: params.direction ?? 'both',
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Project } from 'ts-morph';
|
|
2
|
+
import type { ToolContext } from '../../types.js';
|
|
2
3
|
/** A cached project as reported by `server-status`. */
|
|
3
4
|
export interface CachedProjectInfo {
|
|
4
5
|
/** tsconfig the project was loaded from. */
|
|
@@ -65,12 +66,41 @@ export interface ProjectCacheLimits {
|
|
|
65
66
|
/** Heap limit in MB checked after each load; 0 switches it off. */
|
|
66
67
|
maxHeapMb: number;
|
|
67
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* A project opened for a batched load: compiler options of the tsconfig set,
|
|
71
|
+
* no source files added yet, and the files the tsconfig lists.
|
|
72
|
+
*/
|
|
73
|
+
export interface OpenedProject {
|
|
74
|
+
project: Project;
|
|
75
|
+
files: readonly string[];
|
|
76
|
+
}
|
|
77
|
+
/** Abort signal and load progress of one `acquire()` call. */
|
|
78
|
+
export interface AcquireControl {
|
|
79
|
+
/** Leaves the load; the load stops once no caller waits for it. */
|
|
80
|
+
signal?: AbortSignal;
|
|
81
|
+
/** Files added so far and their total, once per batch. */
|
|
82
|
+
onProgress?: (loaded: number, total: number) => void;
|
|
83
|
+
}
|
|
84
|
+
/** Thrown by `acquire()` when its signal aborts. */
|
|
85
|
+
export declare class ProjectLoadCancelledError extends Error {
|
|
86
|
+
constructor(tsConfigPath: string);
|
|
87
|
+
}
|
|
68
88
|
export interface ProjectCacheOptions extends Partial<ProjectCacheLimits> {
|
|
89
|
+
/** Loads a project in one piece; replaces the batched load (tests). */
|
|
69
90
|
createProject?: (tsConfigFilePath: string) => Project;
|
|
91
|
+
/** Opens a project for the batched load (tests); default: {@link openTsConfigProject}. */
|
|
92
|
+
openProject?: (tsConfigFilePath: string) => OpenedProject;
|
|
93
|
+
/** Files added per batch before `acquire()` yields, at least 1. */
|
|
94
|
+
batchSize?: number;
|
|
70
95
|
memory?: MemoryProbe;
|
|
71
96
|
/** mtime of a file in ms, undefined when it cannot be read. */
|
|
72
97
|
statFile?: (filePath: string) => number | undefined;
|
|
73
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Default files per batch. On a large app (3869 files) a batch of 50 takes 50
|
|
101
|
+
* to 75 ms to read and parse, 160 ms under heavy load.
|
|
102
|
+
*/
|
|
103
|
+
export declare const DEFAULT_LOAD_BATCH_SIZE = 50;
|
|
74
104
|
/** Default number of workspaces kept in memory at once. */
|
|
75
105
|
export declare const DEFAULT_MAX_ENTRIES = 3;
|
|
76
106
|
/**
|
|
@@ -82,6 +112,11 @@ export declare const DEFAULT_MAX_ENTRIES = 3;
|
|
|
82
112
|
export declare const DEFAULT_MAX_HEAP_MB = 2048;
|
|
83
113
|
/** Bytes to MB, one decimal. */
|
|
84
114
|
export declare function toMB(bytes: number): number;
|
|
115
|
+
/**
|
|
116
|
+
* Opens the project of a tsconfig with its compiler options and the file list
|
|
117
|
+
* `new Project({ tsConfigFilePath })` would add, without adding the files.
|
|
118
|
+
*/
|
|
119
|
+
export declare function openTsConfigProject(tsConfigFilePath: string): OpenedProject;
|
|
85
120
|
/**
|
|
86
121
|
* LRU cache of ts-morph Projects keyed by tsconfig path. Keeps `Project`
|
|
87
122
|
* instances alive across tool calls, so repeated investigation calls on the
|
|
@@ -120,6 +155,9 @@ export declare class ProjectCache {
|
|
|
120
155
|
private readonly maxEntries;
|
|
121
156
|
private readonly maxHeapMb;
|
|
122
157
|
private readonly createProject;
|
|
158
|
+
private readonly openProject;
|
|
159
|
+
private readonly batchSize;
|
|
160
|
+
private readonly loading;
|
|
123
161
|
private readonly memory;
|
|
124
162
|
private readonly statFile;
|
|
125
163
|
private evictionCount;
|
|
@@ -129,8 +167,25 @@ export declare class ProjectCache {
|
|
|
129
167
|
* the last two.
|
|
130
168
|
*/
|
|
131
169
|
constructor(options?: ProjectCacheOptions);
|
|
132
|
-
/**
|
|
170
|
+
/**
|
|
171
|
+
* Returns the cached Project for `tsConfigPath`, building it on a miss in
|
|
172
|
+
* one synchronous piece. Tools use `acquire()`.
|
|
173
|
+
*/
|
|
133
174
|
get(tsConfigPath: string): Project;
|
|
175
|
+
/**
|
|
176
|
+
* Returns the cached Project for `tsConfigPath`; on a miss loads it in
|
|
177
|
+
* batches of files with one event-loop turn after each, then builds the
|
|
178
|
+
* program and, after another turn, the type checker. The server keeps
|
|
179
|
+
* reading requests in between, and an aborted signal leaves the load at
|
|
180
|
+
* the next turn.
|
|
181
|
+
*
|
|
182
|
+
* Calls for the same tsconfig while it loads share the load. It stops only
|
|
183
|
+
* when every caller has left; a stopped load is not cached. A hit behaves
|
|
184
|
+
* like `get()`.
|
|
185
|
+
*
|
|
186
|
+
* @throws ProjectLoadCancelledError when `control.signal` aborts.
|
|
187
|
+
*/
|
|
188
|
+
acquire(tsConfigPath: string, control?: AcquireControl): Promise<Project>;
|
|
134
189
|
/** Number of cached projects. */
|
|
135
190
|
get size(): number;
|
|
136
191
|
/** Most projects kept at once. */
|
|
@@ -157,7 +212,18 @@ export declare class ProjectCache {
|
|
|
157
212
|
/** Re-reads program files whose mtime changed and removes deleted ones. */
|
|
158
213
|
private refreshChangedFiles;
|
|
159
214
|
private recordMtimes;
|
|
160
|
-
|
|
215
|
+
/**
|
|
216
|
+
* The load as steps: one per batch of added files (files added, total),
|
|
217
|
+
* the program built after the last one. An injected `createProject` loads
|
|
218
|
+
* in one step.
|
|
219
|
+
*/
|
|
220
|
+
private loadSteps;
|
|
221
|
+
private startLoad;
|
|
222
|
+
private loadInBatches;
|
|
223
|
+
private stopIfCancelled;
|
|
224
|
+
/** Joins `job` until it settles or `control.signal` aborts. */
|
|
225
|
+
private waitFor;
|
|
226
|
+
private store;
|
|
161
227
|
private evictOverCount;
|
|
162
228
|
/**
|
|
163
229
|
* Evicts least recently used projects, never `current`, until the heap is
|
|
@@ -197,4 +263,9 @@ export interface ParsedProjectCacheLimits {
|
|
|
197
263
|
* with a warning so a typo does not stop the server.
|
|
198
264
|
*/
|
|
199
265
|
export declare function parseProjectCacheLimits(argv: readonly string[], env: Readonly<Record<string, string | undefined>>): ParsedProjectCacheLimits;
|
|
266
|
+
/**
|
|
267
|
+
* Project of a tool call from the shared cache: the call's signal leaves the
|
|
268
|
+
* load, and with a progress token the files loaded are reported per batch.
|
|
269
|
+
*/
|
|
270
|
+
export declare function acquireProject(projects: ProjectCache, tsConfigPath: string, ctx?: ToolContext): Promise<Project>;
|
|
200
271
|
//# sourceMappingURL=project-cache.d.ts.map
|