@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
package/dist/tools/scan-solid.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @angular-modernizer/adapter-mcp - Scan SOLID Principles Tool
|
|
3
3
|
*
|
|
4
4
|
* MCP tool for scanning Angular codebases for SOLID principle violations.
|
|
5
|
-
* Runs only the SolidPlugin (
|
|
5
|
+
* Runs only the SolidPlugin (7 rules: DIP, SRP, LSP, OCP, ISP).
|
|
6
6
|
*/
|
|
7
7
|
import { findTsConfig } from './helpers/find-ts-config.js';
|
|
8
8
|
import { Kernel, createToolCacheConfig, loadConfig, } from '@angular-modernizer/core';
|
|
@@ -12,14 +12,26 @@ import { createPublicApi } from '@angular-modernizer/api';
|
|
|
12
12
|
import { glob } from 'glob';
|
|
13
13
|
import { resolve, relative } from 'node:path';
|
|
14
14
|
import { readFileSync, existsSync } from 'node:fs';
|
|
15
|
+
import { describeScan, SCAN_EXECUTION_SCHEMA, scanOutputSchema, } from './helpers/analysis-output.js';
|
|
16
|
+
import { cancelledExecution, fileProgressMessage, yieldIfCancellable, } from './helpers/tool-context.js';
|
|
17
|
+
import { loadSourceFiles } from './helpers/load-source-files.js';
|
|
15
18
|
/**
|
|
16
19
|
* Scan for SOLID principle violations using the SolidPlugin.
|
|
17
20
|
*/
|
|
18
21
|
export class ScanSolidTool {
|
|
19
22
|
name = 'scan-solid';
|
|
20
|
-
|
|
23
|
+
title = 'Scan SOLID Principles';
|
|
24
|
+
annotations = {
|
|
25
|
+
readOnlyHint: true,
|
|
26
|
+
destructiveHint: false,
|
|
27
|
+
idempotentHint: true,
|
|
28
|
+
openWorldHint: false,
|
|
29
|
+
};
|
|
30
|
+
description = 'Scan for SOLID principle violations (DIP, SRP, LSP, OCP, ISP). maxResults (default 1000) and resultOffset ' +
|
|
31
|
+
'page the violations; counts cover all of them, summary is a short text.';
|
|
21
32
|
inputSchema = {
|
|
22
33
|
type: 'object',
|
|
34
|
+
additionalProperties: false,
|
|
23
35
|
properties: {
|
|
24
36
|
rootPath: {
|
|
25
37
|
type: 'string',
|
|
@@ -89,7 +101,8 @@ export class ScanSolidTool {
|
|
|
89
101
|
},
|
|
90
102
|
required: ['rootPath'],
|
|
91
103
|
};
|
|
92
|
-
|
|
104
|
+
outputSchema = scanOutputSchema({ execution: SCAN_EXECUTION_SCHEMA });
|
|
105
|
+
async execute(args, ctx = {}) {
|
|
93
106
|
const params = args;
|
|
94
107
|
const config = this.loadConfig(params.rootPath);
|
|
95
108
|
const mergedParams = { ...config, ...params };
|
|
@@ -133,7 +146,8 @@ export class ScanSolidTool {
|
|
|
133
146
|
});
|
|
134
147
|
allFiles.push(...files);
|
|
135
148
|
}
|
|
136
|
-
|
|
149
|
+
// Sorted: glob returns files in no fixed order, the result pages depend on it
|
|
150
|
+
const uniqueFiles = Array.from(new Set(allFiles)).sort();
|
|
137
151
|
const filesToAnalyze = uniqueFiles; // Analyze ALL files found (batch processing prevents memory issues)
|
|
138
152
|
const maxFiles = mergedParams.maxFiles ?? 100; // Batch size (default 100)
|
|
139
153
|
// Initialize kernel
|
|
@@ -220,8 +234,11 @@ export class ScanSolidTool {
|
|
|
220
234
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment
|
|
221
235
|
const results = [...cachedResults];
|
|
222
236
|
let filesAnalyzed = cachedResults.length;
|
|
223
|
-
// Process each batch
|
|
224
|
-
|
|
237
|
+
// Process each batch; cancellation is checked between files
|
|
238
|
+
const cachedFiles = filesToAnalyze.length - totalFiles;
|
|
239
|
+
let processedFiles = 0;
|
|
240
|
+
let cancelled = false;
|
|
241
|
+
for (let batchNum = 0; batchNum < totalBatches && !cancelled; batchNum++) {
|
|
225
242
|
const batchStart = batchNum * batchSize;
|
|
226
243
|
const batchEnd = Math.min(batchStart + batchSize, totalFiles);
|
|
227
244
|
const batchFiles = filesToProcess.slice(batchStart, batchEnd);
|
|
@@ -233,14 +250,11 @@ export class ScanSolidTool {
|
|
|
233
250
|
for (const file of existingFiles) {
|
|
234
251
|
project.removeSourceFile(file);
|
|
235
252
|
}
|
|
236
|
-
// Add current batch files
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
catch (error) {
|
|
242
|
-
console.warn(`Failed to add file ${filePath}:`, error);
|
|
243
|
-
}
|
|
253
|
+
// Add current batch files; a cancel during the load stops the scan
|
|
254
|
+
const loaded = await loadSourceFiles(project, batchFiles, { signal: ctx.signal });
|
|
255
|
+
if (loaded.cancelled) {
|
|
256
|
+
cancelled = true;
|
|
257
|
+
break;
|
|
244
258
|
}
|
|
245
259
|
console.info(`Batch ${batchNum + 1}: Project now has ${project.getSourceFiles().length} source files`);
|
|
246
260
|
// Create PublicApi for this batch
|
|
@@ -248,6 +262,11 @@ export class ScanSolidTool {
|
|
|
248
262
|
// Analyze files in this batch
|
|
249
263
|
let batchViolationCount = 0;
|
|
250
264
|
for (const sourceFile of project.getSourceFiles()) {
|
|
265
|
+
await yieldIfCancellable(ctx.signal);
|
|
266
|
+
if (ctx.signal?.aborted === true) {
|
|
267
|
+
cancelled = true;
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
251
270
|
for (const rule of allRules) {
|
|
252
271
|
try {
|
|
253
272
|
const ruleResults = await rule.analyze(ContextFactory.createAnalysisContext({
|
|
@@ -260,7 +279,7 @@ export class ScanSolidTool {
|
|
|
260
279
|
for (const result of ruleResults) {
|
|
261
280
|
results.push({
|
|
262
281
|
ruleId: result.ruleId,
|
|
263
|
-
severity: rule.severity,
|
|
282
|
+
severity: result.severity ?? rule.severity,
|
|
264
283
|
message: result.message,
|
|
265
284
|
filePath: result.filePath,
|
|
266
285
|
line: result.line,
|
|
@@ -276,6 +295,8 @@ export class ScanSolidTool {
|
|
|
276
295
|
console.warn(`Failed to analyze with rule ${rule.id}:`, error);
|
|
277
296
|
}
|
|
278
297
|
}
|
|
298
|
+
processedFiles++;
|
|
299
|
+
ctx.progress?.(cachedFiles + processedFiles, filesToAnalyze.length, fileProgressMessage(cachedFiles + processedFiles, filesToAnalyze.length, results.length));
|
|
279
300
|
}
|
|
280
301
|
filesAnalyzed += batchFiles.length;
|
|
281
302
|
console.info(`Batch ${batchNum + 1}: Found ${batchViolationCount} violations in ${batchFiles.length} files`);
|
|
@@ -354,13 +375,23 @@ export class ScanSolidTool {
|
|
|
354
375
|
const offset = mergedParams.resultOffset ?? 0;
|
|
355
376
|
const maxResults = mergedParams.maxResults ?? 1000;
|
|
356
377
|
const paginatedViolations = violations.slice(offset, offset + maxResults);
|
|
357
|
-
//
|
|
358
|
-
const
|
|
378
|
+
// Counts cover every violation, not only the page
|
|
379
|
+
const analyzedFiles = cancelled ? cachedFiles + processedFiles : filesToAnalyze.length;
|
|
380
|
+
const counts = this.calculateSummary(violations, analyzedFiles);
|
|
381
|
+
const execution = cancelled
|
|
382
|
+
? cancelledExecution(analyzedFiles, filesToAnalyze.length - analyzedFiles)
|
|
383
|
+
: undefined;
|
|
384
|
+
const pagination = {
|
|
385
|
+
totalResults: totalViolations,
|
|
386
|
+
returnedResults: paginatedViolations.length,
|
|
387
|
+
offset,
|
|
388
|
+
hasMore: offset + maxResults < totalViolations,
|
|
389
|
+
};
|
|
359
390
|
const duration = Date.now() - startTime;
|
|
360
391
|
const ruleIds = allRules.map((r) => r.id);
|
|
361
392
|
return {
|
|
362
393
|
violations: paginatedViolations,
|
|
363
|
-
|
|
394
|
+
counts,
|
|
364
395
|
metadata: {
|
|
365
396
|
rulesExecuted: ruleIds,
|
|
366
397
|
duration,
|
|
@@ -377,12 +408,9 @@ export class ScanSolidTool {
|
|
|
377
408
|
throughput: filesToAnalyze.length / (duration / 1000),
|
|
378
409
|
}
|
|
379
410
|
: undefined,
|
|
380
|
-
pagination
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
offset,
|
|
384
|
-
hasMore: offset + maxResults < totalViolations,
|
|
385
|
-
},
|
|
411
|
+
pagination,
|
|
412
|
+
...(execution === undefined ? {} : { execution }),
|
|
413
|
+
summary: describeScan(counts, paginatedViolations, pagination, execution === undefined ? [] : [execution.note]),
|
|
386
414
|
};
|
|
387
415
|
}
|
|
388
416
|
/**
|
|
@@ -19,8 +19,9 @@
|
|
|
19
19
|
* // args: { query: 'selector:\\s*["\']app-[^"\']+', mode: 'pattern', projectRoot: '/project' }
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
|
-
import { type MCPTool } from '../types.js';
|
|
22
|
+
import { type MCPTool, type ToolAnnotations } from '../types.js';
|
|
23
23
|
import { type SearchCoverage, type SearchResult } from '@angular-modernizer/api';
|
|
24
|
+
import { ProjectCache } from './helpers/project-cache.js';
|
|
24
25
|
/**
|
|
25
26
|
* Output of the search-codebase tool.
|
|
26
27
|
*/
|
|
@@ -34,15 +35,22 @@ interface SearchCodebaseOutput {
|
|
|
34
35
|
/** Present when 0 hits were found: why that does not prove absence. */
|
|
35
36
|
hint?: string;
|
|
36
37
|
};
|
|
38
|
+
/** Conditions that can make the result incomplete (unresolved library imports). */
|
|
39
|
+
warnings?: string[];
|
|
37
40
|
}
|
|
38
41
|
/**
|
|
39
42
|
* MCP tool that searches TypeScript source files by text, regex, or symbol.
|
|
40
43
|
*/
|
|
41
44
|
export declare class SearchCodebaseTool implements MCPTool {
|
|
45
|
+
private readonly projects;
|
|
42
46
|
readonly name = "search-codebase";
|
|
47
|
+
readonly title = "Search Codebase";
|
|
48
|
+
readonly annotations: ToolAnnotations;
|
|
49
|
+
constructor(projects?: ProjectCache);
|
|
43
50
|
readonly description: string;
|
|
44
51
|
readonly inputSchema: {
|
|
45
52
|
type: string;
|
|
53
|
+
additionalProperties: boolean;
|
|
46
54
|
properties: {
|
|
47
55
|
query: {
|
|
48
56
|
type: string;
|
|
@@ -76,6 +84,82 @@ export declare class SearchCodebaseTool implements MCPTool {
|
|
|
76
84
|
};
|
|
77
85
|
required: string[];
|
|
78
86
|
};
|
|
87
|
+
readonly outputSchema: {
|
|
88
|
+
type: string;
|
|
89
|
+
properties: {
|
|
90
|
+
warnings: {
|
|
91
|
+
readonly type: "array";
|
|
92
|
+
readonly items: {
|
|
93
|
+
readonly type: "string";
|
|
94
|
+
};
|
|
95
|
+
readonly description: "Conditions that can make the result incomplete, e.g. library imports that do not resolve because node_modules is missing.";
|
|
96
|
+
};
|
|
97
|
+
results: {
|
|
98
|
+
type: string;
|
|
99
|
+
items: {
|
|
100
|
+
type: string;
|
|
101
|
+
properties: {
|
|
102
|
+
file: {
|
|
103
|
+
type: string;
|
|
104
|
+
};
|
|
105
|
+
line: {
|
|
106
|
+
type: string;
|
|
107
|
+
};
|
|
108
|
+
col: {
|
|
109
|
+
type: string;
|
|
110
|
+
};
|
|
111
|
+
snippet: {
|
|
112
|
+
type: string;
|
|
113
|
+
};
|
|
114
|
+
symbolKind: {
|
|
115
|
+
type: string;
|
|
116
|
+
};
|
|
117
|
+
source: {
|
|
118
|
+
type: string;
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
required: string[];
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
totalCount: {
|
|
125
|
+
type: string;
|
|
126
|
+
};
|
|
127
|
+
summary: {
|
|
128
|
+
type: string;
|
|
129
|
+
};
|
|
130
|
+
coverage: {
|
|
131
|
+
type: string;
|
|
132
|
+
properties: {
|
|
133
|
+
programFileCount: {
|
|
134
|
+
type: string;
|
|
135
|
+
};
|
|
136
|
+
extraFileCount: {
|
|
137
|
+
type: string;
|
|
138
|
+
};
|
|
139
|
+
templatesScanned: {
|
|
140
|
+
type: string;
|
|
141
|
+
};
|
|
142
|
+
nonProgramFilesScanned: {
|
|
143
|
+
type: string;
|
|
144
|
+
};
|
|
145
|
+
excludedDirectories: {
|
|
146
|
+
type: string;
|
|
147
|
+
items: {
|
|
148
|
+
type: string;
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
tsConfigPath: {
|
|
152
|
+
type: string;
|
|
153
|
+
};
|
|
154
|
+
hint: {
|
|
155
|
+
type: string;
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
required: string[];
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
required: string[];
|
|
162
|
+
};
|
|
79
163
|
execute(args: Record<string, unknown>): Promise<SearchCodebaseOutput>;
|
|
80
164
|
/**
|
|
81
165
|
* Explains why 0 hits is not proof of absence, naming what was excluded.
|
|
@@ -19,15 +19,27 @@
|
|
|
19
19
|
* // args: { query: 'selector:\\s*["\']app-[^"\']+', mode: 'pattern', projectRoot: '/project' }
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
|
-
import { Project } from 'ts-morph';
|
|
23
22
|
import { CodebaseSearcher, } from '@angular-modernizer/api';
|
|
24
23
|
import { existsSync } from 'node:fs';
|
|
25
24
|
import { findTsConfig } from './helpers/find-ts-config.js';
|
|
25
|
+
import { ProjectCache } from './helpers/project-cache.js';
|
|
26
|
+
import { WARNINGS_OUTPUT_SCHEMA, withWarnings, } from './helpers/output-contract.js';
|
|
26
27
|
/**
|
|
27
28
|
* MCP tool that searches TypeScript source files by text, regex, or symbol.
|
|
28
29
|
*/
|
|
29
30
|
export class SearchCodebaseTool {
|
|
31
|
+
projects;
|
|
30
32
|
name = 'search-codebase';
|
|
33
|
+
title = 'Search Codebase';
|
|
34
|
+
annotations = {
|
|
35
|
+
readOnlyHint: true,
|
|
36
|
+
destructiveHint: false,
|
|
37
|
+
idempotentHint: true,
|
|
38
|
+
openWorldHint: false,
|
|
39
|
+
};
|
|
40
|
+
constructor(projects = new ProjectCache()) {
|
|
41
|
+
this.projects = projects;
|
|
42
|
+
}
|
|
31
43
|
description = 'Search TypeScript source files in a project. Three modes: ' +
|
|
32
44
|
'"text" (literal substring), "pattern" (regular expression), ' +
|
|
33
45
|
'"symbol" (TypeScript class/function/interface/enum/type declaration by name). ' +
|
|
@@ -40,6 +52,7 @@ export class SearchCodebaseTool {
|
|
|
40
52
|
'declarations, or discover all files that reference a specific pattern.';
|
|
41
53
|
inputSchema = {
|
|
42
54
|
type: 'object',
|
|
55
|
+
additionalProperties: false,
|
|
43
56
|
properties: {
|
|
44
57
|
query: {
|
|
45
58
|
type: 'string',
|
|
@@ -76,6 +89,50 @@ export class SearchCodebaseTool {
|
|
|
76
89
|
},
|
|
77
90
|
required: ['query', 'mode', 'projectRoot'],
|
|
78
91
|
};
|
|
92
|
+
outputSchema = {
|
|
93
|
+
type: 'object',
|
|
94
|
+
properties: {
|
|
95
|
+
results: {
|
|
96
|
+
type: 'array',
|
|
97
|
+
items: {
|
|
98
|
+
type: 'object',
|
|
99
|
+
properties: {
|
|
100
|
+
file: { type: 'string' },
|
|
101
|
+
line: { type: 'integer' },
|
|
102
|
+
col: { type: 'integer' },
|
|
103
|
+
snippet: { type: 'string' },
|
|
104
|
+
symbolKind: { type: 'string' },
|
|
105
|
+
source: { type: 'string' },
|
|
106
|
+
},
|
|
107
|
+
required: ['file', 'line', 'col', 'snippet'],
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
totalCount: { type: 'integer' },
|
|
111
|
+
summary: { type: 'string' },
|
|
112
|
+
coverage: {
|
|
113
|
+
type: 'object',
|
|
114
|
+
properties: {
|
|
115
|
+
programFileCount: { type: 'integer' },
|
|
116
|
+
extraFileCount: { type: 'integer' },
|
|
117
|
+
templatesScanned: { type: 'boolean' },
|
|
118
|
+
nonProgramFilesScanned: { type: 'boolean' },
|
|
119
|
+
excludedDirectories: { type: 'array', items: { type: 'string' } },
|
|
120
|
+
tsConfigPath: { type: 'string' },
|
|
121
|
+
hint: { type: 'string' },
|
|
122
|
+
},
|
|
123
|
+
required: [
|
|
124
|
+
'programFileCount',
|
|
125
|
+
'extraFileCount',
|
|
126
|
+
'templatesScanned',
|
|
127
|
+
'nonProgramFilesScanned',
|
|
128
|
+
'excludedDirectories',
|
|
129
|
+
'tsConfigPath',
|
|
130
|
+
],
|
|
131
|
+
},
|
|
132
|
+
...WARNINGS_OUTPUT_SCHEMA,
|
|
133
|
+
},
|
|
134
|
+
required: ['results', 'totalCount', 'summary', 'coverage'],
|
|
135
|
+
};
|
|
79
136
|
async execute(args) {
|
|
80
137
|
const params = args;
|
|
81
138
|
if (!params.query) {
|
|
@@ -94,7 +151,7 @@ export class SearchCodebaseTool {
|
|
|
94
151
|
if (!tsConfigPath) {
|
|
95
152
|
throw new Error(`tsconfig.json not found in projectRoot: ${params.projectRoot}`);
|
|
96
153
|
}
|
|
97
|
-
const project =
|
|
154
|
+
const project = this.projects.get(tsConfigPath);
|
|
98
155
|
const searcher = new CodebaseSearcher(project);
|
|
99
156
|
const { results, coverage } = searcher.searchWithCoverage(params.query, {
|
|
100
157
|
mode: params.mode,
|
|
@@ -105,7 +162,7 @@ export class SearchCodebaseTool {
|
|
|
105
162
|
includeNonProgramFiles: params.includeNonProgramFiles !== false,
|
|
106
163
|
});
|
|
107
164
|
const hint = results.length === 0 ? this.buildZeroHitHint(params.mode, coverage) : undefined;
|
|
108
|
-
return {
|
|
165
|
+
return withWarnings({
|
|
109
166
|
results,
|
|
110
167
|
totalCount: results.length,
|
|
111
168
|
summary: this.buildSummary(params.query, params.mode, results, hint),
|
|
@@ -114,7 +171,7 @@ export class SearchCodebaseTool {
|
|
|
114
171
|
tsConfigPath,
|
|
115
172
|
...(hint === undefined ? {} : { hint }),
|
|
116
173
|
},
|
|
117
|
-
};
|
|
174
|
+
}, this.projects.warnings(tsConfigPath));
|
|
118
175
|
}
|
|
119
176
|
/**
|
|
120
177
|
* Explains why 0 hits is not proof of absence, naming what was excluded.
|