@angular-modernizer/adapter-mcp 1.1.0 → 2.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/CHANGELOG.md +662 -0
- package/README.md +86 -445
- package/dist/cli.js +9 -1
- package/dist/core/project-analyzer.js +2 -2
- package/dist/index.d.ts +10 -1
- package/dist/index.js +1 -0
- package/dist/scan-host/scan-host.d.ts +7 -0
- package/dist/scan-host/scan-host.js +73 -10
- package/dist/scan-host/scan-protocol.d.ts +2 -0
- package/dist/scan-host/scan-worker.js +14 -8
- package/dist/server/limited-stdio-transport.d.ts +6 -3
- package/dist/server/limited-stdio-transport.js +26 -9
- package/dist/server/mcp-server.js +1 -1
- package/dist/server/sdk-server.d.ts +14 -3
- package/dist/server/sdk-server.js +54 -6
- package/dist/server/tool-registry.d.ts +3 -1
- package/dist/server/tool-registry.js +8 -3
- package/dist/streaming/progress-store.d.ts +19 -7
- package/dist/streaming/progress-store.js +19 -8
- package/dist/tools/analyze-build-impact.d.ts +9 -6
- package/dist/tools/analyze-build-impact.js +14 -7
- package/dist/tools/analyze-core-to-shared.d.ts +10 -6
- package/dist/tools/analyze-core-to-shared.js +63 -60
- package/dist/tools/analyze-parser-performance.d.ts +57 -13
- package/dist/tools/analyze-parser-performance.js +67 -6
- package/dist/tools/analyze-project.d.ts +35 -6
- package/dist/tools/analyze-project.js +141 -36
- package/dist/tools/check-incremental-compatibility.d.ts +30 -41
- package/dist/tools/check-incremental-compatibility.js +32 -264
- package/dist/tools/collect-feedback.js +15 -2
- package/dist/tools/extract-libraries.js +42 -27
- package/dist/tools/find-angular-symbol.d.ts +2 -2
- package/dist/tools/find-angular-symbol.js +6 -5
- package/dist/tools/find-component-hosts.d.ts +2 -2
- package/dist/tools/find-component-hosts.js +6 -5
- package/dist/tools/find-usages.d.ts +2 -2
- package/dist/tools/find-usages.js +24 -15
- package/dist/tools/get-bootstrap-execution.d.ts +2 -2
- package/dist/tools/get-bootstrap-execution.js +3 -3
- package/dist/tools/get-call-graph.d.ts +2 -2
- package/dist/tools/get-call-graph.js +18 -5
- package/dist/tools/get-operation-progress-tool.d.ts +1 -1
- package/dist/tools/get-operation-progress-tool.js +2 -2
- package/dist/tools/get-operation-progress.d.ts +4 -1
- package/dist/tools/get-operation-progress.js +6 -2
- package/dist/tools/helpers/analysis-output.d.ts +32 -1
- package/dist/tools/helpers/analysis-output.js +22 -1
- package/dist/tools/helpers/build-cache.d.ts +27 -0
- package/dist/tools/helpers/build-cache.js +86 -0
- package/dist/tools/helpers/class-filter.d.ts +18 -0
- package/dist/tools/helpers/class-filter.js +30 -0
- package/dist/tools/helpers/cli-arguments.d.ts +23 -0
- package/dist/tools/helpers/cli-arguments.js +35 -0
- package/dist/tools/helpers/feedback-catalog.d.ts +38 -0
- package/dist/tools/helpers/feedback-catalog.js +196 -0
- package/dist/tools/helpers/feedback-sidecar.d.ts +201 -0
- package/dist/tools/helpers/feedback-sidecar.js +381 -0
- package/dist/tools/helpers/file-type-check.d.ts +34 -0
- package/dist/tools/helpers/file-type-check.js +56 -0
- package/dist/tools/helpers/output-contract.d.ts +42 -0
- package/dist/tools/helpers/output-contract.js +54 -0
- package/dist/tools/helpers/pattern-anonymizer.d.ts +27 -0
- package/dist/tools/helpers/pattern-anonymizer.js +159 -0
- package/dist/tools/helpers/project-cache.d.ts +78 -6
- package/dist/tools/helpers/project-cache.js +205 -15
- package/dist/tools/helpers/project-decorators.d.ts +11 -4
- package/dist/tools/helpers/project-decorators.js +13 -6
- package/dist/tools/helpers/refresh-apply.d.ts +94 -0
- package/dist/tools/helpers/refresh-apply.js +460 -0
- package/dist/tools/helpers/refresh-inventory.d.ts +106 -0
- package/dist/tools/helpers/refresh-inventory.js +610 -0
- package/dist/tools/helpers/rule-runner.js +3 -1
- package/dist/tools/helpers/scan-cache.d.ts +74 -5
- package/dist/tools/helpers/scan-cache.js +134 -6
- package/dist/tools/helpers/scan-engine.d.ts +30 -6
- package/dist/tools/helpers/scan-engine.js +131 -22
- package/dist/tools/helpers/scan-plan.d.ts +1 -1
- package/dist/tools/helpers/scan-plan.js +16 -2
- package/dist/tools/helpers/source-map-loader.d.ts +55 -0
- package/dist/tools/helpers/source-map-loader.js +226 -0
- package/dist/tools/helpers/template-check.d.ts +76 -0
- package/dist/tools/helpers/template-check.js +158 -0
- package/dist/tools/helpers/tool-cache.d.ts +7 -2
- package/dist/tools/helpers/tool-cache.js +9 -3
- package/dist/tools/helpers/tool-context.d.ts +18 -0
- package/dist/tools/helpers/tool-context.js +29 -0
- package/dist/tools/helpers/transform-safety.d.ts +151 -1
- package/dist/tools/helpers/transform-safety.js +357 -4
- package/dist/tools/inspect-form-group.d.ts +2 -2
- package/dist/tools/inspect-form-group.js +8 -3
- package/dist/tools/inspect-i18n.d.ts +2 -2
- package/dist/tools/inspect-i18n.js +3 -3
- package/dist/tools/inspect-template.d.ts +2 -2
- package/dist/tools/inspect-template.js +11 -5
- package/dist/tools/learn-patterns.d.ts +43 -28
- package/dist/tools/learn-patterns.js +83 -161
- package/dist/tools/list-imports.d.ts +2 -2
- package/dist/tools/list-imports.js +3 -3
- package/dist/tools/orchestrate-migration.d.ts +19 -1
- package/dist/tools/orchestrate-migration.js +52 -10
- package/dist/tools/parse-stack-trace.d.ts +48 -1
- package/dist/tools/parse-stack-trace.js +108 -9
- package/dist/tools/plan-migration.d.ts +2 -2
- package/dist/tools/plan-migration.js +25 -12
- package/dist/tools/refresh-state.d.ts +378 -0
- package/dist/tools/refresh-state.js +370 -0
- package/dist/tools/resolve-type.d.ts +2 -2
- package/dist/tools/resolve-type.js +13 -6
- package/dist/tools/review-feedback.d.ts +42 -7
- package/dist/tools/review-feedback.js +24 -17
- package/dist/tools/rollback-changes.d.ts +5 -0
- package/dist/tools/rollback-changes.js +7 -2
- package/dist/tools/run-angular-cli.js +36 -22
- package/dist/tools/run-build.d.ts +33 -28
- package/dist/tools/run-build.js +136 -438
- package/dist/tools/run-schematic.d.ts +8 -2
- package/dist/tools/run-schematic.js +80 -50
- package/dist/tools/scan-all.d.ts +31 -15
- package/dist/tools/scan-all.js +75 -109
- package/dist/tools/scan-angular.d.ts +27 -14
- package/dist/tools/scan-angular.js +70 -92
- package/dist/tools/scan-architecture.d.ts +29 -12
- package/dist/tools/scan-architecture.js +205 -135
- package/dist/tools/scan-solid.d.ts +27 -14
- package/dist/tools/scan-solid.js +73 -89
- package/dist/tools/search-codebase.d.ts +8 -3
- package/dist/tools/search-codebase.js +16 -10
- package/dist/tools/suggest-improvements.d.ts +34 -3
- package/dist/tools/suggest-improvements.js +34 -9
- package/dist/tools/trace-output-flow.d.ts +2 -2
- package/dist/tools/trace-output-flow.js +6 -5
- package/dist/tools/transform-code-batch.d.ts +9 -9
- package/dist/tools/transform-code.d.ts +161 -12
- package/dist/tools/transform-code.js +782 -197
- package/dist/tools/validate-before-transform.js +2 -1
- package/dist/tools/validate-project-compatibility.d.ts +28 -55
- package/dist/tools/validate-project-compatibility.js +33 -225
- package/dist/tools/validate-transformation.d.ts +40 -26
- package/dist/tools/validate-transformation.js +115 -294
- package/dist/tools/verify-citations.js +8 -2
- package/dist/types.d.ts +9 -9
- package/dist/utils/format-tool-response.d.ts +3 -1
- package/dist/utils/format-tool-response.js +8 -3
- package/package.json +14 -13
|
@@ -2,9 +2,10 @@ import { TemplateInspector, } from '@angular-modernizer/api';
|
|
|
2
2
|
import { existsSync } from 'node:fs';
|
|
3
3
|
import { isAbsolute, resolve } from 'node:path';
|
|
4
4
|
import { findTsConfig } from './helpers/find-ts-config.js';
|
|
5
|
-
import { ProjectCache } from './helpers/project-cache.js';
|
|
5
|
+
import { ProjectCache, acquireProject } from './helpers/project-cache.js';
|
|
6
6
|
import { COMPACT_OUTPUT_SCHEMA, limitList, parseCompactOptions, } from './helpers/compact-output.js';
|
|
7
7
|
import { configuredComponentDecorators } from './helpers/project-decorators.js';
|
|
8
|
+
import { missingClassMessage } from './helpers/class-filter.js';
|
|
8
9
|
import { WARNINGS_OUTPUT_SCHEMA, withWarnings, } from './helpers/output-contract.js';
|
|
9
10
|
const COUNT_OBJECT = { type: 'object', additionalProperties: { type: 'integer' } };
|
|
10
11
|
const TEMPLATE_COUNT_KEYS = [
|
|
@@ -232,7 +233,7 @@ export class InspectTemplateTool {
|
|
|
232
233
|
},
|
|
233
234
|
required: ['templates', 'summary', 'tsConfigPath'],
|
|
234
235
|
};
|
|
235
|
-
async execute(args) {
|
|
236
|
+
async execute(args, ctx = {}) {
|
|
236
237
|
const params = args;
|
|
237
238
|
if (!params.file || typeof params.file !== 'string') {
|
|
238
239
|
throw new Error('file is required');
|
|
@@ -255,12 +256,17 @@ export class InspectTemplateTool {
|
|
|
255
256
|
if (!tsConfigPath) {
|
|
256
257
|
throw new Error(`tsconfig.json not found in projectRoot: ${params.projectRoot}`);
|
|
257
258
|
}
|
|
258
|
-
const project = this.projects
|
|
259
|
+
const project = await acquireProject(this.projects, tsConfigPath, ctx);
|
|
259
260
|
if (!filePath.endsWith('.html') && !project.getSourceFile(filePath)) {
|
|
260
261
|
throw new Error(`file is not part of the tsconfig program: ${filePath}`);
|
|
261
262
|
}
|
|
263
|
+
const decorators = configuredComponentDecorators(params.projectRoot);
|
|
264
|
+
const missingClass = missingClassMessage(project.getSourceFile(filePath), params.className, filePath);
|
|
265
|
+
if (missingClass !== undefined) {
|
|
266
|
+
return withWarnings({ templates: [], summary: missingClass, tsConfigPath }, [...decorators.warnings, ...this.projects.warnings(tsConfigPath)]);
|
|
267
|
+
}
|
|
262
268
|
const inspector = new TemplateInspector(project, {
|
|
263
|
-
componentDecorators:
|
|
269
|
+
componentDecorators: decorators.componentDecorators,
|
|
264
270
|
includePlainElements: params.includePlainElements === true,
|
|
265
271
|
...(i18nNames === undefined ? {} : { i18nNames }),
|
|
266
272
|
});
|
|
@@ -269,7 +275,7 @@ export class InspectTemplateTool {
|
|
|
269
275
|
templates: reports.map((r) => this.shape(r, compact.summaryOnly, compact.maxResults)),
|
|
270
276
|
summary: this.buildSummary(filePath, reports),
|
|
271
277
|
tsConfigPath,
|
|
272
|
-
}, this.projects.warnings(tsConfigPath));
|
|
278
|
+
}, [...decorators.warnings, ...this.projects.warnings(tsConfigPath)]);
|
|
273
279
|
}
|
|
274
280
|
parseI18nNames(value) {
|
|
275
281
|
if (value === undefined) {
|
|
@@ -21,7 +21,7 @@ export interface LearnPatternsResult {
|
|
|
21
21
|
complexity: 'low' | 'medium' | 'high';
|
|
22
22
|
/** Example occurrences. */
|
|
23
23
|
examples: {
|
|
24
|
-
/** File of the example. */
|
|
24
|
+
/** File of the example (form depends on `anonymizationLevel`). */
|
|
25
25
|
filePath: string;
|
|
26
26
|
/** Code of the example. */
|
|
27
27
|
code: string;
|
|
@@ -78,13 +78,6 @@ export interface LearnPatternsResult {
|
|
|
78
78
|
/** Patterns in the file. */
|
|
79
79
|
patterns: string[];
|
|
80
80
|
}[];
|
|
81
|
-
/** Rule files written. */
|
|
82
|
-
rules?: {
|
|
83
|
-
/** Path of the file. */
|
|
84
|
-
path: string;
|
|
85
|
-
/** Rule ids in the file. */
|
|
86
|
-
ruleIds: string[];
|
|
87
|
-
}[];
|
|
88
81
|
};
|
|
89
82
|
/**
|
|
90
83
|
* Validation results.
|
|
@@ -179,11 +172,10 @@ export interface LearnPatternsResult {
|
|
|
179
172
|
styleAlignedPatterns: number;
|
|
180
173
|
};
|
|
181
174
|
/**
|
|
182
|
-
*
|
|
175
|
+
* Rules proposed from the patterns (if generateRules=true); only reported,
|
|
176
|
+
* no rule file is written.
|
|
183
177
|
*/
|
|
184
178
|
generatedRules?: {
|
|
185
|
-
/** Output folder (`ruleOutputPath`, default `./learned-rules`). */
|
|
186
|
-
path: string;
|
|
187
179
|
/** Generated rule id. */
|
|
188
180
|
ruleId: string;
|
|
189
181
|
/** Confidence of the rule. */
|
|
@@ -205,8 +197,8 @@ export interface LearnPatternsResult {
|
|
|
205
197
|
* @remarks
|
|
206
198
|
* Detects a style profile of the codebase (DI, RxJS/signals, change
|
|
207
199
|
* detection, module style, state management), scores patterns by confidence
|
|
208
|
-
* and style alignment, tracks them across scans in a knowledge base
|
|
209
|
-
* write
|
|
200
|
+
* and style alignment, tracks them across scans in a knowledge base, can
|
|
201
|
+
* write fixture files and proposes rules (reported only, no rule files).
|
|
210
202
|
*/
|
|
211
203
|
export declare class LearnPatternsTool implements MCPTool {
|
|
212
204
|
name: string;
|
|
@@ -442,6 +434,26 @@ export declare class LearnPatternsTool implements MCPTool {
|
|
|
442
434
|
};
|
|
443
435
|
artifacts: {
|
|
444
436
|
type: string;
|
|
437
|
+
properties: {
|
|
438
|
+
fixtures: {
|
|
439
|
+
type: string;
|
|
440
|
+
items: {
|
|
441
|
+
type: string;
|
|
442
|
+
properties: {
|
|
443
|
+
path: {
|
|
444
|
+
type: string;
|
|
445
|
+
};
|
|
446
|
+
patterns: {
|
|
447
|
+
type: string;
|
|
448
|
+
items: {
|
|
449
|
+
type: string;
|
|
450
|
+
};
|
|
451
|
+
};
|
|
452
|
+
};
|
|
453
|
+
required: string[];
|
|
454
|
+
};
|
|
455
|
+
};
|
|
456
|
+
};
|
|
445
457
|
};
|
|
446
458
|
validation: {
|
|
447
459
|
type: string;
|
|
@@ -459,6 +471,21 @@ export declare class LearnPatternsTool implements MCPTool {
|
|
|
459
471
|
type: string;
|
|
460
472
|
items: {
|
|
461
473
|
type: string;
|
|
474
|
+
properties: {
|
|
475
|
+
ruleId: {
|
|
476
|
+
type: string;
|
|
477
|
+
};
|
|
478
|
+
confidence: {
|
|
479
|
+
type: string;
|
|
480
|
+
};
|
|
481
|
+
alignedWithStyle: {
|
|
482
|
+
type: string;
|
|
483
|
+
};
|
|
484
|
+
rationale: {
|
|
485
|
+
type: string;
|
|
486
|
+
};
|
|
487
|
+
};
|
|
488
|
+
required: string[];
|
|
462
489
|
};
|
|
463
490
|
};
|
|
464
491
|
summary: {
|
|
@@ -505,13 +532,10 @@ export declare class LearnPatternsTool implements MCPTool {
|
|
|
505
532
|
*/
|
|
506
533
|
private filterByOccurrence;
|
|
507
534
|
/**
|
|
508
|
-
* Anonymize patterns
|
|
535
|
+
* Anonymize the examples of the patterns (file path, code, metadata) at
|
|
536
|
+
* the given level; see `helpers/pattern-anonymizer.ts`.
|
|
509
537
|
*/
|
|
510
538
|
private anonymizePatterns;
|
|
511
|
-
/**
|
|
512
|
-
* Anonymize code while preserving framework terms.
|
|
513
|
-
*/
|
|
514
|
-
private anonymizeCode;
|
|
515
539
|
/**
|
|
516
540
|
* Calculate complexity of a pattern.
|
|
517
541
|
*/
|
|
@@ -521,7 +545,7 @@ export declare class LearnPatternsTool implements MCPTool {
|
|
|
521
545
|
*/
|
|
522
546
|
private validatePatternQuality;
|
|
523
547
|
/**
|
|
524
|
-
* Generate artifacts (
|
|
548
|
+
* Generate artifacts (fixture files; `'rules'` writes nothing).
|
|
525
549
|
*/
|
|
526
550
|
private generateArtifacts;
|
|
527
551
|
/**
|
|
@@ -532,10 +556,6 @@ export declare class LearnPatternsTool implements MCPTool {
|
|
|
532
556
|
* Generate fixture file content.
|
|
533
557
|
*/
|
|
534
558
|
private generateFixtureContent;
|
|
535
|
-
/**
|
|
536
|
-
* Generate rule files (stub).
|
|
537
|
-
*/
|
|
538
|
-
private generateRules;
|
|
539
559
|
/**
|
|
540
560
|
* Format pattern name from type.
|
|
541
561
|
*/
|
|
@@ -556,10 +576,5 @@ export declare class LearnPatternsTool implements MCPTool {
|
|
|
556
576
|
* Count patterns by complexity.
|
|
557
577
|
*/
|
|
558
578
|
private countByComplexity;
|
|
559
|
-
/**
|
|
560
|
-
* Ensure output directory is in .gitignore.
|
|
561
|
-
* Automatically adds the directory to .gitignore when it's created.
|
|
562
|
-
*/
|
|
563
|
-
private ensureGitignore;
|
|
564
579
|
}
|
|
565
580
|
//# sourceMappingURL=learn-patterns.d.ts.map
|
|
@@ -1,10 +1,26 @@
|
|
|
1
1
|
import { findTsConfig } from './helpers/find-ts-config.js';
|
|
2
2
|
import { Project, SyntaxKind } from 'ts-morph';
|
|
3
|
-
import { writeFileSync, existsSync, mkdirSync
|
|
4
|
-
import { resolve, dirname } from 'node:path';
|
|
3
|
+
import { writeFileSync, existsSync, mkdirSync } from 'node:fs';
|
|
4
|
+
import { resolve, dirname, join } from 'node:path';
|
|
5
5
|
import { countList } from './helpers/analysis-output.js';
|
|
6
|
+
import { anonymizeCode, anonymizeFilePath, anonymizeMetadata, } from './helpers/pattern-anonymizer.js';
|
|
6
7
|
import { COUNT_OBJECT } from './helpers/investigation-schemas.js';
|
|
7
|
-
import { PatternKnowledgeBase, StyleConventionDetector, ContextAwareScorer, ContextAwareRuleGenerator, RealFileSystemAdapter, } from '@angular-modernizer/core';
|
|
8
|
+
import { PatternKnowledgeBase, StyleConventionDetector, ContextAwareScorer, ContextAwareRuleGenerator, RealFileSystemAdapter, loadConfig, } from '@angular-modernizer/core';
|
|
9
|
+
/**
|
|
10
|
+
* Stable id of a pattern: the same category and type give the same id in
|
|
11
|
+
* every run, so the knowledge base recognises a pattern it stored before.
|
|
12
|
+
* Patterns are grouped by category and type, so the id is unique per run.
|
|
13
|
+
*/
|
|
14
|
+
function patternId(category, type) {
|
|
15
|
+
return `learned-${category}-${type}`;
|
|
16
|
+
}
|
|
17
|
+
/** Pattern type from an id built by {@link patternId}. */
|
|
18
|
+
function patternTypeOf(pattern) {
|
|
19
|
+
const prefix = `learned-${pattern.category}-`;
|
|
20
|
+
return pattern.id.startsWith(prefix) ? pattern.id.slice(prefix.length) : pattern.id;
|
|
21
|
+
}
|
|
22
|
+
/** Own inputs above which a component is a too-many-inputs pattern, unless the config sets `maxInputs`. */
|
|
23
|
+
const DEFAULT_MAX_INPUTS = 5;
|
|
8
24
|
/** Categories and patterns named in the summary. */
|
|
9
25
|
const SUMMARY_PATTERNS = 5;
|
|
10
26
|
/**
|
|
@@ -33,12 +49,11 @@ function describePatterns(result) {
|
|
|
33
49
|
`architecture ${style.architectureStyle} (confidence ${style.confidence.toFixed(2)}).`);
|
|
34
50
|
}
|
|
35
51
|
if (result.generatedRules !== undefined) {
|
|
36
|
-
lines.push(`${result.generatedRules.length} rule(s)
|
|
52
|
+
lines.push(`${result.generatedRules.length} rule(s) proposed (not written to disk).`);
|
|
37
53
|
}
|
|
38
54
|
const fixtures = result.artifacts?.fixtures?.length ?? 0;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
lines.push(`Written: ${fixtures} fixture file(s), ${rules} rule file(s).`);
|
|
55
|
+
if (fixtures > 0) {
|
|
56
|
+
lines.push(`Written: ${fixtures} fixture file(s).`);
|
|
42
57
|
}
|
|
43
58
|
return lines.join('\n');
|
|
44
59
|
}
|
|
@@ -49,8 +64,8 @@ function describePatterns(result) {
|
|
|
49
64
|
* @remarks
|
|
50
65
|
* Detects a style profile of the codebase (DI, RxJS/signals, change
|
|
51
66
|
* detection, module style, state management), scores patterns by confidence
|
|
52
|
-
* and style alignment, tracks them across scans in a knowledge base
|
|
53
|
-
* write
|
|
67
|
+
* and style alignment, tracks them across scans in a knowledge base, can
|
|
68
|
+
* write fixture files and proposes rules (reported only, no rule files).
|
|
54
69
|
*/
|
|
55
70
|
export class LearnPatternsTool {
|
|
56
71
|
name = 'learn-patterns';
|
|
@@ -106,7 +121,7 @@ export class LearnPatternsTool {
|
|
|
106
121
|
type: 'string',
|
|
107
122
|
enum: ['fixtures', 'rules', 'both'],
|
|
108
123
|
default: 'fixtures',
|
|
109
|
-
description:
|
|
124
|
+
description: "Output format for generated artifacts. 'rules' is deprecated and writes nothing (no rule files are written; generateRules reports proposed rules), 'both' writes the fixtures",
|
|
110
125
|
},
|
|
111
126
|
outputPath: {
|
|
112
127
|
type: 'string',
|
|
@@ -116,7 +131,7 @@ export class LearnPatternsTool {
|
|
|
116
131
|
type: 'string',
|
|
117
132
|
enum: ['strict', 'moderate', 'minimal'],
|
|
118
133
|
default: 'strict',
|
|
119
|
-
description:
|
|
134
|
+
description: "Anonymization of the pattern examples. 'strict': file paths hashed, identifiers, string literals and template text in code and metadata renamed deterministically (Angular, RxJS and TypeScript names kept), comments dropped. 'moderate': project-relative file paths, code unchanged. 'minimal': absolute file paths and the original code",
|
|
120
135
|
},
|
|
121
136
|
validatePatterns: {
|
|
122
137
|
type: 'boolean',
|
|
@@ -156,11 +171,11 @@ export class LearnPatternsTool {
|
|
|
156
171
|
generateRules: {
|
|
157
172
|
type: 'boolean',
|
|
158
173
|
default: false,
|
|
159
|
-
description: '
|
|
174
|
+
description: 'Propose analysis rules from high-confidence patterns (generatedRules in the result; no rule files are written)',
|
|
160
175
|
},
|
|
161
176
|
ruleOutputPath: {
|
|
162
177
|
type: 'string',
|
|
163
|
-
description: '
|
|
178
|
+
description: 'Deprecated, has no effect: no rule files are written',
|
|
164
179
|
},
|
|
165
180
|
filterRulesByStyle: {
|
|
166
181
|
type: 'boolean',
|
|
@@ -248,12 +263,39 @@ export class LearnPatternsTool {
|
|
|
248
263
|
},
|
|
249
264
|
required: ['totalPatternsFound', 'byCategory', 'byComplexity', 'filesAnalyzed', 'duration'],
|
|
250
265
|
},
|
|
251
|
-
artifacts: {
|
|
266
|
+
artifacts: {
|
|
267
|
+
type: 'object',
|
|
268
|
+
properties: {
|
|
269
|
+
fixtures: {
|
|
270
|
+
type: 'array',
|
|
271
|
+
items: {
|
|
272
|
+
type: 'object',
|
|
273
|
+
properties: {
|
|
274
|
+
path: { type: 'string' },
|
|
275
|
+
patterns: { type: 'array', items: { type: 'string' } },
|
|
276
|
+
},
|
|
277
|
+
required: ['path', 'patterns'],
|
|
278
|
+
},
|
|
279
|
+
},
|
|
280
|
+
},
|
|
281
|
+
},
|
|
252
282
|
validation: { type: 'object' },
|
|
253
283
|
styleProfile: { type: 'object' },
|
|
254
284
|
learningEvolution: { type: 'object' },
|
|
255
285
|
confidenceAnalysis: { type: 'object' },
|
|
256
|
-
generatedRules: {
|
|
286
|
+
generatedRules: {
|
|
287
|
+
type: 'array',
|
|
288
|
+
items: {
|
|
289
|
+
type: 'object',
|
|
290
|
+
properties: {
|
|
291
|
+
ruleId: { type: 'string' },
|
|
292
|
+
confidence: { type: 'number' },
|
|
293
|
+
alignedWithStyle: { type: 'boolean' },
|
|
294
|
+
rationale: { type: 'string' },
|
|
295
|
+
},
|
|
296
|
+
required: ['ruleId', 'confidence', 'alignedWithStyle', 'rationale'],
|
|
297
|
+
},
|
|
298
|
+
},
|
|
257
299
|
summary: { type: 'string' },
|
|
258
300
|
},
|
|
259
301
|
required: ['patterns', 'statistics', 'summary'],
|
|
@@ -336,12 +378,14 @@ export class LearnPatternsTool {
|
|
|
336
378
|
}
|
|
337
379
|
}
|
|
338
380
|
// Discover patterns
|
|
339
|
-
|
|
381
|
+
// Same limit as the rule angular:too-many-inputs.
|
|
382
|
+
const maxInputs = loadConfig(targetPath).rules?.['angular:too-many-inputs']?.maxInputs ?? DEFAULT_MAX_INPUTS;
|
|
383
|
+
const rawPatterns = await this.discoverPatterns(project, categories, maxInputs);
|
|
340
384
|
// Filter by occurrence count
|
|
341
385
|
const patternGroups = this.groupPatterns(rawPatterns);
|
|
342
386
|
const filteredPatterns = this.filterByOccurrence(patternGroups, minOccurrences);
|
|
343
387
|
// Anonymize patterns
|
|
344
|
-
const anonymizedPatterns = this.anonymizePatterns(filteredPatterns, anonymizationLevel);
|
|
388
|
+
const anonymizedPatterns = this.anonymizePatterns(filteredPatterns, anonymizationLevel, targetPath);
|
|
345
389
|
// Calculate complexity
|
|
346
390
|
const patternsWithComplexity = anonymizedPatterns.map((p) => ({
|
|
347
391
|
...p,
|
|
@@ -361,7 +405,7 @@ export class LearnPatternsTool {
|
|
|
361
405
|
id: pattern.id,
|
|
362
406
|
name: pattern.name,
|
|
363
407
|
category: pattern.category,
|
|
364
|
-
type: pattern
|
|
408
|
+
type: patternTypeOf(pattern),
|
|
365
409
|
description: pattern.description,
|
|
366
410
|
occurrences: pattern.occurrences,
|
|
367
411
|
totalOccurrences: pattern.occurrences,
|
|
@@ -421,7 +465,7 @@ export class LearnPatternsTool {
|
|
|
421
465
|
id: p.id,
|
|
422
466
|
name: p.name,
|
|
423
467
|
category: p.category,
|
|
424
|
-
type: p
|
|
468
|
+
type: patternTypeOf(p),
|
|
425
469
|
description: p.description,
|
|
426
470
|
occurrences: p.occurrences,
|
|
427
471
|
totalOccurrences: p.occurrences,
|
|
@@ -466,7 +510,7 @@ export class LearnPatternsTool {
|
|
|
466
510
|
id: p.id,
|
|
467
511
|
name: p.name,
|
|
468
512
|
category: p.category,
|
|
469
|
-
type: p
|
|
513
|
+
type: patternTypeOf(p),
|
|
470
514
|
description: p.description,
|
|
471
515
|
occurrences: p.occurrences,
|
|
472
516
|
totalOccurrences: p.occurrences,
|
|
@@ -487,7 +531,6 @@ export class LearnPatternsTool {
|
|
|
487
531
|
}));
|
|
488
532
|
const ruleResult = ruleGenerator.generateRules(patternEntries, detectedStyleProfile, filesAnalyzed);
|
|
489
533
|
generatedRulesResult = ruleResult.rules.map((rule) => ({
|
|
490
|
-
path: params.ruleOutputPath ?? './learned-rules',
|
|
491
534
|
ruleId: rule.ruleId,
|
|
492
535
|
confidence: rule.confidence,
|
|
493
536
|
alignedWithStyle: rule.alignsWithStyle,
|
|
@@ -564,7 +607,7 @@ export class LearnPatternsTool {
|
|
|
564
607
|
/**
|
|
565
608
|
* Discover patterns from the project.
|
|
566
609
|
*/
|
|
567
|
-
async discoverPatterns(project, categories) {
|
|
610
|
+
async discoverPatterns(project, categories, maxInputs) {
|
|
568
611
|
const patterns = [];
|
|
569
612
|
const sourceFiles = project.getSourceFiles();
|
|
570
613
|
const activeCategories = categories.includes('all') || categories.length === 0
|
|
@@ -585,7 +628,7 @@ export class LearnPatternsTool {
|
|
|
585
628
|
continue;
|
|
586
629
|
}
|
|
587
630
|
for (const category of activeCategories) {
|
|
588
|
-
const categoryPatterns = this.detectPatternsInFile(sourceFile, category, filePath);
|
|
631
|
+
const categoryPatterns = this.detectPatternsInFile(sourceFile, category, filePath, maxInputs);
|
|
589
632
|
patterns.push(...categoryPatterns);
|
|
590
633
|
}
|
|
591
634
|
}
|
|
@@ -594,14 +637,14 @@ export class LearnPatternsTool {
|
|
|
594
637
|
/**
|
|
595
638
|
* Detect patterns in a single file based on category.
|
|
596
639
|
*/
|
|
597
|
-
detectPatternsInFile(sourceFile, category, filePath) {
|
|
640
|
+
detectPatternsInFile(sourceFile, category, filePath, maxInputs) {
|
|
598
641
|
const patterns = [];
|
|
599
642
|
switch (category) {
|
|
600
643
|
case 'rxjs-patterns':
|
|
601
644
|
patterns.push(...this.detectRxjsPatterns(sourceFile, filePath));
|
|
602
645
|
break;
|
|
603
646
|
case 'component-patterns':
|
|
604
|
-
patterns.push(...this.detectComponentPatterns(sourceFile, filePath));
|
|
647
|
+
patterns.push(...this.detectComponentPatterns(sourceFile, filePath, maxInputs));
|
|
605
648
|
break;
|
|
606
649
|
case 'service-patterns':
|
|
607
650
|
patterns.push(...this.detectServicePatterns(sourceFile, filePath));
|
|
@@ -656,7 +699,7 @@ export class LearnPatternsTool {
|
|
|
656
699
|
/**
|
|
657
700
|
* Detect component patterns (lifecycle, inputs, etc.).
|
|
658
701
|
*/
|
|
659
|
-
detectComponentPatterns(sourceFile, filePath) {
|
|
702
|
+
detectComponentPatterns(sourceFile, filePath, maxInputs) {
|
|
660
703
|
const patterns = [];
|
|
661
704
|
const classes = sourceFile.getClasses();
|
|
662
705
|
for (const cls of classes) {
|
|
@@ -668,7 +711,7 @@ export class LearnPatternsTool {
|
|
|
668
711
|
const inputs = cls
|
|
669
712
|
.getProperties()
|
|
670
713
|
.filter((p) => p.getDecorators().some((d) => d.getName() === 'Input'));
|
|
671
|
-
if (inputs.length >
|
|
714
|
+
if (inputs.length > maxInputs) {
|
|
672
715
|
patterns.push({
|
|
673
716
|
type: 'too-many-inputs',
|
|
674
717
|
category: 'component-patterns',
|
|
@@ -874,7 +917,7 @@ export class LearnPatternsTool {
|
|
|
874
917
|
if (patterns.length >= minOccurrences) {
|
|
875
918
|
const [category, type] = key.split(':');
|
|
876
919
|
result.push({
|
|
877
|
-
id:
|
|
920
|
+
id: patternId(category ?? 'unknown', type ?? ''),
|
|
878
921
|
name: this.formatPatternName(type ?? ''),
|
|
879
922
|
category: category ?? 'unknown',
|
|
880
923
|
description: this.generatePatternDescription(type ?? '', patterns),
|
|
@@ -892,62 +935,22 @@ export class LearnPatternsTool {
|
|
|
892
935
|
return result;
|
|
893
936
|
}
|
|
894
937
|
/**
|
|
895
|
-
* Anonymize patterns
|
|
938
|
+
* Anonymize the examples of the patterns (file path, code, metadata) at
|
|
939
|
+
* the given level; see `helpers/pattern-anonymizer.ts`.
|
|
896
940
|
*/
|
|
897
|
-
anonymizePatterns(patterns, level) {
|
|
941
|
+
anonymizePatterns(patterns, level, projectRoot) {
|
|
898
942
|
if (level === 'minimal') {
|
|
899
|
-
return patterns;
|
|
943
|
+
return patterns;
|
|
900
944
|
}
|
|
901
945
|
return patterns.map((pattern) => ({
|
|
902
946
|
...pattern,
|
|
903
947
|
examples: pattern.examples.map((example) => ({
|
|
904
|
-
|
|
905
|
-
code:
|
|
948
|
+
filePath: anonymizeFilePath(example.filePath, projectRoot, level),
|
|
949
|
+
code: anonymizeCode(example.code, level),
|
|
950
|
+
metadata: anonymizeMetadata(example.metadata, level),
|
|
906
951
|
})),
|
|
907
952
|
}));
|
|
908
953
|
}
|
|
909
|
-
/**
|
|
910
|
-
* Anonymize code while preserving framework terms.
|
|
911
|
-
*/
|
|
912
|
-
anonymizeCode(code, level) {
|
|
913
|
-
if (level === 'minimal') {
|
|
914
|
-
return code;
|
|
915
|
-
}
|
|
916
|
-
// Framework terms to preserve
|
|
917
|
-
const preservedTerms = [
|
|
918
|
-
'Component',
|
|
919
|
-
'Injectable',
|
|
920
|
-
'Input',
|
|
921
|
-
'Output',
|
|
922
|
-
'OnInit',
|
|
923
|
-
'OnDestroy',
|
|
924
|
-
'Observable',
|
|
925
|
-
'Subject',
|
|
926
|
-
'BehaviorSubject',
|
|
927
|
-
'subscribe',
|
|
928
|
-
'pipe',
|
|
929
|
-
'map',
|
|
930
|
-
'filter',
|
|
931
|
-
'switchMap',
|
|
932
|
-
'takeUntil',
|
|
933
|
-
'NgModule',
|
|
934
|
-
'Service',
|
|
935
|
-
'Directive',
|
|
936
|
-
'Pipe',
|
|
937
|
-
];
|
|
938
|
-
let anonymized = code;
|
|
939
|
-
// Simple anonymization: replace custom class names
|
|
940
|
-
// This is a simplified version - production would need more sophisticated anonymization
|
|
941
|
-
if (level === 'strict') {
|
|
942
|
-
anonymized = anonymized.replaceAll(/class\s+([A-Z][a-zA-Z0-9]*)/g, (match, className) => {
|
|
943
|
-
if (preservedTerms.some((term) => className.includes(term))) {
|
|
944
|
-
return match;
|
|
945
|
-
}
|
|
946
|
-
return `class GenericClass${Math.random().toString(36).substring(7)}`;
|
|
947
|
-
});
|
|
948
|
-
}
|
|
949
|
-
return anonymized;
|
|
950
|
-
}
|
|
951
954
|
/**
|
|
952
955
|
* Calculate complexity of a pattern.
|
|
953
956
|
*/
|
|
@@ -983,16 +986,13 @@ export class LearnPatternsTool {
|
|
|
983
986
|
};
|
|
984
987
|
}
|
|
985
988
|
/**
|
|
986
|
-
* Generate artifacts (
|
|
989
|
+
* Generate artifacts (fixture files; `'rules'` writes nothing).
|
|
987
990
|
*/
|
|
988
991
|
generateArtifacts(patterns, format, outputPath) {
|
|
989
992
|
const artifacts = {};
|
|
990
993
|
if (format === 'fixtures' || format === 'both') {
|
|
991
994
|
artifacts.fixtures = this.generateFixtures(patterns, outputPath);
|
|
992
995
|
}
|
|
993
|
-
if (format === 'rules' || format === 'both') {
|
|
994
|
-
artifacts.rules = this.generateRules(patterns, outputPath);
|
|
995
|
-
}
|
|
996
996
|
return artifacts;
|
|
997
997
|
}
|
|
998
998
|
/**
|
|
@@ -1016,8 +1016,9 @@ export class LearnPatternsTool {
|
|
|
1016
1016
|
const dir = dirname(fixturePath);
|
|
1017
1017
|
if (!existsSync(dir)) {
|
|
1018
1018
|
mkdirSync(dir, { recursive: true });
|
|
1019
|
-
//
|
|
1020
|
-
|
|
1019
|
+
// Keep the folder this call created out of git without touching any
|
|
1020
|
+
// .gitignore of the project or the working directory.
|
|
1021
|
+
writeFileSync(join(dir, '.gitignore'), '*\n', 'utf-8');
|
|
1021
1022
|
}
|
|
1022
1023
|
writeFileSync(fixturePath, content, 'utf-8');
|
|
1023
1024
|
fixtures.push({
|
|
@@ -1035,7 +1036,7 @@ export class LearnPatternsTool {
|
|
|
1035
1036
|
lines.push('/**');
|
|
1036
1037
|
lines.push(` * Learned Patterns - ${patterns[0]?.category ?? 'Unknown'}`);
|
|
1037
1038
|
lines.push(' * Generated by learn-patterns tool');
|
|
1038
|
-
lines.push(' *
|
|
1039
|
+
lines.push(' * Examples anonymized per anonymizationLevel');
|
|
1039
1040
|
lines.push(' */');
|
|
1040
1041
|
lines.push('');
|
|
1041
1042
|
for (const pattern of patterns) {
|
|
@@ -1054,16 +1055,6 @@ export class LearnPatternsTool {
|
|
|
1054
1055
|
}
|
|
1055
1056
|
return lines.join('\n');
|
|
1056
1057
|
}
|
|
1057
|
-
/**
|
|
1058
|
-
* Generate rule files (stub).
|
|
1059
|
-
*/
|
|
1060
|
-
generateRules(patterns, outputPath) {
|
|
1061
|
-
// Simplified - would generate actual rule templates in production
|
|
1062
|
-
return patterns.map((p) => ({
|
|
1063
|
-
path: `${outputPath ?? './learned-rules'}/${p.id}.rule.ts`,
|
|
1064
|
-
ruleIds: [p.suggestedRule?.ruleId ?? p.id],
|
|
1065
|
-
}));
|
|
1066
|
-
}
|
|
1067
1058
|
/**
|
|
1068
1059
|
* Format pattern name from type.
|
|
1069
1060
|
*/
|
|
@@ -1117,74 +1108,5 @@ export class LearnPatternsTool {
|
|
|
1117
1108
|
}
|
|
1118
1109
|
return counts;
|
|
1119
1110
|
}
|
|
1120
|
-
/**
|
|
1121
|
-
* Ensure output directory is in .gitignore.
|
|
1122
|
-
* Automatically adds the directory to .gitignore when it's created.
|
|
1123
|
-
*/
|
|
1124
|
-
ensureGitignore(outputPath) {
|
|
1125
|
-
try {
|
|
1126
|
-
// Resolve the absolute path
|
|
1127
|
-
const absoluteOutputPath = resolve(outputPath);
|
|
1128
|
-
const currentDir = process.cwd();
|
|
1129
|
-
// Find .gitignore file (walk up from current directory)
|
|
1130
|
-
let gitignorePath = null;
|
|
1131
|
-
let searchDir = currentDir;
|
|
1132
|
-
// Search up to 5 levels for .gitignore
|
|
1133
|
-
for (let i = 0; i < 5; i++) {
|
|
1134
|
-
const candidatePath = resolve(searchDir, '.gitignore');
|
|
1135
|
-
if (existsSync(candidatePath)) {
|
|
1136
|
-
gitignorePath = candidatePath;
|
|
1137
|
-
break;
|
|
1138
|
-
}
|
|
1139
|
-
const parentDir = dirname(searchDir);
|
|
1140
|
-
if (parentDir === searchDir) {
|
|
1141
|
-
break;
|
|
1142
|
-
} // Reached root
|
|
1143
|
-
searchDir = parentDir;
|
|
1144
|
-
}
|
|
1145
|
-
// Calculate relative path from .gitignore location
|
|
1146
|
-
const gitignoreDir = gitignorePath ? dirname(gitignorePath) : currentDir;
|
|
1147
|
-
let relativeOutputPath = absoluteOutputPath.startsWith(gitignoreDir)
|
|
1148
|
-
? absoluteOutputPath.substring(gitignoreDir.length + 1)
|
|
1149
|
-
: outputPath;
|
|
1150
|
-
// Normalize path separators and ensure it ends with /
|
|
1151
|
-
relativeOutputPath = relativeOutputPath.replaceAll('\\', '/');
|
|
1152
|
-
if (!relativeOutputPath.endsWith('/')) {
|
|
1153
|
-
relativeOutputPath += '/';
|
|
1154
|
-
}
|
|
1155
|
-
// Ensure it starts with / for root-relative paths
|
|
1156
|
-
if (!relativeOutputPath.startsWith('/')) {
|
|
1157
|
-
relativeOutputPath = '/' + relativeOutputPath;
|
|
1158
|
-
}
|
|
1159
|
-
// Read existing .gitignore or create new one
|
|
1160
|
-
let gitignoreContent = '';
|
|
1161
|
-
if (gitignorePath && existsSync(gitignorePath)) {
|
|
1162
|
-
gitignoreContent = readFileSync(gitignorePath, 'utf-8');
|
|
1163
|
-
}
|
|
1164
|
-
else {
|
|
1165
|
-
// Create .gitignore in current directory
|
|
1166
|
-
gitignorePath = resolve(currentDir, '.gitignore');
|
|
1167
|
-
}
|
|
1168
|
-
// Check if path already exists in .gitignore
|
|
1169
|
-
const lines = gitignoreContent.split('\n');
|
|
1170
|
-
const pathExists = lines.some((line) => {
|
|
1171
|
-
const trimmed = line.trim();
|
|
1172
|
-
return (trimmed === relativeOutputPath ||
|
|
1173
|
-
trimmed === relativeOutputPath.slice(0, -1) || // Without trailing slash
|
|
1174
|
-
trimmed === outputPath ||
|
|
1175
|
-
trimmed === `${outputPath}/`);
|
|
1176
|
-
});
|
|
1177
|
-
if (!pathExists) {
|
|
1178
|
-
// Add entry to .gitignore
|
|
1179
|
-
const entry = `\n# Auto-generated pattern discovery output (learn-patterns tool)\n${relativeOutputPath}\n`;
|
|
1180
|
-
const updatedContent = gitignoreContent.trimEnd() + entry;
|
|
1181
|
-
writeFileSync(gitignorePath, updatedContent, 'utf-8');
|
|
1182
|
-
}
|
|
1183
|
-
}
|
|
1184
|
-
catch (error) {
|
|
1185
|
-
// Silently fail - .gitignore management is not critical
|
|
1186
|
-
console.warn('Warning: Could not update .gitignore:', error.message);
|
|
1187
|
-
}
|
|
1188
|
-
}
|
|
1189
1111
|
}
|
|
1190
1112
|
//# sourceMappingURL=learn-patterns.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type MCPTool, type ToolAnnotations } from '../types.js';
|
|
1
|
+
import { type MCPTool, type ToolAnnotations, type ToolContext } from '../types.js';
|
|
2
2
|
import { type ModuleSpecifierKind } from '@angular-modernizer/core';
|
|
3
3
|
import { ProjectCache } from './helpers/project-cache.js';
|
|
4
4
|
/**
|
|
@@ -227,7 +227,7 @@ export declare class ListImportsTool implements MCPTool {
|
|
|
227
227
|
};
|
|
228
228
|
required: string[];
|
|
229
229
|
};
|
|
230
|
-
execute(args: Record<string, unknown
|
|
230
|
+
execute(args: Record<string, unknown>, ctx?: ToolContext): Promise<ListImportsOutput>;
|
|
231
231
|
private resolveFilePath;
|
|
232
232
|
private findProjectRoot;
|
|
233
233
|
private toEntry;
|
|
@@ -3,7 +3,7 @@ import { classifyModuleSpecifier, collectModuleEdges, } from '@angular-modernize
|
|
|
3
3
|
import { existsSync } from 'node:fs';
|
|
4
4
|
import { dirname, isAbsolute, relative, resolve } from 'node:path';
|
|
5
5
|
import { findTsConfig } from './helpers/find-ts-config.js';
|
|
6
|
-
import { ProjectCache } from './helpers/project-cache.js';
|
|
6
|
+
import { ProjectCache, acquireProject } from './helpers/project-cache.js';
|
|
7
7
|
import { COMPACT_OUTPUT_SCHEMA, limitList, parseCompactOptions, truncationNote, } from './helpers/compact-output.js';
|
|
8
8
|
import { WARNINGS_OUTPUT_SCHEMA, withWarnings, } from './helpers/output-contract.js';
|
|
9
9
|
/** Unresolved specifiers named in the summary. */
|
|
@@ -139,7 +139,7 @@ export class ListImportsTool {
|
|
|
139
139
|
},
|
|
140
140
|
required: ['file', 'projectRoot', 'tsConfigPath', 'truncated', 'counts', 'summary'],
|
|
141
141
|
};
|
|
142
|
-
async execute(args) {
|
|
142
|
+
async execute(args, ctx = {}) {
|
|
143
143
|
const params = args;
|
|
144
144
|
if (!params.file || typeof params.file !== 'string') {
|
|
145
145
|
throw new Error('file is required');
|
|
@@ -161,7 +161,7 @@ export class ListImportsTool {
|
|
|
161
161
|
}
|
|
162
162
|
// A file outside the program (a spec excluded by the tsconfig, say) gets
|
|
163
163
|
// its own Project: the cached one must not grow.
|
|
164
|
-
const sourceFile = this.projects
|
|
164
|
+
const sourceFile = (await acquireProject(this.projects, tsConfigPath, ctx)).getSourceFile(filePath) ??
|
|
165
165
|
new Project({ tsConfigFilePath: tsConfigPath }).addSourceFileAtPath(filePath);
|
|
166
166
|
const includeReExports = params.includeReExports !== false;
|
|
167
167
|
const imports = collectModuleEdges(sourceFile, includeReExports).map((edge) => this.toEntry(sourceFile, edge, projectRoot));
|