@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
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @angular-modernizer/adapter-mcp - Scan Architecture Tool
|
|
3
|
-
*
|
|
4
|
-
* MCP tool for scanning Angular codebases for architectural issues.
|
|
5
|
-
* Runs only the ArchitecturePlugin (17 rules: import cycles, layer violations, god objects, etc.).
|
|
6
|
-
*/
|
|
7
1
|
import { findTsConfig } from './helpers/find-ts-config.js';
|
|
2
|
+
import { cancelledExecution, fileProgressMessage, yieldIfCancellable, } from './helpers/tool-context.js';
|
|
3
|
+
import { runScan } from '../scan-host/scan-host.js';
|
|
4
|
+
import { openToolCache } from './helpers/tool-cache.js';
|
|
5
|
+
import { loadSourceFiles } from './helpers/load-source-files.js';
|
|
6
|
+
import { filterFilesByScopePaths } from './helpers/scope-paths.js';
|
|
8
7
|
import { toParallelOptions } from '../types.js';
|
|
9
8
|
import { Kernel, createToolCacheConfig, loadConfig, } from '@angular-modernizer/core';
|
|
10
9
|
import { ArchitecturePlugin } from '@angular-modernizer/plugin-architecture';
|
|
@@ -14,8 +13,8 @@ import { glob } from 'glob';
|
|
|
14
13
|
import { resolve, extname } from 'node:path';
|
|
15
14
|
import { readFileSync, existsSync, statSync } from 'node:fs';
|
|
16
15
|
import { randomUUID } from 'node:crypto';
|
|
17
|
-
import { cpus } from 'node:os';
|
|
18
16
|
import { ProgressStore } from '../streaming/progress-store.js';
|
|
17
|
+
import { describeScan, scanOutputSchema, } from './helpers/analysis-output.js';
|
|
19
18
|
import { incompleteNote, parseMaxDurationMs, runRulesOverFiles, } from './helpers/rule-runner.js';
|
|
20
19
|
/** Violations per response unless `maxResults` says otherwise. */
|
|
21
20
|
const DEFAULT_MAX_RESULTS = 1000;
|
|
@@ -38,19 +37,40 @@ function paginateViolations(violations, params) {
|
|
|
38
37
|
};
|
|
39
38
|
}
|
|
40
39
|
/**
|
|
41
|
-
*
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
* Adds the text summary to a scan result; an incomplete run adds its note.
|
|
41
|
+
*/
|
|
42
|
+
function withScanSummary(result) {
|
|
43
|
+
const notes = result.execution?.note === undefined ? [] : [result.execution.note];
|
|
44
|
+
return {
|
|
45
|
+
...result,
|
|
46
|
+
summary: describeScan(result.counts, result.violations, result.pagination, notes),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* MCP tool `scan-architecture`: scans for architectural issues. Runs only the
|
|
51
|
+
* ArchitecturePlugin (17 rules: import cycles, layer violations, god objects
|
|
52
|
+
* and others).
|
|
45
53
|
*/
|
|
46
54
|
export class ScanArchitectureTool {
|
|
47
55
|
name = 'scan-architecture';
|
|
56
|
+
title = 'Scan Architecture';
|
|
57
|
+
annotations = {
|
|
58
|
+
readOnlyHint: true,
|
|
59
|
+
destructiveHint: false,
|
|
60
|
+
idempotentHint: true,
|
|
61
|
+
openWorldHint: false,
|
|
62
|
+
};
|
|
48
63
|
description = 'Scan Angular codebases for architectural issues with the 17 architecture rules: import cycles ' +
|
|
49
64
|
'(solid:circular-dependency, NG0919 risk), import direction, god objects, layer boundaries, content ' +
|
|
50
|
-
'placement, service bags and more.
|
|
51
|
-
'maxResults (default 1000) and resultOffset page the violations
|
|
65
|
+
'placement, service bags and more. Returns the violations directly; streaming: true (deprecated) runs in the background instead (poll get-operation-progress); ' +
|
|
66
|
+
'maxResults (default 1000) and resultOffset page the violations; counts cover all of them, summary is a short text.';
|
|
67
|
+
/**
|
|
68
|
+
* JSON Schema of the tool arguments.
|
|
69
|
+
* @hidden
|
|
70
|
+
*/
|
|
52
71
|
inputSchema = {
|
|
53
72
|
type: 'object',
|
|
73
|
+
additionalProperties: false,
|
|
54
74
|
properties: {
|
|
55
75
|
rootPath: {
|
|
56
76
|
type: 'string',
|
|
@@ -140,16 +160,16 @@ export class ScanArchitectureTool {
|
|
|
140
160
|
},
|
|
141
161
|
orchestration: {
|
|
142
162
|
type: 'object',
|
|
143
|
-
description: '
|
|
163
|
+
description: 'Deprecated, kept in 1.x: parallel and incremental run the old WorkerPool path on the main thread. On a large app it was no faster than the default path, blocked the server for seconds and took about four times the memory. Leave unset; the default path runs in the scan worker and answers cancellation at once.',
|
|
144
164
|
properties: {
|
|
145
165
|
parallel: {
|
|
146
166
|
type: 'boolean',
|
|
147
|
-
description: '
|
|
167
|
+
description: 'Deprecated: runs the old WorkerPool path (only with apiStyle imperative). Leave unset.',
|
|
148
168
|
default: false,
|
|
149
169
|
},
|
|
150
170
|
incremental: {
|
|
151
171
|
type: 'boolean',
|
|
152
|
-
description: '
|
|
172
|
+
description: 'Deprecated: analyzes files changed against baseBranch (requires git, else every file) on the main thread. Leave unset.',
|
|
153
173
|
default: false,
|
|
154
174
|
},
|
|
155
175
|
baseBranch: {
|
|
@@ -208,8 +228,8 @@ export class ScanArchitectureTool {
|
|
|
208
228
|
},
|
|
209
229
|
streaming: {
|
|
210
230
|
type: 'boolean',
|
|
211
|
-
description: '
|
|
212
|
-
default:
|
|
231
|
+
description: 'Deprecated, kept in 1.x (default: false): returns operationId immediately, the analysis runs in the background and get-operation-progress returns the result. Synchronous calls report progress through MCP progress notifications and stop on cancellation.',
|
|
232
|
+
default: false,
|
|
213
233
|
},
|
|
214
234
|
apiStyle: {
|
|
215
235
|
type: 'string',
|
|
@@ -226,10 +246,33 @@ export class ScanArchitectureTool {
|
|
|
226
246
|
},
|
|
227
247
|
required: ['rootPath'],
|
|
228
248
|
};
|
|
229
|
-
|
|
249
|
+
/**
|
|
250
|
+
* JSON Schema of the tool result (`structuredContent`).
|
|
251
|
+
* @hidden
|
|
252
|
+
*/
|
|
253
|
+
outputSchema = scanOutputSchema({
|
|
254
|
+
operationId: { type: 'string' },
|
|
255
|
+
execution: {
|
|
256
|
+
type: 'object',
|
|
257
|
+
properties: {
|
|
258
|
+
maxDurationMs: { type: 'number' },
|
|
259
|
+
incomplete: { type: 'boolean' },
|
|
260
|
+
stopReason: { type: 'string' },
|
|
261
|
+
skippedFiles: { type: 'integer' },
|
|
262
|
+
ruleTimings: { type: 'array', items: { type: 'object' } },
|
|
263
|
+
note: { type: 'string' },
|
|
264
|
+
},
|
|
265
|
+
required: ['maxDurationMs', 'incomplete', 'skippedFiles', 'ruleTimings'],
|
|
266
|
+
},
|
|
267
|
+
scope: { type: 'object' },
|
|
268
|
+
progress: { type: 'object' },
|
|
269
|
+
pipeline: { type: 'array', items: { type: 'string' } },
|
|
270
|
+
intermediateResults: { type: 'object' },
|
|
271
|
+
});
|
|
272
|
+
async execute(args, ctx = {}) {
|
|
230
273
|
const params = args;
|
|
231
274
|
// Check if streaming mode is enabled
|
|
232
|
-
const streaming = params.streaming ??
|
|
275
|
+
const streaming = params.streaming ?? false;
|
|
233
276
|
if (streaming) {
|
|
234
277
|
// Streaming mode - start operation in background and return operationId
|
|
235
278
|
return this.executeStreaming(params);
|
|
@@ -237,7 +280,7 @@ export class ScanArchitectureTool {
|
|
|
237
280
|
// Check if fluent API should be used
|
|
238
281
|
const apiStyle = params.apiStyle ?? 'fluent';
|
|
239
282
|
if (apiStyle === 'fluent') {
|
|
240
|
-
return this.executeWithFluentApi(params);
|
|
283
|
+
return this.executeWithFluentApi(params, ctx);
|
|
241
284
|
}
|
|
242
285
|
// Load configuration from .angular-modernizer.json if it exists
|
|
243
286
|
const config = this.loadConfig(typeof params.rootPath === 'string' ? params.rootPath : undefined);
|
|
@@ -285,78 +328,6 @@ export class ScanArchitectureTool {
|
|
|
285
328
|
if (!tsConfigPath) {
|
|
286
329
|
throw new Error('Could not find tsconfig.json in the project root');
|
|
287
330
|
}
|
|
288
|
-
// Initialize kernel with ArchitecturePlugin only + caching
|
|
289
|
-
const kernel = new Kernel({
|
|
290
|
-
tsConfigPath,
|
|
291
|
-
plugins: [new ArchitecturePlugin()],
|
|
292
|
-
projectOptions: {
|
|
293
|
-
skipAddingFilesFromTsConfig: true, // CRITICAL: We manually add filtered files
|
|
294
|
-
},
|
|
295
|
-
cacheConfig: createToolCacheConfig(mergedParams.rootPath, 'architecture'),
|
|
296
|
-
});
|
|
297
|
-
await kernel.initialize();
|
|
298
|
-
// Load rules config from .angular-modernizer.json for per-rule overrides (BUG-3)
|
|
299
|
-
const fullConfig = loadConfig(mergedParams.rootPath);
|
|
300
|
-
const rulesConfig = fullConfig.rules;
|
|
301
|
-
// Detect offline mode by testing worker availability
|
|
302
|
-
let isOfflineMode = false;
|
|
303
|
-
try {
|
|
304
|
-
const testWorkerPath = getWorkerScriptPath();
|
|
305
|
-
if (existsSync(testWorkerPath)) {
|
|
306
|
-
console.info('Worker threads available');
|
|
307
|
-
}
|
|
308
|
-
else {
|
|
309
|
-
console.warn('Worker threads not available (offline mode)');
|
|
310
|
-
isOfflineMode = true;
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
catch (error) {
|
|
314
|
-
console.warn('Worker threads not available (offline mode):', error instanceof Error ? error.message : String(error));
|
|
315
|
-
isOfflineMode = true;
|
|
316
|
-
}
|
|
317
|
-
// In offline mode, disable worker threads but keep auto-selection enabled
|
|
318
|
-
// This allows large codebases to still use Promise mode efficiently
|
|
319
|
-
if (isOfflineMode) {
|
|
320
|
-
console.info('Worker threads disabled in offline mode, keeping auto-selection for optimal performance');
|
|
321
|
-
orchestration.useWorkerThreads = false;
|
|
322
|
-
// Keep autoSelectMode enabled so large projects still get Promise parallelism
|
|
323
|
-
}
|
|
324
|
-
// Setup progress tracking if requested
|
|
325
|
-
let lastProgress;
|
|
326
|
-
if (orchestration.enableProgress) {
|
|
327
|
-
const progressReporter = kernel.getProgressReporter();
|
|
328
|
-
if (progressReporter) {
|
|
329
|
-
progressReporter.on('progress', (progress) => {
|
|
330
|
-
lastProgress = {
|
|
331
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access -- Progress event typing is dynamic
|
|
332
|
-
current: progress.current,
|
|
333
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
|
334
|
-
total: progress.total,
|
|
335
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
|
336
|
-
percentage: progress.percentage,
|
|
337
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
|
338
|
-
eta: progress.eta ?? 0,
|
|
339
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
|
340
|
-
phase: progress.type,
|
|
341
|
-
};
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
// Check resource limits before proceeding
|
|
346
|
-
const resourceManager = kernel.getResourceManager();
|
|
347
|
-
if (resourceManager && !resourceManager.canProceed()) {
|
|
348
|
-
throw new Error('Insufficient resources to proceed with analysis');
|
|
349
|
-
}
|
|
350
|
-
// Get analysis rules from ArchitecturePlugin
|
|
351
|
-
const archPlugin = kernel.getPlugin('@angular-modernizer/plugin-architecture');
|
|
352
|
-
const allRules = archPlugin.getAnalysisRules();
|
|
353
|
-
const rulesToRun = params.rules
|
|
354
|
-
? allRules.filter((rule) => params.rules.includes(rule.id))
|
|
355
|
-
: allRules;
|
|
356
|
-
console.info(`ScanArchitecture: Found ${allRules.length} total rules, running ${rulesToRun.length} rules:`, rulesToRun.map((r) => r.id));
|
|
357
|
-
if (rulesToRun.length === 0) {
|
|
358
|
-
throw new Error('No matching rules found');
|
|
359
|
-
}
|
|
360
331
|
// Run analysis using full orchestration
|
|
361
332
|
// Resolve scope for targeted scanning
|
|
362
333
|
const resolvedScope = this.resolveScope(params.rootPath, mergedParams.scope);
|
|
@@ -374,16 +345,86 @@ export class ScanArchitectureTool {
|
|
|
374
345
|
const scopeFilteredFiles = resolvedScope.type !== 'all'
|
|
375
346
|
? this.filterFilesByScope(preDiscoveryFiles, resolvedScope)
|
|
376
347
|
: preDiscoveryFiles;
|
|
377
|
-
//
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
348
|
+
// No automatic switch to the parallel path above 100 files: on a large
|
|
349
|
+
// app it was no faster than the scan worker (371 files 10.8-12.1 vs
|
|
350
|
+
// 10.3-13.1 s), blocked the server for up to 10.7 s and took about four
|
|
351
|
+
// times the memory.
|
|
352
|
+
// The parallel and incremental paths run the kernel here (it starts its
|
|
353
|
+
// own analysis workers); the sequential path runs in a scan worker.
|
|
354
|
+
let parallelKernel;
|
|
355
|
+
let rulesExecuted = [];
|
|
356
|
+
let lastProgress;
|
|
386
357
|
if (orchestration.parallel || orchestration.incremental) {
|
|
358
|
+
// Initialize kernel with ArchitecturePlugin only + caching
|
|
359
|
+
const kernel = new Kernel({
|
|
360
|
+
tsConfigPath,
|
|
361
|
+
plugins: [new ArchitecturePlugin()],
|
|
362
|
+
projectOptions: {
|
|
363
|
+
skipAddingFilesFromTsConfig: true, // CRITICAL: We manually add filtered files
|
|
364
|
+
},
|
|
365
|
+
cacheConfig: createToolCacheConfig(mergedParams.rootPath, 'architecture'),
|
|
366
|
+
});
|
|
367
|
+
await kernel.initialize();
|
|
368
|
+
// Detect offline mode by testing worker availability
|
|
369
|
+
let isOfflineMode = false;
|
|
370
|
+
try {
|
|
371
|
+
const testWorkerPath = getWorkerScriptPath();
|
|
372
|
+
if (existsSync(testWorkerPath)) {
|
|
373
|
+
console.info('Worker threads available');
|
|
374
|
+
}
|
|
375
|
+
else {
|
|
376
|
+
console.warn('Worker threads not available (offline mode)');
|
|
377
|
+
isOfflineMode = true;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
catch (error) {
|
|
381
|
+
console.warn('Worker threads not available (offline mode):', error instanceof Error ? error.message : String(error));
|
|
382
|
+
isOfflineMode = true;
|
|
383
|
+
}
|
|
384
|
+
// In offline mode, disable worker threads but keep auto-selection enabled
|
|
385
|
+
// This allows large codebases to still use Promise mode efficiently
|
|
386
|
+
if (isOfflineMode) {
|
|
387
|
+
console.info('Worker threads disabled in offline mode, keeping auto-selection for optimal performance');
|
|
388
|
+
orchestration.useWorkerThreads = false;
|
|
389
|
+
// Keep autoSelectMode enabled so large projects still get Promise parallelism
|
|
390
|
+
}
|
|
391
|
+
// Setup progress tracking if requested
|
|
392
|
+
if (orchestration.enableProgress) {
|
|
393
|
+
const progressReporter = kernel.getProgressReporter();
|
|
394
|
+
if (progressReporter) {
|
|
395
|
+
progressReporter.on('progress', (progress) => {
|
|
396
|
+
lastProgress = {
|
|
397
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access -- Progress event typing is dynamic
|
|
398
|
+
current: progress.current,
|
|
399
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
|
400
|
+
total: progress.total,
|
|
401
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
|
402
|
+
percentage: progress.percentage,
|
|
403
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
|
404
|
+
eta: progress.eta ?? 0,
|
|
405
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
|
406
|
+
phase: progress.type,
|
|
407
|
+
};
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
// Check resource limits before proceeding
|
|
412
|
+
const resourceManager = kernel.getResourceManager();
|
|
413
|
+
if (resourceManager && !resourceManager.canProceed()) {
|
|
414
|
+
throw new Error('Insufficient resources to proceed with analysis');
|
|
415
|
+
}
|
|
416
|
+
// Get analysis rules from ArchitecturePlugin
|
|
417
|
+
const archPlugin = kernel.getPlugin('@angular-modernizer/plugin-architecture');
|
|
418
|
+
const allRules = archPlugin.getAnalysisRules();
|
|
419
|
+
const rulesToRun = params.rules
|
|
420
|
+
? allRules.filter((rule) => params.rules.includes(rule.id))
|
|
421
|
+
: allRules;
|
|
422
|
+
console.info(`ScanArchitecture: Found ${allRules.length} total rules, running ${rulesToRun.length} rules:`, rulesToRun.map((r) => r.id));
|
|
423
|
+
if (rulesToRun.length === 0) {
|
|
424
|
+
throw new Error('No matching rules found');
|
|
425
|
+
}
|
|
426
|
+
parallelKernel = kernel;
|
|
427
|
+
rulesExecuted = rulesToRun.map((r) => r.id);
|
|
387
428
|
// Use pre-discovered and filtered files
|
|
388
429
|
const filesToAnalyze = scopeFilteredFiles;
|
|
389
430
|
// Update resolved scope with matched files count
|
|
@@ -405,8 +446,17 @@ export class ScanArchitectureTool {
|
|
|
405
446
|
rules: params.rules,
|
|
406
447
|
timeout: orchestration.timeout ?? 120000, // 2 minutes for complex architecture rules
|
|
407
448
|
};
|
|
408
|
-
// Process each batch
|
|
449
|
+
// Process each batch; cancellation is checked between batches
|
|
409
450
|
for (let batchNum = 0; batchNum < totalBatches; batchNum++) {
|
|
451
|
+
await yieldIfCancellable(ctx.signal);
|
|
452
|
+
if (ctx.signal?.aborted === true) {
|
|
453
|
+
execution = {
|
|
454
|
+
...cancelledExecution(batchNum * batchSize, totalFiles - batchNum * batchSize),
|
|
455
|
+
maxDurationMs: parseMaxDurationMs(params.maxDurationMs),
|
|
456
|
+
};
|
|
457
|
+
break;
|
|
458
|
+
}
|
|
459
|
+
ctx.progress?.(batchNum * batchSize, totalFiles, `batch ${batchNum + 1}/${totalBatches}, ${violations.length} violations`);
|
|
410
460
|
const batchStart = batchNum * batchSize;
|
|
411
461
|
const batchEnd = Math.min(batchStart + batchSize, totalFiles);
|
|
412
462
|
const batchFiles = filesToAnalyze.slice(batchStart, batchEnd);
|
|
@@ -419,9 +469,17 @@ export class ScanArchitectureTool {
|
|
|
419
469
|
for (const file of existingFiles) {
|
|
420
470
|
project.removeSourceFile(file);
|
|
421
471
|
}
|
|
422
|
-
// Add current batch files
|
|
423
|
-
|
|
424
|
-
|
|
472
|
+
// Add current batch files; a cancel during the load stops the scan
|
|
473
|
+
const loaded = await loadSourceFiles(project, batchFiles, {
|
|
474
|
+
signal: ctx.signal,
|
|
475
|
+
failOnError: true,
|
|
476
|
+
});
|
|
477
|
+
if (loaded.cancelled) {
|
|
478
|
+
execution = {
|
|
479
|
+
...cancelledExecution(batchStart, totalFiles - batchStart),
|
|
480
|
+
maxDurationMs: parseMaxDurationMs(params.maxDurationMs),
|
|
481
|
+
};
|
|
482
|
+
break;
|
|
425
483
|
}
|
|
426
484
|
console.info(`Batch ${batchNum + 1}: Project now has ${project.getSourceFiles().length} source files`);
|
|
427
485
|
// Log cache stats to show cache effectiveness
|
|
@@ -452,7 +510,7 @@ export class ScanArchitectureTool {
|
|
|
452
510
|
violations.push({
|
|
453
511
|
id: `${analysisResult.ruleId}-${analysisResult.filePath}-${analysisResult.line ?? 0}-${analysisResult.column ?? 0}`,
|
|
454
512
|
ruleId: analysisResult.ruleId,
|
|
455
|
-
severity: rule.severity,
|
|
513
|
+
severity: analysisResult.severity ?? rule.severity,
|
|
456
514
|
message: analysisResult.message,
|
|
457
515
|
filePath: analysisResult.filePath,
|
|
458
516
|
line: analysisResult.line,
|
|
@@ -480,7 +538,7 @@ export class ScanArchitectureTool {
|
|
|
480
538
|
violations.push({
|
|
481
539
|
id: `${analysisResult.ruleId}-${analysisResult.filePath}-${analysisResult.line ?? 0}-${analysisResult.column ?? 0}`,
|
|
482
540
|
ruleId: analysisResult.ruleId,
|
|
483
|
-
severity: rule.severity,
|
|
541
|
+
severity: analysisResult.severity ?? rule.severity,
|
|
484
542
|
message: analysisResult.message,
|
|
485
543
|
filePath: analysisResult.filePath,
|
|
486
544
|
line: analysisResult.line,
|
|
@@ -501,8 +559,6 @@ export class ScanArchitectureTool {
|
|
|
501
559
|
else {
|
|
502
560
|
// Sequential analysis mode (existing logic)
|
|
503
561
|
console.info('Using sequential analysis mode...');
|
|
504
|
-
const project = kernel.getProject();
|
|
505
|
-
const api = createPublicApi(project); // eslint-disable-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment
|
|
506
562
|
let filesToAnalyze = await this.findFilesToAnalyze(params.rootPath, includePatterns, excludePatterns, maxFiles);
|
|
507
563
|
// Apply scope filtering for sequential mode
|
|
508
564
|
if (resolvedScope.type !== 'all') {
|
|
@@ -534,41 +590,36 @@ export class ScanArchitectureTool {
|
|
|
534
590
|
// NOTE: Parallel mode uses kernel.analyzeParallel() which has caching built-in.
|
|
535
591
|
// This cache read logic is for sequential mode only.
|
|
536
592
|
// ============================================================================
|
|
537
|
-
const
|
|
593
|
+
const cache = await openToolCache(mergedParams.rootPath, 'architecture');
|
|
538
594
|
const cachedViolations = []; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
filesToProcess.push(filePath);
|
|
550
|
-
}
|
|
595
|
+
const filesToProcess = [];
|
|
596
|
+
for (const filePath of filesToAnalyze) {
|
|
597
|
+
const cached = await cache.getAnalysisResult(filePath);
|
|
598
|
+
if (cached?.results && cached.results.length > 0) {
|
|
599
|
+
// File is cached and hasn't changed
|
|
600
|
+
cachedViolations.push(...cached.results);
|
|
601
|
+
}
|
|
602
|
+
else {
|
|
603
|
+
// File not cached or has changed
|
|
604
|
+
filesToProcess.push(filePath);
|
|
551
605
|
}
|
|
552
|
-
const stats = cacheManagerForRead.getStats();
|
|
553
|
-
console.info(`Cache: ${cachedViolations.length} results from cache, ${filesToProcess.length} files to analyze (hit rate: ${stats.hitRate.toFixed(1)}%)`);
|
|
554
|
-
}
|
|
555
|
-
else {
|
|
556
|
-
// No cache manager, analyze all files
|
|
557
|
-
filesToProcess = filesToAnalyze;
|
|
558
606
|
}
|
|
607
|
+
console.info(`Cache: ${cachedViolations.length} results from cache, ${filesToProcess.length} files to analyze (hit rate: ${cache.getStats().hitRate.toFixed(1)}%)`);
|
|
559
608
|
// Add cached violations to results
|
|
560
609
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
561
610
|
violations.push(...cachedViolations);
|
|
562
|
-
const run = await
|
|
563
|
-
|
|
611
|
+
const { run, ruleIds } = await this.runRules({
|
|
612
|
+
tool: this.name,
|
|
613
|
+
plugins: 'architecture',
|
|
614
|
+
tsConfigPath,
|
|
615
|
+
rootPath: mergedParams.rootPath,
|
|
564
616
|
files: filesToProcess,
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
config: rulesConfig,
|
|
617
|
+
mode: 'runner',
|
|
618
|
+
...(params.rules === undefined ? {} : { ruleIds: params.rules }),
|
|
568
619
|
maxDurationMs,
|
|
569
620
|
startTime,
|
|
570
|
-
});
|
|
571
|
-
|
|
621
|
+
}, violations, ctx);
|
|
622
|
+
rulesExecuted = ruleIds;
|
|
572
623
|
execution = toExecution(run, maxDurationMs);
|
|
573
624
|
filesAnalyzed = filesToAnalyze.length - run.skippedFiles;
|
|
574
625
|
// ============================================================================
|
|
@@ -595,26 +646,23 @@ export class ScanArchitectureTool {
|
|
|
595
646
|
// NOTE: Parallel mode uses kernel.analyzeParallel() which has caching built-in.
|
|
596
647
|
// This cache write logic is for sequential mode only.
|
|
597
648
|
// ============================================================================
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
const
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
if (!resultsByFile.has(filePath)) {
|
|
606
|
-
resultsByFile.set(filePath, []);
|
|
607
|
-
}
|
|
608
|
-
resultsByFile.get(filePath).push(violation);
|
|
609
|
-
}
|
|
610
|
-
// Write each file's results to cache
|
|
611
|
-
for (const [filePath, fileResults] of resultsByFile.entries()) {
|
|
612
|
-
await cacheManager.setAnalysisResult(filePath, fileResults);
|
|
649
|
+
// Group violations by file path
|
|
650
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
651
|
+
const resultsByFile = new Map();
|
|
652
|
+
for (const violation of violations) {
|
|
653
|
+
const filePath = violation.filePath;
|
|
654
|
+
if (!resultsByFile.has(filePath)) {
|
|
655
|
+
resultsByFile.set(filePath, []);
|
|
613
656
|
}
|
|
614
|
-
|
|
615
|
-
const stats = cacheManager.getStats();
|
|
616
|
-
console.info(`Cache: Cached ${resultsByFile.size} files (hit rate: ${stats.hitRate.toFixed(1)}%)`);
|
|
657
|
+
resultsByFile.get(filePath).push(violation);
|
|
617
658
|
}
|
|
659
|
+
// Write each file's results to cache
|
|
660
|
+
for (const [filePath, fileResults] of resultsByFile.entries()) {
|
|
661
|
+
await cache.setAnalysisResult(filePath, fileResults);
|
|
662
|
+
}
|
|
663
|
+
// Log cache effectiveness
|
|
664
|
+
const stats = cache.getStats();
|
|
665
|
+
console.info(`Cache: Cached ${resultsByFile.size} files (hit rate: ${stats.hitRate.toFixed(1)}%)`);
|
|
618
666
|
}
|
|
619
667
|
// Calculate summary (before pagination)
|
|
620
668
|
const summary = this.calculateSummary(violations);
|
|
@@ -622,8 +670,8 @@ export class ScanArchitectureTool {
|
|
|
622
670
|
const page = paginateViolations(violations, params);
|
|
623
671
|
// Gather orchestration stats using full Phase 6d/7b options
|
|
624
672
|
let orchestrationMetrics;
|
|
625
|
-
if (
|
|
626
|
-
const stats =
|
|
673
|
+
if (parallelKernel !== undefined) {
|
|
674
|
+
const stats = parallelKernel.getOrchestrationStats();
|
|
627
675
|
orchestrationMetrics = {
|
|
628
676
|
parallel: orchestration.parallel ?? false,
|
|
629
677
|
incremental: orchestration.incremental ?? false,
|
|
@@ -649,14 +697,14 @@ export class ScanArchitectureTool {
|
|
|
649
697
|
: undefined,
|
|
650
698
|
};
|
|
651
699
|
}
|
|
652
|
-
|
|
700
|
+
return withScanSummary({
|
|
653
701
|
violations: page.violations,
|
|
654
|
-
|
|
702
|
+
counts: {
|
|
655
703
|
...summary,
|
|
656
704
|
analyzedFiles: filesAnalyzed,
|
|
657
705
|
},
|
|
658
706
|
metadata: {
|
|
659
|
-
rulesExecuted
|
|
707
|
+
rulesExecuted,
|
|
660
708
|
duration,
|
|
661
709
|
projectRoot: params.rootPath,
|
|
662
710
|
},
|
|
@@ -665,17 +713,47 @@ export class ScanArchitectureTool {
|
|
|
665
713
|
pagination: page.pagination,
|
|
666
714
|
orchestration: orchestrationMetrics,
|
|
667
715
|
progress: lastProgress,
|
|
668
|
-
};
|
|
669
|
-
return result;
|
|
716
|
+
});
|
|
670
717
|
}
|
|
671
718
|
catch (error) {
|
|
672
719
|
throw new Error(`Architecture scan failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
673
720
|
}
|
|
674
721
|
}
|
|
722
|
+
/**
|
|
723
|
+
* Runs the rules through the scan engine (in a scan worker when enabled)
|
|
724
|
+
* and appends each file's findings to `violations`. A worker terminated by
|
|
725
|
+
* a cancel leaves no run summary; it is rebuilt from the files received.
|
|
726
|
+
*/
|
|
727
|
+
async runRules(spec, violations, ctx) {
|
|
728
|
+
const total = spec.files.length;
|
|
729
|
+
let analyzed = 0;
|
|
730
|
+
let found = 0;
|
|
731
|
+
if (total > 0) {
|
|
732
|
+
ctx.progress?.(0, total, `loading project, ${total} files to analyze`);
|
|
733
|
+
}
|
|
734
|
+
const engine = await runScan(spec, {
|
|
735
|
+
file: (event) => {
|
|
736
|
+
// The runner mode sets the violation id
|
|
737
|
+
violations.push(...event.findings);
|
|
738
|
+
analyzed++;
|
|
739
|
+
found += event.findings.length;
|
|
740
|
+
ctx.progress?.(analyzed, total, fileProgressMessage(analyzed, total, found));
|
|
741
|
+
},
|
|
742
|
+
}, { signal: ctx.signal });
|
|
743
|
+
const run = engine.run ?? {
|
|
744
|
+
filesAnalyzed: analyzed,
|
|
745
|
+
incomplete: true,
|
|
746
|
+
stopReason: 'cancelled',
|
|
747
|
+
skippedFiles: total - analyzed,
|
|
748
|
+
ruleTimings: [],
|
|
749
|
+
durationMs: Date.now() - (spec.startTime ?? Date.now()),
|
|
750
|
+
};
|
|
751
|
+
return { run, ruleIds: engine.ruleIds };
|
|
752
|
+
}
|
|
675
753
|
/**
|
|
676
754
|
* Execute analysis using fluent API.
|
|
677
755
|
*/
|
|
678
|
-
async executeWithFluentApi(params) {
|
|
756
|
+
async executeWithFluentApi(params, ctx) {
|
|
679
757
|
// Validate input
|
|
680
758
|
if (!params.rootPath || typeof params.rootPath !== 'string') {
|
|
681
759
|
throw new Error('rootPath is required and must be a string');
|
|
@@ -703,26 +781,6 @@ export class ScanArchitectureTool {
|
|
|
703
781
|
if (!tsConfigPath) {
|
|
704
782
|
throw new Error('Could not find tsconfig.json in the project root');
|
|
705
783
|
}
|
|
706
|
-
// Initialize kernel with ArchitecturePlugin
|
|
707
|
-
const kernel = new Kernel({
|
|
708
|
-
tsConfigPath,
|
|
709
|
-
plugins: [new ArchitecturePlugin()],
|
|
710
|
-
projectOptions: {
|
|
711
|
-
skipAddingFilesFromTsConfig: true,
|
|
712
|
-
},
|
|
713
|
-
cacheConfig: createToolCacheConfig(params.rootPath, 'architecture'),
|
|
714
|
-
});
|
|
715
|
-
await kernel.initialize();
|
|
716
|
-
// Get analysis rules from ArchitecturePlugin
|
|
717
|
-
const archPlugin = kernel.getPlugin('@angular-modernizer/plugin-architecture');
|
|
718
|
-
const allRules = archPlugin.getAnalysisRules();
|
|
719
|
-
const rulesToRun = params.rules
|
|
720
|
-
? allRules.filter((rule) => params.rules.includes(rule.id))
|
|
721
|
-
: allRules;
|
|
722
|
-
console.info(`ScanArchitecture (Fluent): Found ${allRules.length} total rules, running ${rulesToRun.length} rules:`, rulesToRun.map((r) => r.id));
|
|
723
|
-
if (rulesToRun.length === 0) {
|
|
724
|
-
throw new Error('No matching rules found');
|
|
725
|
-
}
|
|
726
784
|
// Find files to analyze — resolve scope BEFORE applying maxFiles cap so
|
|
727
785
|
// that scope filtering happens on the full set, not on an arbitrary prefix.
|
|
728
786
|
const maxFiles = params.maxFiles ?? 100;
|
|
@@ -739,37 +797,35 @@ export class ScanArchitectureTool {
|
|
|
739
797
|
if (filesToAnalyze.length === 0) {
|
|
740
798
|
throw new Error('No files found to analyze');
|
|
741
799
|
}
|
|
742
|
-
//
|
|
743
|
-
//
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
800
|
+
// Rules run directly with the config of .angular-modernizer.json
|
|
801
|
+
// (FluentKernel creates contexts without user config, so config-driven
|
|
802
|
+
// rules such as layer-boundary-violation returned 0 violations, Bug 1/3),
|
|
803
|
+
// in a scan worker when enabled.
|
|
804
|
+
const violations = [];
|
|
805
|
+
const { run, ruleIds } = await this.runRules({
|
|
806
|
+
tool: this.name,
|
|
807
|
+
plugins: 'architecture',
|
|
808
|
+
tsConfigPath,
|
|
809
|
+
rootPath: params.rootPath,
|
|
752
810
|
files: filesToAnalyze,
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
config: rulesConfig,
|
|
811
|
+
mode: 'runner',
|
|
812
|
+
...(params.rules === undefined ? {} : { ruleIds: params.rules }),
|
|
756
813
|
maxDurationMs: parseMaxDurationMs(params.maxDurationMs),
|
|
757
814
|
startTime,
|
|
758
|
-
});
|
|
759
|
-
const violations = run.violations;
|
|
815
|
+
}, violations, ctx);
|
|
760
816
|
const filesAnalyzed = run.filesAnalyzed;
|
|
761
817
|
const execution = toExecution(run, parseMaxDurationMs(params.maxDurationMs));
|
|
762
818
|
const duration = Date.now() - startTime;
|
|
763
819
|
const summary = this.calculateSummary(violations);
|
|
764
820
|
const page = paginateViolations(violations, params);
|
|
765
|
-
return {
|
|
821
|
+
return withScanSummary({
|
|
766
822
|
violations: page.violations,
|
|
767
|
-
|
|
823
|
+
counts: {
|
|
768
824
|
...summary,
|
|
769
825
|
analyzedFiles: filesAnalyzed,
|
|
770
826
|
},
|
|
771
827
|
metadata: {
|
|
772
|
-
rulesExecuted:
|
|
828
|
+
rulesExecuted: ruleIds,
|
|
773
829
|
duration,
|
|
774
830
|
projectRoot: params.rootPath,
|
|
775
831
|
},
|
|
@@ -783,7 +839,7 @@ export class ScanArchitectureTool {
|
|
|
783
839
|
message: `Analysis completed with ${violations.length} violations`,
|
|
784
840
|
},
|
|
785
841
|
},
|
|
786
|
-
};
|
|
842
|
+
});
|
|
787
843
|
}
|
|
788
844
|
catch (error) {
|
|
789
845
|
throw new Error(`Architecture analysis failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -815,7 +871,7 @@ export class ScanArchitectureTool {
|
|
|
815
871
|
return {
|
|
816
872
|
operationId,
|
|
817
873
|
violations: [],
|
|
818
|
-
|
|
874
|
+
counts: {
|
|
819
875
|
totalViolations: 0,
|
|
820
876
|
analyzedFiles: 0,
|
|
821
877
|
bySeverity: {},
|
|
@@ -827,6 +883,8 @@ export class ScanArchitectureTool {
|
|
|
827
883
|
duration: 0,
|
|
828
884
|
projectRoot: params.rootPath,
|
|
829
885
|
},
|
|
886
|
+
summary: `Scan started in the background as operation ${operationId}; ` +
|
|
887
|
+
'get-operation-progress returns the violations when it is complete.',
|
|
830
888
|
};
|
|
831
889
|
}
|
|
832
890
|
/**
|
|
@@ -964,10 +1022,10 @@ export class ScanArchitectureTool {
|
|
|
964
1022
|
// Store full result so get-operation-progress can return violations
|
|
965
1023
|
const summary = this.calculateSummary(violations);
|
|
966
1024
|
const page = paginateViolations(violations, params);
|
|
967
|
-
store.setResult(operationId, {
|
|
1025
|
+
store.setResult(operationId, withScanSummary({
|
|
968
1026
|
violations: page.violations,
|
|
969
1027
|
pagination: page.pagination,
|
|
970
|
-
|
|
1028
|
+
counts: {
|
|
971
1029
|
...summary,
|
|
972
1030
|
analyzedFiles: filesProcessed,
|
|
973
1031
|
},
|
|
@@ -977,7 +1035,7 @@ export class ScanArchitectureTool {
|
|
|
977
1035
|
projectRoot: params.rootPath,
|
|
978
1036
|
},
|
|
979
1037
|
execution,
|
|
980
|
-
});
|
|
1038
|
+
}));
|
|
981
1039
|
// Mark complete
|
|
982
1040
|
store.markComplete(operationId);
|
|
983
1041
|
}
|
|
@@ -994,8 +1052,9 @@ export class ScanArchitectureTool {
|
|
|
994
1052
|
});
|
|
995
1053
|
allFiles.push(...files);
|
|
996
1054
|
}
|
|
997
|
-
//
|
|
998
|
-
|
|
1055
|
+
// Sorted before the limit: glob returns files in no fixed order, and both
|
|
1056
|
+
// the chosen files and the result pages depend on it
|
|
1057
|
+
const uniqueFiles = [...new Set(allFiles)].sort().slice(0, maxFiles);
|
|
999
1058
|
// Filter to only TypeScript files and ensure they are actual files (not directories)
|
|
1000
1059
|
return uniqueFiles.filter((file) => {
|
|
1001
1060
|
const isTsFile = ['.ts', '.tsx'].includes(extname(file));
|
|
@@ -1251,10 +1310,8 @@ export class ScanArchitectureTool {
|
|
|
1251
1310
|
resolvedScope.resolvedPaths.length === 0) {
|
|
1252
1311
|
return files;
|
|
1253
1312
|
}
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
file.startsWith(scopePath.replaceAll('\\', '/')));
|
|
1257
|
-
});
|
|
1313
|
+
// Inside the folder, not a sibling sharing its prefix
|
|
1314
|
+
return filterFilesByScopePaths(files, resolvedScope.resolvedPaths);
|
|
1258
1315
|
}
|
|
1259
1316
|
}
|
|
1260
1317
|
function toExecution(run, maxDurationMs) {
|