@angular-modernizer/adapter-mcp 0.3.0 → 1.1.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 +181 -282
- package/dist/cli.js +21 -13
- package/dist/core/project-analyzer.d.ts +3 -12
- package/dist/core/project-analyzer.js +3 -12
- package/dist/index.d.ts +122 -6
- package/dist/index.js +49 -5
- package/dist/mcp-watcher.d.ts +32 -7
- package/dist/mcp-watcher.js +16 -15
- package/dist/scan-host/scan-host.d.ts +119 -0
- package/dist/scan-host/scan-host.js +376 -0
- package/dist/scan-host/scan-protocol.d.ts +35 -0
- package/dist/scan-host/scan-protocol.js +6 -0
- package/dist/scan-host/scan-worker.d.ts +14 -0
- package/dist/scan-host/scan-worker.js +48 -0
- package/dist/server/limited-stdio-transport.d.ts +75 -0
- package/dist/server/limited-stdio-transport.js +115 -0
- package/dist/server/mcp-server.d.ts +20 -18
- package/dist/server/mcp-server.js +42 -79
- package/dist/server/package-version.d.ts +16 -0
- package/dist/server/package-version.js +37 -0
- package/dist/server/sdk-server.d.ts +71 -0
- package/dist/server/sdk-server.js +113 -0
- package/dist/server/tool-registry.d.ts +6 -9
- package/dist/server/tool-registry.js +6 -12
- package/dist/streaming/progress-store.d.ts +22 -5
- package/dist/streaming/progress-store.js +9 -5
- package/dist/tools/analyze-build-impact.d.ts +276 -35
- package/dist/tools/analyze-build-impact.js +175 -28
- package/dist/tools/analyze-core-to-shared.d.ts +176 -16
- package/dist/tools/analyze-core-to-shared.js +124 -19
- package/dist/tools/analyze-parser-performance.d.ts +209 -15
- package/dist/tools/analyze-parser-performance.js +119 -56
- package/dist/tools/analyze-project.d.ts +349 -17
- package/dist/tools/analyze-project.js +282 -97
- package/dist/tools/check-incremental-compatibility.d.ts +74 -12
- package/dist/tools/check-incremental-compatibility.js +69 -10
- package/dist/tools/collect-feedback.d.ts +225 -21
- package/dist/tools/collect-feedback.js +199 -118
- package/dist/tools/compare-health.d.ts +413 -0
- package/dist/tools/compare-health.js +479 -0
- package/dist/tools/extract-libraries.d.ts +200 -24
- package/dist/tools/extract-libraries.js +131 -27
- package/dist/tools/find-angular-symbol.d.ts +92 -24
- package/dist/tools/find-angular-symbol.js +70 -20
- package/dist/tools/find-component-hosts.d.ts +603 -27
- package/dist/tools/find-component-hosts.js +223 -19
- package/dist/tools/find-usages.d.ts +102 -22
- package/dist/tools/find-usages.js +81 -21
- package/dist/tools/get-bootstrap-execution.d.ts +183 -25
- package/dist/tools/get-bootstrap-execution.js +109 -25
- package/dist/tools/get-call-graph.d.ts +127 -12
- package/dist/tools/get-call-graph.js +84 -19
- package/dist/tools/get-operation-progress-tool.d.ts +126 -8
- package/dist/tools/get-operation-progress-tool.js +124 -12
- package/dist/tools/get-operation-progress.d.ts +27 -1
- package/dist/tools/get-operation-progress.js +5 -5
- package/dist/tools/helpers/analysis-output.d.ts +182 -0
- package/dist/tools/helpers/analysis-output.js +165 -0
- package/dist/tools/helpers/batch-kernel.d.ts +14 -0
- package/dist/tools/helpers/batch-kernel.js +12 -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 +2 -1
- package/dist/tools/helpers/compact-output.js +2 -1
- 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 +99 -0
- package/dist/tools/helpers/health-delta.js +236 -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 +60 -37
- package/dist/tools/helpers/project-cache.js +54 -37
- 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 +25 -13
- package/dist/tools/helpers/rule-runner.js +45 -24
- package/dist/tools/helpers/scan-cache.d.ts +22 -0
- package/dist/tools/helpers/scan-cache.js +34 -0
- package/dist/tools/helpers/scan-engine.d.ts +107 -0
- package/dist/tools/helpers/scan-engine.js +197 -0
- package/dist/tools/helpers/scan-plan.d.ts +5 -2
- package/dist/tools/helpers/scan-plan.js +18 -3
- package/dist/tools/helpers/scope-paths.d.ts +17 -0
- package/dist/tools/helpers/scope-paths.js +32 -0
- package/dist/tools/helpers/suggestion-generator.d.ts +9 -13
- package/dist/tools/helpers/suggestion-generator.js +0 -12
- package/dist/tools/helpers/tool-cache.d.ts +11 -0
- package/dist/tools/helpers/tool-cache.js +15 -0
- package/dist/tools/helpers/tool-context.d.ts +63 -0
- package/dist/tools/helpers/tool-context.js +79 -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 +262 -24
- package/dist/tools/inspect-form-group.js +134 -13
- package/dist/tools/inspect-i18n.d.ts +410 -23
- package/dist/tools/inspect-i18n.js +213 -13
- package/dist/tools/inspect-template.d.ts +260 -22
- package/dist/tools/inspect-template.js +174 -13
- package/dist/tools/learn-patterns.d.ts +210 -13
- package/dist/tools/learn-patterns.js +113 -12
- package/dist/tools/list-imports.d.ts +152 -34
- package/dist/tools/list-imports.js +124 -18
- package/dist/tools/orchestrate-migration.d.ts +159 -14
- package/dist/tools/orchestrate-migration.js +147 -20
- package/dist/tools/parse-stack-trace.d.ts +78 -21
- package/dist/tools/parse-stack-trace.js +44 -7
- package/dist/tools/plan-migration.d.ts +395 -26
- package/dist/tools/plan-migration.js +173 -22
- package/dist/tools/resolve-type.d.ts +57 -9
- package/dist/tools/resolve-type.js +49 -12
- package/dist/tools/review-feedback.d.ts +214 -16
- package/dist/tools/review-feedback.js +142 -57
- package/dist/tools/rollback-changes.d.ts +88 -7
- package/dist/tools/rollback-changes.js +74 -19
- package/dist/tools/run-angular-cli.d.ts +57 -12
- package/dist/tools/run-angular-cli.js +76 -13
- package/dist/tools/run-build.d.ts +127 -13
- package/dist/tools/run-build.js +128 -16
- package/dist/tools/run-schematic.d.ts +82 -12
- package/dist/tools/run-schematic.js +115 -18
- package/dist/tools/scan-all.d.ts +88 -23
- package/dist/tools/scan-all.js +161 -220
- package/dist/tools/scan-angular.d.ts +60 -19
- package/dist/tools/scan-angular.js +100 -141
- package/dist/tools/scan-architecture.d.ts +92 -24
- package/dist/tools/scan-architecture.js +268 -211
- package/dist/tools/scan-solid.d.ts +59 -19
- package/dist/tools/scan-solid.js +98 -139
- package/dist/tools/search-codebase.d.ts +110 -23
- package/dist/tools/search-codebase.js +67 -11
- package/dist/tools/server-status.d.ts +392 -26
- package/dist/tools/server-status.js +260 -27
- package/dist/tools/suggest-improvements.d.ts +105 -10
- package/dist/tools/suggest-improvements.js +91 -51
- package/dist/tools/trace-output-flow.d.ts +713 -26
- package/dist/tools/trace-output-flow.js +396 -33
- 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 +402 -18
- package/dist/tools/transform-code.js +708 -649
- package/dist/tools/validate-before-transform.d.ts +136 -7
- package/dist/tools/validate-before-transform.js +65 -9
- package/dist/tools/validate-project-compatibility.d.ts +82 -15
- package/dist/tools/validate-project-compatibility.js +84 -15
- package/dist/tools/validate-transformation.d.ts +243 -8
- package/dist/tools/validate-transformation.js +127 -23
- package/dist/tools/verify-citations.d.ts +202 -0
- package/dist/tools/verify-citations.js +221 -0
- package/dist/types.d.ts +78 -11
- package/dist/types.js +0 -5
- package/dist/utils/format-tool-response.d.ts +22 -59
- package/dist/utils/format-tool-response.js +25 -134
- package/package.json +31 -20
- 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 -98
- package/dist/server/json-rpc-handler.d.ts.map +0 -1
- package/dist/server/json-rpc-handler.js +0 -301
- 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/stdio-guard.d.ts.map +0 -1
- package/dist/server/stdio-guard.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-component-hosts.d.ts.map +0 -1
- package/dist/tools/find-component-hosts.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-bootstrap-execution.d.ts.map +0 -1
- package/dist/tools/get-bootstrap-execution.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/compact-output.d.ts.map +0 -1
- package/dist/tools/helpers/compact-output.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/project-cache.d.ts.map +0 -1
- package/dist/tools/helpers/project-cache.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/rule-runner.d.ts.map +0 -1
- package/dist/tools/helpers/rule-runner.js.map +0 -1
- package/dist/tools/helpers/scan-plan.d.ts.map +0 -1
- package/dist/tools/helpers/scan-plan.js.map +0 -1
- package/dist/tools/helpers/stack-frame-file-index.d.ts.map +0 -1
- package/dist/tools/helpers/stack-frame-file-index.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/inspect-form-group.d.ts.map +0 -1
- package/dist/tools/inspect-form-group.js.map +0 -1
- package/dist/tools/inspect-i18n.d.ts.map +0 -1
- package/dist/tools/inspect-i18n.js.map +0 -1
- package/dist/tools/inspect-template.d.ts.map +0 -1
- package/dist/tools/inspect-template.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/server-status.d.ts.map +0 -1
- package/dist/tools/server-status.js.map +0 -1
- package/dist/tools/shared/scan-types.d.ts +0 -200
- package/dist/tools/shared/scan-types.d.ts.map +0 -1
- package/dist/tools/shared/scan-types.js +0 -7
- 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/trace-output-flow.d.ts.map +0 -1
- package/dist/tools/trace-output-flow.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,479 @@
|
|
|
1
|
+
import { isAbsolute, relative, resolve } from 'node:path';
|
|
2
|
+
import { RealFileSystemAdapter, } from '@angular-modernizer/core';
|
|
3
|
+
import { COMPACT_OUTPUT_SCHEMA, limitList, parseCompactOptions, } from './helpers/compact-output.js';
|
|
4
|
+
import { DEFAULT_HEALTH_SNAPSHOT_PATH, HEALTH_SNAPSHOT_VERSION, compareHealth, compareViolations, parseHealthSnapshot, scopeDifferences, serializeHealthSnapshot, } from './helpers/health-delta.js';
|
|
5
|
+
import { ScanAllTool } from './scan-all.js';
|
|
6
|
+
/** Violations spelled out per list in the summary; the rest is in the lists. */
|
|
7
|
+
const SUMMARY_LINES = 15;
|
|
8
|
+
const STRING_LIST = { type: 'array', items: { type: 'string' } };
|
|
9
|
+
const VIOLATION_SCHEMA = {
|
|
10
|
+
type: 'object',
|
|
11
|
+
properties: {
|
|
12
|
+
ruleId: { type: 'string' },
|
|
13
|
+
filePath: { type: 'string' },
|
|
14
|
+
message: { type: 'string' },
|
|
15
|
+
severity: { type: 'string' },
|
|
16
|
+
category: { type: 'string' },
|
|
17
|
+
line: { type: 'integer' },
|
|
18
|
+
},
|
|
19
|
+
required: ['ruleId', 'filePath', 'message', 'severity', 'category'],
|
|
20
|
+
};
|
|
21
|
+
const RUN_SCHEMA = {
|
|
22
|
+
type: 'object',
|
|
23
|
+
properties: {
|
|
24
|
+
createdAt: { type: 'string' },
|
|
25
|
+
analyzedFiles: { type: 'integer' },
|
|
26
|
+
totalViolations: { type: 'integer' },
|
|
27
|
+
},
|
|
28
|
+
required: ['createdAt', 'analyzedFiles', 'totalViolations'],
|
|
29
|
+
};
|
|
30
|
+
const COUNTS_SCHEMA = {
|
|
31
|
+
type: 'object',
|
|
32
|
+
additionalProperties: { type: 'integer' },
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* MCP tool `compare-health`: runs the scan-all scan and compares it with the
|
|
36
|
+
* previous run: which violations are new, fixed or unchanged, per rule and
|
|
37
|
+
* per file.
|
|
38
|
+
*
|
|
39
|
+
* @remarks
|
|
40
|
+
* scan-all returns a window of `maxResults` violations and sums only that
|
|
41
|
+
* window, so a comparison of two scan-all answers would compare two windows.
|
|
42
|
+
* This tool takes the complete result, stores it as a snapshot in the target
|
|
43
|
+
* project (default `.angular-modernizer-cache/health/last-run.json`, ignored
|
|
44
|
+
* like the cache) and compares the next run against it.
|
|
45
|
+
*
|
|
46
|
+
* The snapshot is replaced after every comparison unless `updateSnapshot` is
|
|
47
|
+
* false. When the stored run used another scope (rules, include or exclude
|
|
48
|
+
* patterns) or the file cannot be read, nothing is compared and the file is
|
|
49
|
+
* kept unless `updateSnapshot` is explicitly true. A cancelled scan throws
|
|
50
|
+
* instead of comparing or writing a partial snapshot.
|
|
51
|
+
*/
|
|
52
|
+
export class CompareHealthTool {
|
|
53
|
+
scan;
|
|
54
|
+
fileSystem;
|
|
55
|
+
now;
|
|
56
|
+
name = 'compare-health';
|
|
57
|
+
title = 'Compare Health With Last Run';
|
|
58
|
+
description = 'Run the full scan-all scan (all violations, no result window) and compare it with the previous run ' +
|
|
59
|
+
'stored in the project: new, fixed and unchanged violations, per rule (byRule) and per changed file ' +
|
|
60
|
+
'(byFile), plus the lists newViolations and fixedViolations. Violations match by rule, file and message ' +
|
|
61
|
+
'with digits ignored, not by line, so code moving up or down stays unchanged. The first run writes the ' +
|
|
62
|
+
'baseline (status baseline-created). After a comparison the snapshot is replaced by the current run ' +
|
|
63
|
+
'unless updateSnapshot is false. A snapshot taken with other rules or include/exclude patterns is not ' +
|
|
64
|
+
'compared (status scope-mismatch) and is only replaced with updateSnapshot: true. currentRun.bySeverity ' +
|
|
65
|
+
'and byCategory count all violations. Writes only the snapshot file.';
|
|
66
|
+
annotations = {
|
|
67
|
+
readOnlyHint: false,
|
|
68
|
+
destructiveHint: false,
|
|
69
|
+
idempotentHint: false,
|
|
70
|
+
openWorldHint: false,
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* JSON Schema of the tool arguments.
|
|
74
|
+
* @hidden
|
|
75
|
+
*/
|
|
76
|
+
inputSchema = {
|
|
77
|
+
type: 'object',
|
|
78
|
+
additionalProperties: false,
|
|
79
|
+
properties: {
|
|
80
|
+
rootPath: {
|
|
81
|
+
type: 'string',
|
|
82
|
+
description: 'Root path of the project to scan',
|
|
83
|
+
},
|
|
84
|
+
rules: {
|
|
85
|
+
...STRING_LIST,
|
|
86
|
+
description: 'Rule IDs to compare (optional, all 52 if not specified). Part of the snapshot scope.',
|
|
87
|
+
},
|
|
88
|
+
includePatterns: {
|
|
89
|
+
...STRING_LIST,
|
|
90
|
+
description: 'File patterns to include, as in scan-all. Part of the snapshot scope.',
|
|
91
|
+
},
|
|
92
|
+
excludePatterns: {
|
|
93
|
+
...STRING_LIST,
|
|
94
|
+
description: 'File patterns to exclude, as in scan-all. Part of the snapshot scope.',
|
|
95
|
+
},
|
|
96
|
+
maxFiles: {
|
|
97
|
+
type: 'number',
|
|
98
|
+
description: 'Batch size for processing files, as in scan-all.',
|
|
99
|
+
},
|
|
100
|
+
snapshotPath: {
|
|
101
|
+
type: 'string',
|
|
102
|
+
description: `Snapshot file, absolute or relative to rootPath. Default: ${DEFAULT_HEALTH_SNAPSHOT_PATH}.`,
|
|
103
|
+
},
|
|
104
|
+
updateSnapshot: {
|
|
105
|
+
type: 'boolean',
|
|
106
|
+
description: 'false: compare only, keep the stored snapshot. true: also replace a snapshot with another scope or ' +
|
|
107
|
+
'an unreadable one. Default: replace after a comparison and write the first baseline.',
|
|
108
|
+
},
|
|
109
|
+
...COMPACT_OUTPUT_SCHEMA,
|
|
110
|
+
},
|
|
111
|
+
required: ['rootPath'],
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* JSON Schema of the tool result (`structuredContent`).
|
|
115
|
+
* @hidden
|
|
116
|
+
*/
|
|
117
|
+
outputSchema = {
|
|
118
|
+
type: 'object',
|
|
119
|
+
properties: {
|
|
120
|
+
status: {
|
|
121
|
+
type: 'string',
|
|
122
|
+
enum: [
|
|
123
|
+
'compared',
|
|
124
|
+
'baseline-created',
|
|
125
|
+
'no-baseline',
|
|
126
|
+
'scope-mismatch',
|
|
127
|
+
'invalid-snapshot',
|
|
128
|
+
],
|
|
129
|
+
},
|
|
130
|
+
projectRoot: { type: 'string' },
|
|
131
|
+
snapshotPath: { type: 'string' },
|
|
132
|
+
snapshotWritten: { type: 'boolean' },
|
|
133
|
+
previousRun: RUN_SCHEMA,
|
|
134
|
+
currentRun: {
|
|
135
|
+
type: 'object',
|
|
136
|
+
properties: {
|
|
137
|
+
...RUN_SCHEMA.properties,
|
|
138
|
+
bySeverity: COUNTS_SCHEMA,
|
|
139
|
+
byCategory: COUNTS_SCHEMA,
|
|
140
|
+
},
|
|
141
|
+
required: [...RUN_SCHEMA.required, 'bySeverity', 'byCategory'],
|
|
142
|
+
},
|
|
143
|
+
totals: {
|
|
144
|
+
type: 'object',
|
|
145
|
+
properties: {
|
|
146
|
+
new: { type: 'integer' },
|
|
147
|
+
fixed: { type: 'integer' },
|
|
148
|
+
unchanged: { type: 'integer' },
|
|
149
|
+
},
|
|
150
|
+
required: ['new', 'fixed', 'unchanged'],
|
|
151
|
+
},
|
|
152
|
+
byRule: {
|
|
153
|
+
type: 'array',
|
|
154
|
+
items: {
|
|
155
|
+
type: 'object',
|
|
156
|
+
properties: {
|
|
157
|
+
ruleId: { type: 'string' },
|
|
158
|
+
previous: { type: 'integer' },
|
|
159
|
+
current: { type: 'integer' },
|
|
160
|
+
new: { type: 'integer' },
|
|
161
|
+
fixed: { type: 'integer' },
|
|
162
|
+
unchanged: { type: 'integer' },
|
|
163
|
+
},
|
|
164
|
+
required: [
|
|
165
|
+
'ruleId',
|
|
166
|
+
'previous',
|
|
167
|
+
'current',
|
|
168
|
+
'new',
|
|
169
|
+
'fixed',
|
|
170
|
+
'unchanged',
|
|
171
|
+
],
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
byFile: {
|
|
175
|
+
type: 'array',
|
|
176
|
+
items: {
|
|
177
|
+
type: 'object',
|
|
178
|
+
properties: {
|
|
179
|
+
filePath: { type: 'string' },
|
|
180
|
+
previous: { type: 'integer' },
|
|
181
|
+
current: { type: 'integer' },
|
|
182
|
+
new: { type: 'integer' },
|
|
183
|
+
fixed: { type: 'integer' },
|
|
184
|
+
},
|
|
185
|
+
required: ['filePath', 'previous', 'current', 'new', 'fixed'],
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
newViolations: { type: 'array', items: VIOLATION_SCHEMA },
|
|
189
|
+
fixedViolations: { type: 'array', items: VIOLATION_SCHEMA },
|
|
190
|
+
rulesAdded: STRING_LIST,
|
|
191
|
+
rulesRemoved: STRING_LIST,
|
|
192
|
+
scopeDifferences: STRING_LIST,
|
|
193
|
+
truncated: { type: 'boolean' },
|
|
194
|
+
summary: { type: 'string' },
|
|
195
|
+
},
|
|
196
|
+
required: [
|
|
197
|
+
'status',
|
|
198
|
+
'projectRoot',
|
|
199
|
+
'snapshotPath',
|
|
200
|
+
'snapshotWritten',
|
|
201
|
+
'currentRun',
|
|
202
|
+
'byRule',
|
|
203
|
+
'rulesAdded',
|
|
204
|
+
'rulesRemoved',
|
|
205
|
+
'scopeDifferences',
|
|
206
|
+
'truncated',
|
|
207
|
+
'summary',
|
|
208
|
+
],
|
|
209
|
+
};
|
|
210
|
+
constructor(scan = (args, ctx) => new ScanAllTool().execute(args, ctx), fileSystem = new RealFileSystemAdapter(), now = () => new Date()) {
|
|
211
|
+
this.scan = scan;
|
|
212
|
+
this.fileSystem = fileSystem;
|
|
213
|
+
this.now = now;
|
|
214
|
+
}
|
|
215
|
+
async execute(args, ctx = {}) {
|
|
216
|
+
const input = parseInput(args);
|
|
217
|
+
const compact = parseCompactOptions(args);
|
|
218
|
+
const root = resolve(input.rootPath);
|
|
219
|
+
const snapshotFile = isAbsolute(input.snapshotPath)
|
|
220
|
+
? input.snapshotPath
|
|
221
|
+
: resolve(root, input.snapshotPath);
|
|
222
|
+
const snapshotLabel = relative(root, snapshotFile).startsWith('..')
|
|
223
|
+
? snapshotFile
|
|
224
|
+
: relative(root, snapshotFile);
|
|
225
|
+
const scanResult = await this.scan(scanArguments(root, input), ctx);
|
|
226
|
+
// A cancelled scan covers only part of the project: comparing it would
|
|
227
|
+
// report the rest as fixed, and writing it would replace the baseline
|
|
228
|
+
if (scanResult.execution?.stopReason === 'cancelled') {
|
|
229
|
+
throw new Error('Scan cancelled; snapshot not compared or written.');
|
|
230
|
+
}
|
|
231
|
+
const current = {
|
|
232
|
+
version: HEALTH_SNAPSHOT_VERSION,
|
|
233
|
+
createdAt: this.now().toISOString(),
|
|
234
|
+
scope: input.scope,
|
|
235
|
+
rulesExecuted: [...scanResult.metadata.rulesExecuted].sort(),
|
|
236
|
+
analyzedFiles: scanResult.counts.analyzedFiles,
|
|
237
|
+
violations: scanResult.violations
|
|
238
|
+
.map(toHealthViolation)
|
|
239
|
+
.sort(compareViolations),
|
|
240
|
+
};
|
|
241
|
+
const stored = await this.readSnapshot(snapshotFile);
|
|
242
|
+
const previous = stored.snapshot;
|
|
243
|
+
const differences = previous === undefined
|
|
244
|
+
? []
|
|
245
|
+
: scopeDifferences(previous.scope, current.scope);
|
|
246
|
+
const status = decideStatus(stored, differences);
|
|
247
|
+
const write = input.updateSnapshot === true ||
|
|
248
|
+
(input.updateSnapshot === undefined &&
|
|
249
|
+
(status === 'compared' || status === 'baseline-created'));
|
|
250
|
+
if (write) {
|
|
251
|
+
await this.fileSystem.writeFile(snapshotFile, serializeHealthSnapshot(current));
|
|
252
|
+
}
|
|
253
|
+
const output = buildOutput({
|
|
254
|
+
status,
|
|
255
|
+
root,
|
|
256
|
+
snapshotLabel,
|
|
257
|
+
written: write,
|
|
258
|
+
previous,
|
|
259
|
+
current,
|
|
260
|
+
differences,
|
|
261
|
+
compact,
|
|
262
|
+
});
|
|
263
|
+
return output;
|
|
264
|
+
}
|
|
265
|
+
async readSnapshot(path) {
|
|
266
|
+
if (!(await this.fileSystem.exists(path))) {
|
|
267
|
+
return { exists: false, snapshot: undefined };
|
|
268
|
+
}
|
|
269
|
+
const text = await this.fileSystem.readFile(path);
|
|
270
|
+
return { exists: true, snapshot: parseHealthSnapshot(text) };
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
function parseInput(args) {
|
|
274
|
+
const { rootPath, maxFiles, snapshotPath, updateSnapshot } = args;
|
|
275
|
+
if (typeof rootPath !== 'string' || rootPath === '') {
|
|
276
|
+
throw new Error('rootPath is required');
|
|
277
|
+
}
|
|
278
|
+
if (maxFiles !== undefined &&
|
|
279
|
+
(typeof maxFiles !== 'number' ||
|
|
280
|
+
!Number.isInteger(maxFiles) ||
|
|
281
|
+
maxFiles < 1)) {
|
|
282
|
+
throw new Error('maxFiles must be a positive integer');
|
|
283
|
+
}
|
|
284
|
+
if (snapshotPath !== undefined &&
|
|
285
|
+
(typeof snapshotPath !== 'string' || snapshotPath === '')) {
|
|
286
|
+
throw new Error('snapshotPath must be a non-empty string');
|
|
287
|
+
}
|
|
288
|
+
if (updateSnapshot !== undefined && typeof updateSnapshot !== 'boolean') {
|
|
289
|
+
throw new Error('updateSnapshot must be a boolean');
|
|
290
|
+
}
|
|
291
|
+
return {
|
|
292
|
+
rootPath,
|
|
293
|
+
scope: {
|
|
294
|
+
rules: stringList(args, 'rules'),
|
|
295
|
+
includePatterns: stringList(args, 'includePatterns'),
|
|
296
|
+
excludePatterns: stringList(args, 'excludePatterns'),
|
|
297
|
+
},
|
|
298
|
+
maxFiles,
|
|
299
|
+
snapshotPath: snapshotPath ?? DEFAULT_HEALTH_SNAPSHOT_PATH,
|
|
300
|
+
updateSnapshot,
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
function stringList(args, key) {
|
|
304
|
+
const value = args[key];
|
|
305
|
+
if (value === undefined) {
|
|
306
|
+
return null;
|
|
307
|
+
}
|
|
308
|
+
if (!Array.isArray(value) || !value.every((x) => typeof x === 'string')) {
|
|
309
|
+
throw new Error(`${key} must be an array of strings`);
|
|
310
|
+
}
|
|
311
|
+
return [...value].sort();
|
|
312
|
+
}
|
|
313
|
+
/** scan-all arguments for the complete result; unset keys stay unset so the project config applies. */
|
|
314
|
+
function scanArguments(root, input) {
|
|
315
|
+
const { rules, includePatterns, excludePatterns } = input.scope;
|
|
316
|
+
return {
|
|
317
|
+
rootPath: root,
|
|
318
|
+
includeAutoFixes: false,
|
|
319
|
+
maxResults: Number.MAX_SAFE_INTEGER,
|
|
320
|
+
resultOffset: 0,
|
|
321
|
+
...(rules === null ? {} : { rules }),
|
|
322
|
+
...(includePatterns === null ? {} : { includePatterns }),
|
|
323
|
+
...(excludePatterns === null ? {} : { excludePatterns }),
|
|
324
|
+
...(input.maxFiles === undefined ? {} : { maxFiles: input.maxFiles }),
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
function toHealthViolation(v) {
|
|
328
|
+
return {
|
|
329
|
+
ruleId: v.ruleId,
|
|
330
|
+
filePath: v.filePath,
|
|
331
|
+
message: v.message,
|
|
332
|
+
severity: v.severity,
|
|
333
|
+
category: v.category,
|
|
334
|
+
...(v.line === undefined ? {} : { line: v.line }),
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
function decideStatus(stored, differences) {
|
|
338
|
+
if (!stored.exists) {
|
|
339
|
+
return 'baseline-created';
|
|
340
|
+
}
|
|
341
|
+
if (stored.snapshot === undefined) {
|
|
342
|
+
return 'invalid-snapshot';
|
|
343
|
+
}
|
|
344
|
+
return differences.length > 0 ? 'scope-mismatch' : 'compared';
|
|
345
|
+
}
|
|
346
|
+
function buildOutput(parts) {
|
|
347
|
+
const { root, snapshotLabel, written, previous, current, differences, compact, } = parts;
|
|
348
|
+
const status = parts.status === 'baseline-created' && !written
|
|
349
|
+
? 'no-baseline'
|
|
350
|
+
: parts.status;
|
|
351
|
+
const previousRules = new Set(previous?.rulesExecuted ?? []);
|
|
352
|
+
const currentRules = new Set(current.rulesExecuted);
|
|
353
|
+
const base = {
|
|
354
|
+
status,
|
|
355
|
+
projectRoot: root,
|
|
356
|
+
snapshotPath: snapshotLabel,
|
|
357
|
+
snapshotWritten: written,
|
|
358
|
+
...(previous === undefined ? {} : { previousRun: runInfo(previous) }),
|
|
359
|
+
currentRun: {
|
|
360
|
+
...runInfo(current),
|
|
361
|
+
bySeverity: countBy(current.violations, (v) => v.severity),
|
|
362
|
+
byCategory: countBy(current.violations, (v) => v.category),
|
|
363
|
+
},
|
|
364
|
+
rulesAdded: previous === undefined
|
|
365
|
+
? []
|
|
366
|
+
: current.rulesExecuted.filter((r) => !previousRules.has(r)),
|
|
367
|
+
rulesRemoved: previous === undefined
|
|
368
|
+
? []
|
|
369
|
+
: previous.rulesExecuted.filter((r) => !currentRules.has(r)),
|
|
370
|
+
scopeDifferences: differences,
|
|
371
|
+
};
|
|
372
|
+
if (status !== 'compared' || previous === undefined) {
|
|
373
|
+
const byRule = compareHealth([], current.violations).byRule.map((r) => ({
|
|
374
|
+
...r,
|
|
375
|
+
new: 0,
|
|
376
|
+
}));
|
|
377
|
+
return {
|
|
378
|
+
...base,
|
|
379
|
+
byRule,
|
|
380
|
+
truncated: false,
|
|
381
|
+
summary: describeOther(status, snapshotLabel, previous, current, differences, written),
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
const delta = compareHealth(previous.violations, current.violations);
|
|
385
|
+
const totals = {
|
|
386
|
+
new: delta.newViolations.length,
|
|
387
|
+
fixed: delta.fixedViolations.length,
|
|
388
|
+
unchanged: delta.unchanged,
|
|
389
|
+
};
|
|
390
|
+
const summary = describeComparison(previous, current, totals, delta.byRule, delta.newViolations, delta.fixedViolations, base.rulesAdded, snapshotLabel, written);
|
|
391
|
+
if (compact.summaryOnly) {
|
|
392
|
+
return { ...base, totals, byRule: delta.byRule, truncated: false, summary };
|
|
393
|
+
}
|
|
394
|
+
const byFile = limitList(delta.byFile, compact.maxResults);
|
|
395
|
+
const added = limitList(delta.newViolations, compact.maxResults);
|
|
396
|
+
const fixed = limitList(delta.fixedViolations, compact.maxResults);
|
|
397
|
+
return {
|
|
398
|
+
...base,
|
|
399
|
+
totals,
|
|
400
|
+
byRule: delta.byRule,
|
|
401
|
+
byFile: byFile.items,
|
|
402
|
+
newViolations: added.items,
|
|
403
|
+
fixedViolations: fixed.items,
|
|
404
|
+
truncated: byFile.truncated || added.truncated || fixed.truncated,
|
|
405
|
+
summary,
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
function runInfo(snapshot) {
|
|
409
|
+
return {
|
|
410
|
+
createdAt: snapshot.createdAt,
|
|
411
|
+
analyzedFiles: snapshot.analyzedFiles,
|
|
412
|
+
totalViolations: snapshot.violations.length,
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
function countBy(violations, key) {
|
|
416
|
+
const counts = {};
|
|
417
|
+
for (const v of violations) {
|
|
418
|
+
counts[key(v)] = (counts[key(v)] ?? 0) + 1;
|
|
419
|
+
}
|
|
420
|
+
return counts;
|
|
421
|
+
}
|
|
422
|
+
function describeViolation(v) {
|
|
423
|
+
const where = v.line === undefined ? v.filePath : `${v.filePath}:${v.line}`;
|
|
424
|
+
return `${where} ${v.ruleId}: ${v.message}`;
|
|
425
|
+
}
|
|
426
|
+
function listLines(label, violations) {
|
|
427
|
+
if (violations.length === 0) {
|
|
428
|
+
return [];
|
|
429
|
+
}
|
|
430
|
+
const lines = [
|
|
431
|
+
`${label}:`,
|
|
432
|
+
...violations
|
|
433
|
+
.slice(0, SUMMARY_LINES)
|
|
434
|
+
.map((v) => `- ${describeViolation(v)}`),
|
|
435
|
+
];
|
|
436
|
+
if (violations.length > SUMMARY_LINES) {
|
|
437
|
+
lines.push(`... and ${violations.length - SUMMARY_LINES} more.`);
|
|
438
|
+
}
|
|
439
|
+
return lines;
|
|
440
|
+
}
|
|
441
|
+
function describeComparison(previous, current, totals, byRule, added, fixed, rulesAdded, snapshotLabel, written) {
|
|
442
|
+
const lines = [
|
|
443
|
+
`Compared with the run of ${previous.createdAt}: ${totals.new} new, ${totals.fixed} fixed, ` +
|
|
444
|
+
`${totals.unchanged} unchanged (${previous.violations.length} -> ${current.violations.length} ` +
|
|
445
|
+
`violations, ${current.analyzedFiles} files).`,
|
|
446
|
+
];
|
|
447
|
+
const changedRules = byRule.filter((r) => r.new + r.fixed > 0);
|
|
448
|
+
if (changedRules.length > 0) {
|
|
449
|
+
lines.push('By rule:', ...changedRules.map((r) => `- ${r.ruleId}: +${r.new} / -${r.fixed} (${r.previous} -> ${r.current})`));
|
|
450
|
+
}
|
|
451
|
+
if (rulesAdded.length > 0) {
|
|
452
|
+
lines.push(`Rules new since the previous run (their findings count as new): ${rulesAdded.join(', ')}.`);
|
|
453
|
+
}
|
|
454
|
+
lines.push(...listLines('New', added), ...listLines('Fixed', fixed));
|
|
455
|
+
lines.push(written
|
|
456
|
+
? `Snapshot ${snapshotLabel} now holds this run.`
|
|
457
|
+
: `Snapshot ${snapshotLabel} kept (updateSnapshot: false).`);
|
|
458
|
+
return lines.join('\n');
|
|
459
|
+
}
|
|
460
|
+
function describeOther(status, snapshotLabel, previous, current, differences, written) {
|
|
461
|
+
const run = `${current.violations.length} violations in ${current.analyzedFiles} files`;
|
|
462
|
+
const replaced = written
|
|
463
|
+
? ` Replaced by this run (updateSnapshot: true): ${run}.`
|
|
464
|
+
: ' Kept; pass updateSnapshot: true to replace it with this run, or another snapshotPath to keep both.';
|
|
465
|
+
switch (status) {
|
|
466
|
+
case 'baseline-created':
|
|
467
|
+
return `No previous run at ${snapshotLabel}. Baseline written: ${run}. The next run reports new, fixed and unchanged violations.`;
|
|
468
|
+
case 'no-baseline':
|
|
469
|
+
return `No previous run at ${snapshotLabel}; updateSnapshot is false, so no baseline was written. Current run: ${run}.`;
|
|
470
|
+
case 'scope-mismatch':
|
|
471
|
+
return (`The previous run (${previous?.createdAt ?? '?'}) used another scope, so nothing was compared: ` +
|
|
472
|
+
`${differences.join('; ')}.${replaced}`);
|
|
473
|
+
case 'invalid-snapshot':
|
|
474
|
+
return `${snapshotLabel} is not a readable health snapshot (version ${HEALTH_SNAPSHOT_VERSION}); nothing was compared.${replaced}`;
|
|
475
|
+
case 'compared':
|
|
476
|
+
return `Current run: ${run}.`;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
//# sourceMappingURL=compare-health.js.map
|