@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,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/adapter-mcp - Unresolved library imports
|
|
3
|
+
*
|
|
4
|
+
* Counts the library imports of a ts-morph Project that do not resolve, so
|
|
5
|
+
* investigation tools can say when their answer may be incomplete.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Without a resolvable `node_modules` the program still loads, but every
|
|
9
|
+
* library type is `any`: dialogs opened through `MatDialog`, subscriptions on
|
|
10
|
+
* `EventEmitter`, injected framework services and the like are no longer
|
|
11
|
+
* recognised, and the tools return fewer results without any error. This
|
|
12
|
+
* check makes that visible.
|
|
13
|
+
*
|
|
14
|
+
* A library import is a bare module specifier whose package is declared in
|
|
15
|
+
* the nearest `package.json` above the tsconfig (dependencies,
|
|
16
|
+
* devDependencies, peerDependencies, optionalDependencies) and that does not
|
|
17
|
+
* match a tsconfig `paths` alias. Relative imports, broken aliases, aliases of
|
|
18
|
+
* other tsconfigs (`@testing/*` from a spec config) and Node builtins
|
|
19
|
+
* (ambient modules of `@types/node`, which the resolver does not find as
|
|
20
|
+
* files) are not a missing install and are not counted. Each distinct
|
|
21
|
+
* specifier is resolved once with the TypeScript module resolver against the
|
|
22
|
+
* project's compiler options and file system host, so in-memory projects work
|
|
23
|
+
* the same way; when that fails, a package folder in a `node_modules` above
|
|
24
|
+
* the importing file still counts as installed (side-effect imports of plain
|
|
25
|
+
* JavaScript such as `moment/locale/de-at` have no types to resolve). No
|
|
26
|
+
* program is created.
|
|
27
|
+
*/
|
|
28
|
+
import { isRelativeSpecifier, matchPathPattern, } from '@angular-modernizer/core';
|
|
29
|
+
import { dirname, join } from 'node:path';
|
|
30
|
+
import { ts } from 'ts-morph';
|
|
31
|
+
/** Package names listed in the warning. */
|
|
32
|
+
export const EXAMPLE_PACKAGES = 5;
|
|
33
|
+
/** Module specifiers of the import and re-export declarations of one file. */
|
|
34
|
+
function moduleSpecifiers(sourceFile) {
|
|
35
|
+
const specifiers = [];
|
|
36
|
+
for (const statement of sourceFile.statements) {
|
|
37
|
+
const isEdge = ts.isImportDeclaration(statement) || ts.isExportDeclaration(statement);
|
|
38
|
+
const specifier = isEdge ? statement.moduleSpecifier : undefined;
|
|
39
|
+
if (specifier !== undefined && ts.isStringLiteral(specifier)) {
|
|
40
|
+
specifiers.push(specifier.text);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return specifiers;
|
|
44
|
+
}
|
|
45
|
+
/** `@scope/name/sub` -> `@scope/name`, `name/sub` -> `name`. */
|
|
46
|
+
export function packageName(specifier) {
|
|
47
|
+
const parts = specifier.split('/');
|
|
48
|
+
return specifier.startsWith('@') ? parts.slice(0, 2).join('/') : (parts[0] ?? specifier);
|
|
49
|
+
}
|
|
50
|
+
const DEPENDENCY_FIELDS = [
|
|
51
|
+
'dependencies',
|
|
52
|
+
'devDependencies',
|
|
53
|
+
'peerDependencies',
|
|
54
|
+
'optionalDependencies',
|
|
55
|
+
];
|
|
56
|
+
/**
|
|
57
|
+
* Package names declared in the nearest `package.json` at or above `dir`;
|
|
58
|
+
* empty when there is none or it cannot be read.
|
|
59
|
+
*/
|
|
60
|
+
export function declaredPackages(fs, dir) {
|
|
61
|
+
for (let current = dir;; current = dirname(current)) {
|
|
62
|
+
const file = join(current, 'package.json');
|
|
63
|
+
if (fs.fileExistsSync(file)) {
|
|
64
|
+
try {
|
|
65
|
+
const manifest = JSON.parse(fs.readFileSync(file));
|
|
66
|
+
return new Set(DEPENDENCY_FIELDS.flatMap((field) => {
|
|
67
|
+
const deps = manifest[field];
|
|
68
|
+
return typeof deps === 'object' && deps !== null ? Object.keys(deps) : [];
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return new Set();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (dirname(current) === current) {
|
|
76
|
+
return new Set();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/** `true` when `node_modules/<pkg>` exists in the directory of `fromFile` or above it. */
|
|
81
|
+
function packageFolderExists(host, fromFile, pkg) {
|
|
82
|
+
for (let dir = dirname(fromFile);; dir = dirname(dir)) {
|
|
83
|
+
if (host.directoryExists?.(join(dir, 'node_modules', pkg)) === true) {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
if (dirname(dir) === dir) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Resolves every distinct library specifier of `project` once and counts the
|
|
93
|
+
* declarations whose specifier does not resolve.
|
|
94
|
+
*
|
|
95
|
+
* @param tsConfigPath - The project's tsconfig; the `package.json` with the
|
|
96
|
+
* declared packages is looked up from its directory upwards.
|
|
97
|
+
*/
|
|
98
|
+
export function findUnresolvedLibraryImports(project, tsConfigPath) {
|
|
99
|
+
const declared = declaredPackages(project.getFileSystem(), dirname(tsConfigPath));
|
|
100
|
+
const options = project.getCompilerOptions();
|
|
101
|
+
const host = project.getModuleResolutionHost();
|
|
102
|
+
const aliases = Object.keys(options.paths ?? {});
|
|
103
|
+
const isAlias = (specifier) => aliases.some((pattern) => matchPathPattern(pattern, specifier) !== undefined);
|
|
104
|
+
const cache = ts.createModuleResolutionCache(project.getFileSystem().getCurrentDirectory(), (fileName) => fileName, options);
|
|
105
|
+
const resolved = new Map();
|
|
106
|
+
const unresolvedPerPackage = new Map();
|
|
107
|
+
let imports = 0;
|
|
108
|
+
for (const sourceFile of project.getSourceFiles()) {
|
|
109
|
+
if (sourceFile.isInNodeModules()) {
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
const containingFile = sourceFile.getFilePath();
|
|
113
|
+
for (const specifier of moduleSpecifiers(sourceFile.compilerNode)) {
|
|
114
|
+
const isLibrary = !isRelativeSpecifier(specifier) &&
|
|
115
|
+
declared.has(packageName(specifier)) &&
|
|
116
|
+
!isAlias(specifier);
|
|
117
|
+
if (!isLibrary) {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
let ok = resolved.get(specifier);
|
|
121
|
+
if (ok === undefined) {
|
|
122
|
+
ok =
|
|
123
|
+
ts.resolveModuleName(specifier, containingFile, options, host, cache)
|
|
124
|
+
.resolvedModule !== undefined ||
|
|
125
|
+
packageFolderExists(host, containingFile, packageName(specifier));
|
|
126
|
+
resolved.set(specifier, ok);
|
|
127
|
+
}
|
|
128
|
+
if (!ok) {
|
|
129
|
+
imports++;
|
|
130
|
+
const name = packageName(specifier);
|
|
131
|
+
unresolvedPerPackage.set(name, (unresolvedPerPackage.get(name) ?? 0) + 1);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const examples = [...unresolvedPerPackage]
|
|
136
|
+
.sort(([a, countA], [b, countB]) => countB - countA || a.localeCompare(b))
|
|
137
|
+
.slice(0, EXAMPLE_PACKAGES)
|
|
138
|
+
.map(([name]) => name);
|
|
139
|
+
return { imports, packages: unresolvedPerPackage.size, examples };
|
|
140
|
+
}
|
|
141
|
+
/** Warning text for `warnings` and the summary, or `undefined` when all resolve. */
|
|
142
|
+
export function libraryImportWarning(found) {
|
|
143
|
+
if (found.imports === 0) {
|
|
144
|
+
return undefined;
|
|
145
|
+
}
|
|
146
|
+
const more = found.packages > found.examples.length ? ', ...' : '';
|
|
147
|
+
return (`${found.imports} library import(s) from ${found.packages} package(s) do not resolve ` +
|
|
148
|
+
`(${found.examples.join(', ')}${more}); is node_modules missing or incomplete? ` +
|
|
149
|
+
'Results that depend on library types (dialogs, subscriptions, injected services) can be incomplete.');
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=library-imports.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/adapter-mcp - Cancellable file loading for scans
|
|
3
|
+
*
|
|
4
|
+
* Adding a file to a ts-morph project reads and parses it synchronously. A
|
|
5
|
+
* scan adds hundreds of files before its analysis loop starts, so without a
|
|
6
|
+
* yield per file a `notifications/cancelled` is read only after the whole
|
|
7
|
+
* batch is loaded (measured: answer 2.6 s after a cancel at 2 s, 375 files).
|
|
8
|
+
*/
|
|
9
|
+
import type { Project, SourceFile } from 'ts-morph';
|
|
10
|
+
export interface LoadSourceFilesOptions {
|
|
11
|
+
/** Aborts the load between files (MCP `notifications/cancelled`). */
|
|
12
|
+
signal?: AbortSignal;
|
|
13
|
+
isCancelled?: () => boolean;
|
|
14
|
+
/** Use a file the project already has instead of adding it again. */
|
|
15
|
+
reuseExisting?: boolean;
|
|
16
|
+
/** Rethrow a file that cannot be added; default: warn and skip it. */
|
|
17
|
+
failOnError?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface LoadedSourceFiles {
|
|
20
|
+
/** Files added (or reused), in the order of the input list. */
|
|
21
|
+
sourceFiles: SourceFile[];
|
|
22
|
+
/** `true` when the load stopped at a cancellation. */
|
|
23
|
+
cancelled: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Add `files` to `project` one by one. With a signal the event loop gets one
|
|
27
|
+
* turn per file and the signal is checked before each file.
|
|
28
|
+
*/
|
|
29
|
+
export declare function loadSourceFiles(project: Project, files: readonly string[], options?: LoadSourceFilesOptions): Promise<LoadedSourceFiles>;
|
|
30
|
+
//# sourceMappingURL=load-source-files.d.ts.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/adapter-mcp - Cancellable file loading for scans
|
|
3
|
+
*
|
|
4
|
+
* Adding a file to a ts-morph project reads and parses it synchronously. A
|
|
5
|
+
* scan adds hundreds of files before its analysis loop starts, so without a
|
|
6
|
+
* yield per file a `notifications/cancelled` is read only after the whole
|
|
7
|
+
* batch is loaded (measured: answer 2.6 s after a cancel at 2 s, 375 files).
|
|
8
|
+
*/
|
|
9
|
+
import { yieldIfCancellable } from './tool-context.js';
|
|
10
|
+
/**
|
|
11
|
+
* Add `files` to `project` one by one. With a signal the event loop gets one
|
|
12
|
+
* turn per file and the signal is checked before each file.
|
|
13
|
+
*/
|
|
14
|
+
export async function loadSourceFiles(project, files, options = {}) {
|
|
15
|
+
const sourceFiles = [];
|
|
16
|
+
for (const filePath of files) {
|
|
17
|
+
await yieldIfCancellable(options.signal);
|
|
18
|
+
if (options.signal?.aborted === true || options.isCancelled?.() === true) {
|
|
19
|
+
return { sourceFiles, cancelled: true };
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
const existing = options.reuseExisting === true ? project.getSourceFile(filePath) : undefined;
|
|
23
|
+
sourceFiles.push(existing ?? project.addSourceFileAtPath(filePath));
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
if (options.failOnError === true) {
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
console.warn(`Error loading ${filePath}:`, error);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return { sourceFiles, cancelled: false };
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=load-source-files.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/adapter-mcp - Output contract helpers
|
|
3
|
+
*
|
|
4
|
+
* Pieces shared by the `outputSchema` of the tools on the structured output
|
|
5
|
+
* contract (`structuredContent` plus a `summary` string).
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Output schemas describe what a tool returns without closing objects
|
|
9
|
+
* (`additionalProperties` stays open), so a new field never turns a valid
|
|
10
|
+
* result into an output validation error. `required` lists only fields every
|
|
11
|
+
* variant of the result carries (`summaryOnly` drops the lists).
|
|
12
|
+
*/
|
|
13
|
+
/** `warnings` entry of an output schema. */
|
|
14
|
+
export declare const WARNINGS_OUTPUT_SCHEMA: {
|
|
15
|
+
readonly warnings: {
|
|
16
|
+
readonly type: "array";
|
|
17
|
+
readonly items: {
|
|
18
|
+
readonly type: "string";
|
|
19
|
+
};
|
|
20
|
+
readonly description: "Conditions that can make the result incomplete, e.g. library imports that do not resolve because node_modules is missing.";
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Adds `warnings` to a result and one `Warning:` line per entry to its
|
|
25
|
+
* summary; returns the result unchanged when there are none.
|
|
26
|
+
*/
|
|
27
|
+
export declare function withWarnings<T extends {
|
|
28
|
+
summary: string;
|
|
29
|
+
}>(result: T, warnings: readonly string[]): T & {
|
|
30
|
+
warnings?: string[];
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=output-contract.d.ts.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/adapter-mcp - Output contract helpers
|
|
3
|
+
*
|
|
4
|
+
* Pieces shared by the `outputSchema` of the tools on the structured output
|
|
5
|
+
* contract (`structuredContent` plus a `summary` string).
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Output schemas describe what a tool returns without closing objects
|
|
9
|
+
* (`additionalProperties` stays open), so a new field never turns a valid
|
|
10
|
+
* result into an output validation error. `required` lists only fields every
|
|
11
|
+
* variant of the result carries (`summaryOnly` drops the lists).
|
|
12
|
+
*/
|
|
13
|
+
/** `warnings` entry of an output schema. */
|
|
14
|
+
export const WARNINGS_OUTPUT_SCHEMA = {
|
|
15
|
+
warnings: {
|
|
16
|
+
type: 'array',
|
|
17
|
+
items: { type: 'string' },
|
|
18
|
+
description: 'Conditions that can make the result incomplete, e.g. library imports that do not resolve because node_modules is missing.',
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Adds `warnings` to a result and one `Warning:` line per entry to its
|
|
23
|
+
* summary; returns the result unchanged when there are none.
|
|
24
|
+
*/
|
|
25
|
+
export function withWarnings(result, warnings) {
|
|
26
|
+
if (warnings.length === 0) {
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
const lines = warnings.map((w) => `Warning: ${w}`).join('\n');
|
|
30
|
+
return { ...result, summary: `${result.summary}\n${lines}`, warnings: [...warnings] };
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=output-contract.js.map
|
|
@@ -1,33 +1,63 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @angular-modernizer/adapter-mcp -
|
|
2
|
+
* @angular-modernizer/adapter-mcp - Feedback storage roots
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Feedback always lives in `<projectRoot>/.claude-feedback`. A second,
|
|
5
|
+
* platform-wide store exists only when `ANGULAR_MODERNIZER_PLATFORM_ROOT` is
|
|
6
|
+
* set. The server never derives a platform root from its own install path:
|
|
7
|
+
* installed from npm that path is the user's workspace root or a
|
|
8
|
+
* `node_modules` / npx cache directory.
|
|
6
9
|
*/
|
|
10
|
+
import type { StorageLocation } from '@angular-modernizer/core';
|
|
11
|
+
/** Environment variable that enables the platform feedback store. */
|
|
12
|
+
export declare const PLATFORM_ROOT_ENV = "ANGULAR_MODERNIZER_PLATFORM_ROOT";
|
|
13
|
+
/** Roots the feedback tools read from or write to. */
|
|
14
|
+
export interface FeedbackRoots {
|
|
15
|
+
projectRoot: string;
|
|
16
|
+
/** Set only when {@link PLATFORM_ROOT_ENV} is set. */
|
|
17
|
+
platformRoot?: string;
|
|
18
|
+
/** Locations actually used: never `platform` without a platform root. */
|
|
19
|
+
locations: ('project' | 'platform')[];
|
|
20
|
+
}
|
|
7
21
|
/**
|
|
8
|
-
*
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
*
|
|
13
|
-
* @returns Absolute path to platform root directory
|
|
14
|
-
*
|
|
15
|
-
* @remarks
|
|
16
|
-
* - First checks ANGULAR_MODERNIZER_PLATFORM_ROOT environment variable
|
|
17
|
-
* - Then searches upward from currentDir for package.json with workspaces field
|
|
18
|
-
* - Falls back to calculated path relative to currentDir if not found
|
|
19
|
-
* - Stops searching at filesystem root to prevent infinite loops
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```typescript
|
|
23
|
-
* import { fileURLToPath } from 'node:url';
|
|
24
|
-
* import * as path from 'node:path';
|
|
22
|
+
* The platform root from {@link PLATFORM_ROOT_ENV}, or `undefined`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function configuredPlatformRoot(): string | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Resolve the locations for a requested storage strategy.
|
|
25
27
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
+
* - `project`: the project only
|
|
29
|
+
* - `both`: the project, plus the platform root when it is configured
|
|
30
|
+
* - `platform`: the platform root; without one this is an error
|
|
28
31
|
*
|
|
29
|
-
*
|
|
30
|
-
|
|
32
|
+
* @throws {Error} for `platform` without {@link PLATFORM_ROOT_ENV}
|
|
33
|
+
*/
|
|
34
|
+
export declare function resolveFeedbackRoots(projectRoot: string, requested: StorageLocation): FeedbackRoots;
|
|
35
|
+
/**
|
|
36
|
+
* The `StorageLocation` for core `FeedbackStorage` / `FeedbackCollector`
|
|
37
|
+
* matching the resolved locations.
|
|
38
|
+
*/
|
|
39
|
+
export declare function effectiveStorageLocation(roots: FeedbackRoots): StorageLocation;
|
|
40
|
+
/**
|
|
41
|
+
* Absolute root directory of a location.
|
|
42
|
+
*/
|
|
43
|
+
export declare function locationRoot(roots: FeedbackRoots, location: 'project' | 'platform'): string;
|
|
44
|
+
/**
|
|
45
|
+
* The platform root to hand to core `FeedbackStorage` (which needs a string):
|
|
46
|
+
* the project root when no platform store is configured, never read then
|
|
47
|
+
* because the effective location is `project`.
|
|
48
|
+
*/
|
|
49
|
+
export declare function storagePlatformRoot(roots: FeedbackRoots): string;
|
|
50
|
+
/**
|
|
51
|
+
* Config for core `FeedbackStorage` for the resolved roots.
|
|
52
|
+
*/
|
|
53
|
+
export declare function feedbackStorageConfig(roots: FeedbackRoots): {
|
|
54
|
+
projectRoot: string;
|
|
55
|
+
platformRoot: string;
|
|
56
|
+
storageLocation: StorageLocation;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* The session directories of the used locations (`sourcesRead` of the
|
|
60
|
+
* reading tools).
|
|
31
61
|
*/
|
|
32
|
-
export declare function
|
|
62
|
+
export declare function feedbackSessionDirs(roots: FeedbackRoots): string[];
|
|
33
63
|
//# sourceMappingURL=platform-root-resolver.d.ts.map
|
|
@@ -1,60 +1,87 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @angular-modernizer/adapter-mcp -
|
|
2
|
+
* @angular-modernizer/adapter-mcp - Feedback storage roots
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Feedback always lives in `<projectRoot>/.claude-feedback`. A second,
|
|
5
|
+
* platform-wide store exists only when `ANGULAR_MODERNIZER_PLATFORM_ROOT` is
|
|
6
|
+
* set. The server never derives a platform root from its own install path:
|
|
7
|
+
* installed from npm that path is the user's workspace root or a
|
|
8
|
+
* `node_modules` / npx cache directory.
|
|
6
9
|
*/
|
|
7
10
|
import * as path from 'node:path';
|
|
8
|
-
|
|
11
|
+
/** Environment variable that enables the platform feedback store. */
|
|
12
|
+
export const PLATFORM_ROOT_ENV = 'ANGULAR_MODERNIZER_PLATFORM_ROOT';
|
|
9
13
|
/**
|
|
10
|
-
*
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
*
|
|
18
|
-
* - First checks ANGULAR_MODERNIZER_PLATFORM_ROOT environment variable
|
|
19
|
-
* - Then searches upward from currentDir for package.json with workspaces field
|
|
20
|
-
* - Falls back to calculated path relative to currentDir if not found
|
|
21
|
-
* - Stops searching at filesystem root to prevent infinite loops
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```typescript
|
|
25
|
-
* import { fileURLToPath } from 'node:url';
|
|
26
|
-
* import * as path from 'node:path';
|
|
14
|
+
* The platform root from {@link PLATFORM_ROOT_ENV}, or `undefined`.
|
|
15
|
+
*/
|
|
16
|
+
export function configuredPlatformRoot() {
|
|
17
|
+
const value = process.env[PLATFORM_ROOT_ENV]?.trim();
|
|
18
|
+
return value === undefined || value === '' ? undefined : value;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Resolve the locations for a requested storage strategy.
|
|
27
22
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
23
|
+
* - `project`: the project only
|
|
24
|
+
* - `both`: the project, plus the platform root when it is configured
|
|
25
|
+
* - `platform`: the platform root; without one this is an error
|
|
30
26
|
*
|
|
31
|
-
*
|
|
32
|
-
* ```
|
|
27
|
+
* @throws {Error} for `platform` without {@link PLATFORM_ROOT_ENV}
|
|
33
28
|
*/
|
|
34
|
-
export function
|
|
35
|
-
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
// Search upward from current directory for monorepo root (package.json with workspaces)
|
|
40
|
-
let searchDir = currentDir;
|
|
41
|
-
const root = path.parse(searchDir).root;
|
|
42
|
-
while (searchDir !== root) {
|
|
43
|
-
try {
|
|
44
|
-
const packageJsonPath = path.join(searchDir, 'package.json');
|
|
45
|
-
const packageJsonContent = readFileSync(packageJsonPath, 'utf-8');
|
|
46
|
-
const packageJson = JSON.parse(packageJsonContent);
|
|
47
|
-
// Check if this is the monorepo root (has workspaces)
|
|
48
|
-
if (packageJson.workspaces) {
|
|
49
|
-
return searchDir;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
catch {
|
|
53
|
-
// package.json not found or invalid, continue searching
|
|
29
|
+
export function resolveFeedbackRoots(projectRoot, requested) {
|
|
30
|
+
const platformRoot = configuredPlatformRoot();
|
|
31
|
+
if (platformRoot === undefined) {
|
|
32
|
+
if (requested === 'platform') {
|
|
33
|
+
throw new Error(`Feedback location 'platform' needs ${PLATFORM_ROOT_ENV}; without it feedback is stored in <projectRoot>/.claude-feedback ('project' or 'both').`);
|
|
54
34
|
}
|
|
55
|
-
|
|
35
|
+
return { projectRoot, locations: ['project'] };
|
|
36
|
+
}
|
|
37
|
+
return { projectRoot, platformRoot, locations: LOCATIONS[requested] };
|
|
38
|
+
}
|
|
39
|
+
const LOCATIONS = {
|
|
40
|
+
project: ['project'],
|
|
41
|
+
platform: ['platform'],
|
|
42
|
+
both: ['project', 'platform'],
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* The `StorageLocation` for core `FeedbackStorage` / `FeedbackCollector`
|
|
46
|
+
* matching the resolved locations.
|
|
47
|
+
*/
|
|
48
|
+
export function effectiveStorageLocation(roots) {
|
|
49
|
+
if (roots.locations.length === 2) {
|
|
50
|
+
return 'both';
|
|
56
51
|
}
|
|
57
|
-
|
|
58
|
-
|
|
52
|
+
return roots.locations[0] ?? 'project';
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Absolute root directory of a location.
|
|
56
|
+
*/
|
|
57
|
+
export function locationRoot(roots, location) {
|
|
58
|
+
return location === 'platform' && roots.platformRoot !== undefined
|
|
59
|
+
? roots.platformRoot
|
|
60
|
+
: roots.projectRoot;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The platform root to hand to core `FeedbackStorage` (which needs a string):
|
|
64
|
+
* the project root when no platform store is configured, never read then
|
|
65
|
+
* because the effective location is `project`.
|
|
66
|
+
*/
|
|
67
|
+
export function storagePlatformRoot(roots) {
|
|
68
|
+
return roots.platformRoot ?? roots.projectRoot;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Config for core `FeedbackStorage` for the resolved roots.
|
|
72
|
+
*/
|
|
73
|
+
export function feedbackStorageConfig(roots) {
|
|
74
|
+
return {
|
|
75
|
+
projectRoot: roots.projectRoot,
|
|
76
|
+
platformRoot: storagePlatformRoot(roots),
|
|
77
|
+
storageLocation: effectiveStorageLocation(roots),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The session directories of the used locations (`sourcesRead` of the
|
|
82
|
+
* reading tools).
|
|
83
|
+
*/
|
|
84
|
+
export function feedbackSessionDirs(roots) {
|
|
85
|
+
return roots.locations.map((location) => path.join(locationRoot(roots, location), '.claude-feedback/sessions'));
|
|
59
86
|
}
|
|
60
87
|
//# sourceMappingURL=platform-root-resolver.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/adapter-mcp - Child process output in summaries
|
|
3
|
+
*
|
|
4
|
+
* Tools that run a child process (Angular CLI, build, schematic) keep the
|
|
5
|
+
* full stdout and stderr in their result; the text summary carries only the
|
|
6
|
+
* last lines, which is where a failing CLI prints its error.
|
|
7
|
+
*/
|
|
8
|
+
/** Lines of a process output repeated in a summary. */
|
|
9
|
+
export declare const SUMMARY_OUTPUT_LINES = 15;
|
|
10
|
+
/** Characters of a process output repeated in a summary. */
|
|
11
|
+
export declare const SUMMARY_OUTPUT_CHARS = 2000;
|
|
12
|
+
/**
|
|
13
|
+
* The last non-empty lines of a process output, at most `maxLines` lines and
|
|
14
|
+
* `maxChars` characters; `undefined` when the output is blank.
|
|
15
|
+
*/
|
|
16
|
+
export declare function outputTail(text: string, maxLines?: number, maxChars?: number): string | undefined;
|
|
17
|
+
/** Milliseconds as seconds with one decimal, e.g. `12.3 s`. */
|
|
18
|
+
export declare function seconds(ms: number): string;
|
|
19
|
+
//# sourceMappingURL=process-output.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/adapter-mcp - Child process output in summaries
|
|
3
|
+
*
|
|
4
|
+
* Tools that run a child process (Angular CLI, build, schematic) keep the
|
|
5
|
+
* full stdout and stderr in their result; the text summary carries only the
|
|
6
|
+
* last lines, which is where a failing CLI prints its error.
|
|
7
|
+
*/
|
|
8
|
+
/** Lines of a process output repeated in a summary. */
|
|
9
|
+
export const SUMMARY_OUTPUT_LINES = 15;
|
|
10
|
+
/** Characters of a process output repeated in a summary. */
|
|
11
|
+
export const SUMMARY_OUTPUT_CHARS = 2000;
|
|
12
|
+
/**
|
|
13
|
+
* The last non-empty lines of a process output, at most `maxLines` lines and
|
|
14
|
+
* `maxChars` characters; `undefined` when the output is blank.
|
|
15
|
+
*/
|
|
16
|
+
export function outputTail(text, maxLines = SUMMARY_OUTPUT_LINES, maxChars = SUMMARY_OUTPUT_CHARS) {
|
|
17
|
+
const lines = text
|
|
18
|
+
.split(/\r?\n/)
|
|
19
|
+
.map((line) => line.trimEnd())
|
|
20
|
+
.filter((line) => line !== '');
|
|
21
|
+
if (lines.length === 0) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
const tail = lines.slice(-maxLines).join('\n');
|
|
25
|
+
return tail.length > maxChars ? tail.slice(tail.length - maxChars) : tail;
|
|
26
|
+
}
|
|
27
|
+
/** Milliseconds as seconds with one decimal, e.g. `12.3 s`. */
|
|
28
|
+
export function seconds(ms) {
|
|
29
|
+
return `${(ms / 1000).toFixed(1)} s`;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=process-output.js.map
|