@angular-modernizer/adapter-mcp 1.2.0 → 2.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.
Files changed (138) hide show
  1. package/CHANGELOG.md +688 -0
  2. package/README.md +84 -445
  3. package/dist/cli.js +9 -1
  4. package/dist/core/project-analyzer.js +2 -2
  5. package/dist/index.d.ts +10 -0
  6. package/dist/index.js +1 -0
  7. package/dist/scan-host/scan-host.d.ts +7 -0
  8. package/dist/scan-host/scan-host.js +73 -10
  9. package/dist/scan-host/scan-protocol.d.ts +2 -0
  10. package/dist/scan-host/scan-worker.js +14 -8
  11. package/dist/server/limited-stdio-transport.d.ts +6 -3
  12. package/dist/server/limited-stdio-transport.js +26 -9
  13. package/dist/server/mcp-server.js +1 -1
  14. package/dist/server/sdk-server.d.ts +14 -3
  15. package/dist/server/sdk-server.js +54 -6
  16. package/dist/server/tool-registry.d.ts +3 -1
  17. package/dist/server/tool-registry.js +8 -3
  18. package/dist/streaming/progress-store.d.ts +19 -7
  19. package/dist/streaming/progress-store.js +19 -8
  20. package/dist/tools/analyze-build-impact.d.ts +7 -4
  21. package/dist/tools/analyze-build-impact.js +8 -3
  22. package/dist/tools/analyze-core-to-shared.d.ts +10 -6
  23. package/dist/tools/analyze-core-to-shared.js +63 -60
  24. package/dist/tools/analyze-parser-performance.d.ts +57 -13
  25. package/dist/tools/analyze-parser-performance.js +67 -6
  26. package/dist/tools/analyze-project.d.ts +55 -4
  27. package/dist/tools/analyze-project.js +104 -15
  28. package/dist/tools/check-incremental-compatibility.d.ts +30 -41
  29. package/dist/tools/check-incremental-compatibility.js +32 -264
  30. package/dist/tools/collect-feedback.js +15 -2
  31. package/dist/tools/compare-health.d.ts +40 -4
  32. package/dist/tools/compare-health.js +22 -5
  33. package/dist/tools/extract-libraries.js +42 -27
  34. package/dist/tools/find-angular-symbol.js +3 -2
  35. package/dist/tools/find-component-hosts.js +3 -2
  36. package/dist/tools/find-usages.js +21 -12
  37. package/dist/tools/get-call-graph.js +15 -2
  38. package/dist/tools/get-operation-progress-tool.d.ts +1 -1
  39. package/dist/tools/get-operation-progress-tool.js +2 -2
  40. package/dist/tools/get-operation-progress.d.ts +4 -1
  41. package/dist/tools/get-operation-progress.js +6 -2
  42. package/dist/tools/helpers/analysis-output.d.ts +32 -1
  43. package/dist/tools/helpers/analysis-output.js +25 -1
  44. package/dist/tools/helpers/build-cache.d.ts +27 -0
  45. package/dist/tools/helpers/build-cache.js +86 -0
  46. package/dist/tools/helpers/class-filter.d.ts +18 -0
  47. package/dist/tools/helpers/class-filter.js +30 -0
  48. package/dist/tools/helpers/cli-arguments.d.ts +23 -0
  49. package/dist/tools/helpers/cli-arguments.js +35 -0
  50. package/dist/tools/helpers/feedback-catalog.d.ts +38 -0
  51. package/dist/tools/helpers/feedback-catalog.js +196 -0
  52. package/dist/tools/helpers/feedback-sidecar.d.ts +201 -0
  53. package/dist/tools/helpers/feedback-sidecar.js +381 -0
  54. package/dist/tools/helpers/file-type-check.d.ts +34 -0
  55. package/dist/tools/helpers/file-type-check.js +56 -0
  56. package/dist/tools/helpers/health-delta.d.ts +6 -0
  57. package/dist/tools/helpers/health-delta.js +4 -1
  58. package/dist/tools/helpers/library-import-warning.d.ts +33 -0
  59. package/dist/tools/helpers/library-import-warning.js +38 -0
  60. package/dist/tools/helpers/library-imports.d.ts +38 -14
  61. package/dist/tools/helpers/library-imports.js +128 -23
  62. package/dist/tools/helpers/output-contract.d.ts +64 -0
  63. package/dist/tools/helpers/output-contract.js +67 -0
  64. package/dist/tools/helpers/pattern-anonymizer.d.ts +27 -0
  65. package/dist/tools/helpers/pattern-anonymizer.js +159 -0
  66. package/dist/tools/helpers/project-cache.d.ts +5 -4
  67. package/dist/tools/helpers/project-cache.js +21 -16
  68. package/dist/tools/helpers/project-decorators.d.ts +11 -4
  69. package/dist/tools/helpers/project-decorators.js +13 -6
  70. package/dist/tools/helpers/refresh-apply.d.ts +94 -0
  71. package/dist/tools/helpers/refresh-apply.js +460 -0
  72. package/dist/tools/helpers/refresh-inventory.d.ts +106 -0
  73. package/dist/tools/helpers/refresh-inventory.js +631 -0
  74. package/dist/tools/helpers/rule-runner.js +3 -1
  75. package/dist/tools/helpers/scan-cache.d.ts +117 -5
  76. package/dist/tools/helpers/scan-cache.js +179 -6
  77. package/dist/tools/helpers/scan-engine.d.ts +43 -6
  78. package/dist/tools/helpers/scan-engine.js +141 -22
  79. package/dist/tools/helpers/scan-plan.js +16 -2
  80. package/dist/tools/helpers/source-map-loader.d.ts +55 -0
  81. package/dist/tools/helpers/source-map-loader.js +226 -0
  82. package/dist/tools/helpers/template-check.d.ts +76 -0
  83. package/dist/tools/helpers/template-check.js +158 -0
  84. package/dist/tools/helpers/tool-cache.d.ts +7 -2
  85. package/dist/tools/helpers/tool-cache.js +9 -3
  86. package/dist/tools/helpers/tool-context.d.ts +18 -0
  87. package/dist/tools/helpers/tool-context.js +29 -0
  88. package/dist/tools/helpers/transform-safety.d.ts +151 -1
  89. package/dist/tools/helpers/transform-safety.js +357 -4
  90. package/dist/tools/inspect-form-group.js +5 -0
  91. package/dist/tools/inspect-i18n.d.ts +1 -1
  92. package/dist/tools/inspect-template.js +8 -2
  93. package/dist/tools/learn-patterns.d.ts +43 -28
  94. package/dist/tools/learn-patterns.js +83 -161
  95. package/dist/tools/list-imports.d.ts +1 -1
  96. package/dist/tools/orchestrate-migration.d.ts +19 -1
  97. package/dist/tools/orchestrate-migration.js +52 -10
  98. package/dist/tools/parse-stack-trace.d.ts +48 -1
  99. package/dist/tools/parse-stack-trace.js +108 -9
  100. package/dist/tools/plan-migration.js +22 -10
  101. package/dist/tools/refresh-state.d.ts +378 -0
  102. package/dist/tools/refresh-state.js +370 -0
  103. package/dist/tools/resolve-type.js +10 -3
  104. package/dist/tools/review-feedback.d.ts +42 -7
  105. package/dist/tools/review-feedback.js +24 -17
  106. package/dist/tools/rollback-changes.d.ts +5 -0
  107. package/dist/tools/rollback-changes.js +7 -2
  108. package/dist/tools/run-angular-cli.js +36 -22
  109. package/dist/tools/run-build.d.ts +33 -28
  110. package/dist/tools/run-build.js +136 -438
  111. package/dist/tools/run-schematic.d.ts +8 -2
  112. package/dist/tools/run-schematic.js +80 -50
  113. package/dist/tools/scan-all.d.ts +37 -15
  114. package/dist/tools/scan-all.js +76 -115
  115. package/dist/tools/scan-angular.d.ts +33 -14
  116. package/dist/tools/scan-angular.js +77 -94
  117. package/dist/tools/scan-architecture.d.ts +37 -12
  118. package/dist/tools/scan-architecture.js +220 -139
  119. package/dist/tools/scan-solid.d.ts +33 -14
  120. package/dist/tools/scan-solid.js +80 -91
  121. package/dist/tools/search-codebase.d.ts +6 -1
  122. package/dist/tools/search-codebase.js +13 -7
  123. package/dist/tools/suggest-improvements.d.ts +34 -3
  124. package/dist/tools/suggest-improvements.js +34 -9
  125. package/dist/tools/trace-output-flow.js +3 -2
  126. package/dist/tools/transform-code-batch.d.ts +9 -9
  127. package/dist/tools/transform-code.d.ts +161 -12
  128. package/dist/tools/transform-code.js +715 -206
  129. package/dist/tools/validate-before-transform.js +2 -1
  130. package/dist/tools/validate-project-compatibility.d.ts +28 -55
  131. package/dist/tools/validate-project-compatibility.js +33 -225
  132. package/dist/tools/validate-transformation.d.ts +40 -26
  133. package/dist/tools/validate-transformation.js +115 -294
  134. package/dist/tools/verify-citations.js +8 -2
  135. package/dist/types.d.ts +9 -9
  136. package/dist/utils/format-tool-response.d.ts +3 -1
  137. package/dist/utils/format-tool-response.js +8 -3
  138. package/package.json +14 -13
@@ -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
- * Generated rules (if generateRules=true).
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 and can
209
- * write fixtures and generated rules.
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 to remove business-specific terms.
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 (fixtures or rules).
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, readFileSync } from 'node:fs';
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) generated.`);
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
- const rules = result.artifacts?.rules?.length ?? 0;
40
- if (fixtures + rules > 0) {
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 and can
53
- * write fixtures and generated rules.
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: 'Output format for generated artifacts',
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: 'Anonymization level for patterns',
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: 'Generate analysis rules from high-confidence patterns',
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: 'Output path for generated rule files',
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: { type: 'object' },
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: { type: 'array', items: { type: 'object' } },
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
- const rawPatterns = await this.discoverPatterns(project, categories);
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.id.replace('learned-', '').replace(/-\d+$/, ''),
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.id.replace('learned-', '').replace(/-\d+$/, ''),
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.id.replace('learned-', '').replace(/-\d+$/, ''),
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 > 5) {
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: `learned-${type}-${Date.now()}`,
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 to remove business-specific terms.
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; // No anonymization
943
+ return patterns;
900
944
  }
901
945
  return patterns.map((pattern) => ({
902
946
  ...pattern,
903
947
  examples: pattern.examples.map((example) => ({
904
- ...example,
905
- code: this.anonymizeCode(example.code, level),
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 (fixtures or rules).
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
- // Automatically add to .gitignore when directory is created
1020
- this.ensureGitignore(basePath);
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(' * Auto-anonymized examples from real-world code');
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
@@ -219,7 +219,7 @@ export declare class ListImportsTool implements MCPTool {
219
219
  type: string;
220
220
  };
221
221
  };
222
- required: ("total" | "unresolved" | "typeOnly" | "aliased" | "relative" | "external" | "reExports")[];
222
+ required: ("total" | "unresolved" | "external" | "aliased" | "relative" | "reExports" | "typeOnly")[];
223
223
  };
224
224
  summary: {
225
225
  type: string;
@@ -32,14 +32,23 @@ export interface OrchestrateMigrationResult {
32
32
  stepResults: {
33
33
  /** Step id from the workflow definition. */
34
34
  stepId: string;
35
- /** Step name (the step id). */
35
+ /** Step name from the workflow definition. */
36
36
  name: string;
37
+ /** Tool the step called. */
38
+ tool?: string;
37
39
  /** Step status reported by the workflow engine. */
38
40
  status: string;
39
41
  /** Duration of the step in milliseconds. */
40
42
  durationMs: number;
41
43
  /** Error message of a failed step. */
42
44
  error?: string;
45
+ /**
46
+ * Whether the tool reported success (`false` for `success: false` or
47
+ * `status: 'failed'`); absent when the tool did not answer.
48
+ */
49
+ toolSuccess?: boolean;
50
+ /** The tool's own summary of the step. */
51
+ toolSummary?: string;
43
52
  }[];
44
53
  /**
45
54
  * Checkpoints created during execution
@@ -245,6 +254,9 @@ export declare class OrchestrateMigrationTool implements MCPTool {
245
254
  name: {
246
255
  type: string;
247
256
  };
257
+ tool: {
258
+ type: string;
259
+ };
248
260
  status: {
249
261
  type: string;
250
262
  };
@@ -254,6 +266,12 @@ export declare class OrchestrateMigrationTool implements MCPTool {
254
266
  error: {
255
267
  type: string;
256
268
  };
269
+ toolSuccess: {
270
+ type: string;
271
+ };
272
+ toolSummary: {
273
+ type: string;
274
+ };
257
275
  };
258
276
  required: string[];
259
277
  };