vibecodingmachine-core 2026.2.26-1739 → 2026.3.9-850

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 (192) hide show
  1. package/package.json +1 -1
  2. package/src/agents/AgentCheckDiscoveryService.js +180 -0
  3. package/src/agents/AgentCheckService.js +18 -261
  4. package/src/agents/AgentCheckStatisticsService.js +195 -0
  5. package/src/agents/EnvironmentConfigurationManager.js +31 -380
  6. package/src/agents/InstallationType.js +19 -6
  7. package/src/agents/SimpleAgentCheckService.js +472 -0
  8. package/src/agents/config-managers/ConfigUtils.js +72 -0
  9. package/src/agents/config-managers/DefaultConfig.js +58 -0
  10. package/src/agents/config-managers/EnvVarLoader.js +66 -0
  11. package/src/agents/config-managers/FileConfigLoader.js +124 -0
  12. package/src/agents/config-managers/TypeConverters.js +61 -0
  13. package/src/agents/config-managers/VariableMappings.js +92 -0
  14. package/src/agents/discovery/AgentDiscoveryService-refactored.js +272 -0
  15. package/src/agents/discovery/AgentDiscoveryService.js +29 -403
  16. package/src/agents/discovery/agent-validator.js +262 -0
  17. package/src/agents/discovery/discovery-results.js +176 -0
  18. package/src/agents/discovery/discovery-scanner.js +268 -0
  19. package/src/agents/discovery/discovery-utils.js +161 -0
  20. package/src/agents/discovery/executable-analyzer.js +290 -0
  21. package/src/agents/discovery/history-manager.js +310 -0
  22. package/src/agents/verification/ResultAnalyzer-refactored.js +341 -0
  23. package/src/agents/verification/ResultAnalyzer.js +30 -431
  24. package/src/agents/verification/analysis-utils.js +310 -0
  25. package/src/agents/verification/batch-analyzer.js +440 -0
  26. package/src/agents/verification/pattern-recognizer.js +369 -0
  27. package/src/agents/verification/report-generator.js +320 -0
  28. package/src/agents/verification/test-analyzer.js +290 -0
  29. package/src/agents/windows/InstallerFactory.js +4 -0
  30. package/src/agents/windows/VSCodeExtensionInstaller.js +404 -0
  31. package/src/analysis/analysis-engine.js +314 -0
  32. package/src/analysis/ast-analyzer.js +342 -0
  33. package/src/analysis/boundary-detector-refactored.js +378 -0
  34. package/src/analysis/boundary-detector.js +200 -603
  35. package/src/analysis/boundary-scanner.js +609 -0
  36. package/src/analysis/boundary-types.js +118 -0
  37. package/src/analysis/boundary-utils.js +293 -0
  38. package/src/analysis/deadline-priority-calculator.js +18 -0
  39. package/src/analysis/detection-methods.js +347 -0
  40. package/src/analysis/importance-priority-calculator.js +18 -0
  41. package/src/analysis/priority/factor-calculators.js +204 -0
  42. package/src/analysis/priority/factor-helpers.js +71 -0
  43. package/src/analysis/priority/priority-constants.js +73 -0
  44. package/src/analysis/priority/priority-factor-calculators.js +301 -0
  45. package/src/analysis/priority/reasons-generator.js +44 -0
  46. package/src/analysis/priority-calculator.js +15 -580
  47. package/src/analysis/strategy-generator.js +16 -66
  48. package/src/analysis/type-priority-calculator.js +18 -0
  49. package/src/analysis/urgency-priority-calculator.js +18 -0
  50. package/src/auto-mode/AutoModeBusinessLogic.js +2 -40
  51. package/src/commands/disable-requirement.js +60 -0
  52. package/src/commands/disable-spec.js +60 -0
  53. package/src/commands/enable-requirement.js +60 -0
  54. package/src/commands/enable-spec.js +60 -0
  55. package/src/commands/registry.js +1 -6
  56. package/src/commands/requirements.js +8 -2
  57. package/src/ide-integration/applescript-manager.cjs +9 -24
  58. package/src/ide-integration/cdp-handlers/chat-reader.js +44 -0
  59. package/src/ide-integration/cdp-handlers/connection-handler.js +88 -0
  60. package/src/ide-integration/cdp-handlers/continuation-handler.js +314 -0
  61. package/src/ide-integration/cdp-handlers/message-submitter.js +75 -0
  62. package/src/ide-integration/cdp-handlers/text-sender.js +138 -0
  63. package/src/ide-integration/cdp-manager.js +28 -573
  64. package/src/ide-integration/claude-code-cli-manager.cjs +48 -12
  65. package/src/ide-integration/ide-openers/claude-opener.js +171 -0
  66. package/src/ide-integration/ide-openers/cursor-opener.js +53 -0
  67. package/src/ide-integration/ide-openers/other-ides-opener.js +230 -0
  68. package/src/ide-integration/ide-openers/vscode-opener.js +147 -0
  69. package/src/ide-integration/macos-ide-manager.js +20 -582
  70. package/src/ide-integration/macos-quota-checker.js +164 -0
  71. package/src/ide-integration/macos-text-sender.js +19 -38
  72. package/src/ide-integration/provider-manager.cjs +52 -7
  73. package/src/index.cjs +6 -0
  74. package/src/index.js +10 -0
  75. package/src/llm/direct-llm-manager.cjs +501 -0
  76. package/src/localization/translations/en-part1.js +363 -0
  77. package/src/localization/translations/en-part2.js +320 -0
  78. package/src/localization/translations/en.js +4 -687
  79. package/src/localization/translations/es-part1.js +363 -0
  80. package/src/localization/translations/es-part2.js +320 -0
  81. package/src/localization/translations/es.js +4 -688
  82. package/src/models/file-analysis-collection.js +139 -0
  83. package/src/models/file-analysis-metrics.js +50 -0
  84. package/src/models/file-analysis.js +15 -262
  85. package/src/models/plan-manager.js +410 -0
  86. package/src/models/refactoring-models.js +380 -0
  87. package/src/models/refactoring-plan-refactored.js +81 -0
  88. package/src/models/refactoring-plan.js +2 -663
  89. package/src/monitoring/alert-system.js +4 -45
  90. package/src/monitoring/continuous-scan-notifications.js +37 -191
  91. package/src/monitoring/notification-handlers/base-handler.js +58 -0
  92. package/src/monitoring/notification-handlers/error-handler.js +36 -0
  93. package/src/monitoring/notification-handlers/index.js +21 -0
  94. package/src/monitoring/notification-handlers/new-violation-handler.js +91 -0
  95. package/src/monitoring/notification-handlers/progress-handler.js +48 -0
  96. package/src/monitoring/notification-handlers/resolved-violation-handler.js +54 -0
  97. package/src/monitoring/notification-handlers/threshold-handler.js +36 -0
  98. package/src/provider-registry.js +8 -0
  99. package/src/refactoring/boundary/boundary-detector-refactored.js +58 -0
  100. package/src/refactoring/boundary/boundary-detector.js +26 -596
  101. package/src/refactoring/boundary/detectors/boundary-analyzers.js +281 -0
  102. package/src/refactoring/boundary/detectors/boundary-core.js +167 -0
  103. package/src/refactoring/boundary/detectors/class-detector.js +247 -0
  104. package/src/refactoring/boundary/detectors/config-detector.js +270 -0
  105. package/src/refactoring/boundary/detectors/constant-detector.js +269 -0
  106. package/src/refactoring/boundary/detectors/function-detector.js +248 -0
  107. package/src/refactoring/boundary/detectors/module-detector.js +249 -0
  108. package/src/refactoring/boundary/detectors/object-detector.js +247 -0
  109. package/src/refactoring/boundary/detectors/type-detectors.js +338 -0
  110. package/src/refactoring/boundary/detectors/utility-detector.js +270 -0
  111. package/src/refactoring/circular-dependency-resolver-original.js +16 -76
  112. package/src/refactoring/code-mover-refactored.js +309 -0
  113. package/src/refactoring/code-mover.js +48 -355
  114. package/src/refactoring/execution-status.js +18 -0
  115. package/src/refactoring/execution-strategies.js +172 -0
  116. package/src/refactoring/file-splitter-core.js +568 -0
  117. package/src/refactoring/file-splitter-types.js +136 -0
  118. package/src/refactoring/file-splitter.js +2 -682
  119. package/src/refactoring/functionality-validator.js +11 -51
  120. package/src/refactoring/import-manager-refactored.js +385 -0
  121. package/src/refactoring/import-manager.js +112 -487
  122. package/src/refactoring/import-models.js +189 -0
  123. package/src/refactoring/import-parser.js +306 -0
  124. package/src/refactoring/move-executor.js +431 -0
  125. package/src/refactoring/move-utils.js +368 -0
  126. package/src/refactoring/operation-executor.js +76 -0
  127. package/src/refactoring/plan-creator.js +36 -0
  128. package/src/refactoring/plan-executor.js +143 -0
  129. package/src/refactoring/plan-validator.js +68 -0
  130. package/src/refactoring/refactoring-executor-result.js +70 -0
  131. package/src/refactoring/refactoring-executor.js +34 -569
  132. package/src/refactoring/refactoring-operation.js +94 -0
  133. package/src/refactoring/refactoring-plan.js +69 -0
  134. package/src/refactoring/refactoring-rollback.js +22 -527
  135. package/src/refactoring/rollback-handlers/RollbackExecutor.js +107 -0
  136. package/src/refactoring/rollback-handlers/RollbackManager.js +265 -0
  137. package/src/refactoring/rollback-handlers/RollbackOperation.js +105 -0
  138. package/src/refactoring/rollback-handlers/RollbackResult.js +109 -0
  139. package/src/refactoring/rollback-handlers/RollbackStatistics.js +77 -0
  140. package/src/refactoring/test-validator.js +32 -448
  141. package/src/refactoring/validation/baseline-runner.js +71 -0
  142. package/src/refactoring/validation/report-generator.js +136 -0
  143. package/src/refactoring/validation/result-comparator.js +92 -0
  144. package/src/refactoring/validation/test-suite.js +59 -0
  145. package/src/refactoring/validation/test-validation-result.js +83 -0
  146. package/src/refactoring/validation/validation-runner.js +95 -0
  147. package/src/refactoring/validation/validation-status.js +18 -0
  148. package/src/rui/commands/AgentCommandParser.js +60 -369
  149. package/src/rui/commands/AgentResponseFormatter.js +7 -47
  150. package/src/rui/commands/parsers/CommandMapper.js +148 -0
  151. package/src/rui/commands/parsers/CommandValidator.js +228 -0
  152. package/src/rui/commands/parsers/ComponentExtractor.js +100 -0
  153. package/src/rui/commands/parsers/TokenParser.js +69 -0
  154. package/src/rui/commands/parsers/tokenizer.js +153 -0
  155. package/src/utils/current-requirement-operations.js +50 -1
  156. package/src/utils/report-generator.js +18 -514
  157. package/src/utils/report-generators/analysis-generator.js +115 -0
  158. package/src/utils/report-generators/base-generator.js +141 -0
  159. package/src/utils/report-generators/compliance-generator.js +41 -0
  160. package/src/utils/report-generators/format-handlers.js +185 -0
  161. package/src/utils/report-generators/refactoring-generator.js +46 -0
  162. package/src/utils/report-generators/validation-generator.js +63 -0
  163. package/src/utils/requirement-enable-disable.js +265 -0
  164. package/src/utils/requirement-helpers/requirement-file-ops.js +69 -1
  165. package/src/utils/requirement-helpers/requirement-mover.js +88 -1
  166. package/src/utils/requirement-helpers.js +5 -2
  167. package/src/utils/smoke-test-cli.js +45 -8
  168. package/src/utils/specification-enable-disable.js +122 -0
  169. package/src/utils/specification-helpers.js +30 -4
  170. package/src/utils/specification-migration.js +5 -5
  171. package/src/utils/test-comparator.js +118 -0
  172. package/src/utils/test-config.js +54 -0
  173. package/src/utils/test-executor.js +133 -0
  174. package/src/utils/test-parser.js +215 -0
  175. package/src/utils/test-runner-baseline.js +63 -0
  176. package/src/utils/test-runner-core.js +98 -0
  177. package/src/utils/test-runner-report.js +39 -0
  178. package/src/utils/test-runner-validation.js +71 -0
  179. package/src/utils/test-runner.js +11 -535
  180. package/src/validation/comparison-analyzer.js +333 -0
  181. package/src/validation/compliance-reporter-new.js +282 -0
  182. package/src/validation/compliance-reporter-refactored.js +344 -0
  183. package/src/validation/compliance-reporter.js +278 -591
  184. package/src/validation/compliance-utils.js +278 -0
  185. package/src/validation/html-generator.js +446 -0
  186. package/src/validation/metrics/category-calculator.js +137 -0
  187. package/src/validation/metrics/metrics-helpers.js +155 -0
  188. package/src/validation/metrics/overview-calculator.js +85 -0
  189. package/src/validation/metrics/overview-metrics.js +41 -0
  190. package/src/validation/metrics/quality-calculator.js +166 -0
  191. package/src/validation/metrics/size-calculator.js +69 -0
  192. package/src/validation/metrics-calculator.js +27 -551
@@ -5,6 +5,7 @@ const { getRequirementsPath } = require('./repo-helpers.cjs');
5
5
  const { logger } = require('./logger.cjs');
6
6
  const { DEFAULT_INSTRUCTION_TEXT } = require('./requirement-file-management');
7
7
  const { getProjectRequirementStats } = require('./requirement-statistics');
8
+ const { isRequirementDisabled } = require('./requirement-enable-disable');
8
9
 
9
10
  /**
10
11
  * Current requirement management operations
@@ -464,9 +465,57 @@ async function getCurrentRequirementName(repoPath) {
464
465
  }
465
466
  }
466
467
 
468
+ /**
469
+ * Get all requirements with their disabled status
470
+ * @param {string} repoPath - Repository root path
471
+ * @returns {Promise<Array<{text: string, disabled: boolean, section: string}>>}
472
+ */
473
+ async function getAllRequirementsWithStatus(repoPath = process.cwd()) {
474
+ try {
475
+ const hostname = os.hostname();
476
+ const requirementsFilePath = await getRequirementsPath(repoPath, hostname);
477
+
478
+ if (!requirementsFilePath || !(await fs.pathExists(requirementsFilePath))) {
479
+ return [];
480
+ }
481
+
482
+ // Read the requirements file content
483
+ const content = await fs.readFile(requirementsFilePath, 'utf8');
484
+ const lines = content.split('\n');
485
+
486
+ const requirements = [];
487
+ let currentSection = '';
488
+
489
+ for (const line of lines) {
490
+ if (line.startsWith('##')) {
491
+ currentSection = line.trim();
492
+ continue;
493
+ }
494
+
495
+ if (line.trim().startsWith('- ')) {
496
+ const requirementText = line.substring(2).trim();
497
+ const disabled = requirementText.startsWith('DISABLED:');
498
+ const actualText = disabled ? requirementText.replace(/^DISABLED:\s*/, '') : requirementText;
499
+
500
+ requirements.push({
501
+ text: actualText,
502
+ disabled,
503
+ section: currentSection
504
+ });
505
+ }
506
+ }
507
+
508
+ return requirements;
509
+ } catch (error) {
510
+ logger.error('Error getting all requirements with status:', error);
511
+ return [];
512
+ }
513
+ }
514
+
467
515
  module.exports = {
468
516
  getCurrentRequirement,
469
517
  isCurrentRequirementDone,
470
518
  moveToNextRequirement,
471
- getCurrentRequirementName
519
+ getCurrentRequirementName,
520
+ getAllRequirementsWithStatus
472
521
  };
@@ -1,13 +1,15 @@
1
1
  /**
2
2
  * Report Generator
3
3
  *
4
- * Generates comprehensive reports for file size analysis and refactoring operations.
5
- * Supports multiple output formats and customizable content.
4
+ * Main entry point for generating reports. Delegates to specialized generators.
6
5
  */
7
6
 
8
- const fs = require('fs');
9
- const path = require('path');
10
7
  const RefactoringConfig = require('../config/refactoring-config');
8
+ const AnalysisReportGenerator = require('./report-generators/analysis-generator');
9
+ const RefactoringReportGenerator = require('./report-generators/refactoring-generator');
10
+ const ValidationReportGenerator = require('./report-generators/validation-generator');
11
+ const ComplianceReportGenerator = require('./report-generators/compliance-generator');
12
+ const { FormatHandler, OUTPUT_FORMATS } = require('./report-generators/format-handlers');
11
13
 
12
14
  /**
13
15
  * Report types
@@ -19,546 +21,48 @@ const REPORT_TYPES = {
19
21
  COMPLIANCE: 'compliance'
20
22
  };
21
23
 
22
- /**
23
- * Output formats
24
- */
25
- const OUTPUT_FORMATS = {
26
- JSON: 'json',
27
- MARKDOWN: 'markdown',
28
- CONSOLE: 'console',
29
- HTML: 'html'
30
- };
31
-
32
24
  /**
33
25
  * Report generator class
34
26
  */
35
27
  class ReportGenerator {
36
28
  constructor(config = RefactoringConfig) {
37
29
  this.config = config;
38
- this.reportData = null;
39
- this.metadata = {
40
- generatedAt: new Date().toISOString(),
41
- version: '1.0.0',
42
- config: config.reporting || {}
43
- };
30
+ this.analysisGenerator = new AnalysisReportGenerator(config);
31
+ this.refactoringGenerator = new RefactoringReportGenerator(config);
32
+ this.validationGenerator = new ValidationReportGenerator(config);
33
+ this.complianceGenerator = new ComplianceReportGenerator(config);
44
34
  }
45
35
 
46
36
  /**
47
37
  * Generate analysis report
48
38
  */
49
39
  generateAnalysisReport(analysisData, options = {}) {
50
- this.reportData = {
51
- type: REPORT_TYPES.ANALYSIS,
52
- metadata: this.metadata,
53
- summary: this.generateAnalysisSummary(analysisData),
54
- files: analysisData.files || [],
55
- recommendations: this.generateRecommendations(analysisData),
56
- statistics: this.generateStatistics(analysisData)
57
- };
58
-
59
- return this.outputReport(options.format || OUTPUT_FORMATS.JSON, options.outputPath);
40
+ const reportData = this.analysisGenerator.generate(analysisData);
41
+ return FormatHandler.output(reportData, options.format || OUTPUT_FORMATS.JSON, options.outputPath);
60
42
  }
61
43
 
62
44
  /**
63
45
  * Generate refactoring report
64
46
  */
65
47
  generateRefactoringReport(refactoringData, options = {}) {
66
- this.reportData = {
67
- type: REPORT_TYPES.REFACTORING,
68
- metadata: this.metadata,
69
- summary: this.generateRefactoringSummary(refactoringData),
70
- operations: refactoringData.operations || [],
71
- results: refactoringData.results || [],
72
- rollback: refactoringData.rollback || {}
73
- };
74
-
75
- return this.outputReport(options.format || OUTPUT_FORMATS.JSON, options.outputPath);
48
+ const reportData = this.refactoringGenerator.generate(refactoringData);
49
+ return FormatHandler.output(reportData, options.format || OUTPUT_FORMATS.JSON, options.outputPath);
76
50
  }
77
51
 
78
52
  /**
79
53
  * Generate validation report
80
54
  */
81
55
  generateValidationReport(validationData, options = {}) {
82
- this.reportData = {
83
- type: REPORT_TYPES.VALIDATION,
84
- metadata: this.metadata,
85
- summary: this.generateValidationSummary(validationData),
86
- results: validationData.results || [],
87
- compliance: this.generateComplianceMetrics(validationData)
88
- };
89
-
90
- return this.outputReport(options.format || OUTPUT_FORMATS.JSON, options.outputPath);
56
+ const reportData = this.validationGenerator.generate(validationData);
57
+ return FormatHandler.output(reportData, options.format || OUTPUT_FORMATS.JSON, options.outputPath);
91
58
  }
92
59
 
93
60
  /**
94
61
  * Generate compliance report
95
62
  */
96
63
  generateComplianceReport(complianceData, options = {}) {
97
- this.reportData = {
98
- type: REPORT_TYPES.COMPLIANCE,
99
- metadata: this.metadata,
100
- summary: this.generateComplianceSummary(complianceData),
101
- metrics: complianceData.metrics || {},
102
- violations: complianceData.violations || [],
103
- trends: complianceData.trends || {}
104
- };
105
-
106
- return this.outputReport(options.format || OUTPUT_FORMATS.JSON, options.outputPath);
107
- }
108
-
109
- /**
110
- * Generate analysis summary
111
- */
112
- generateAnalysisSummary(analysisData) {
113
- const files = analysisData.files || [];
114
- const totalFiles = files.length;
115
- const largeFiles = files.filter(f => f.lineCount > 555).length;
116
- const mediumFiles = files.filter(f => f.lineCount > 300 && f.lineCount <= 555).length;
117
- const smallFiles = files.filter(f => f.lineCount <= 300).length;
118
-
119
- const totalLines = files.reduce((sum, f) => sum + f.lineCount, 0);
120
- const avgLines = totalFiles > 0 ? Math.round(totalLines / totalFiles) : 0;
121
-
122
- return {
123
- totalFiles,
124
- totalLines,
125
- averageLines: avgLines,
126
- sizeDistribution: {
127
- small: smallFiles,
128
- medium: mediumFiles,
129
- large: largeFiles,
130
- xlarge: files.filter(f => f.lineCount > 800).length
131
- },
132
- complianceRate: totalFiles > 0 ? ((totalFiles - largeFiles) / totalFiles * 100).toFixed(1) : 0,
133
- needsRefactoring: largeFiles + mediumFiles
134
- };
135
- }
136
-
137
- /**
138
- * Generate refactoring summary
139
- */
140
- generateRefactoringSummary(refactoringData) {
141
- const operations = refactoringData.operations || [];
142
- const successful = operations.filter(op => op.status === 'success').length;
143
- const failed = operations.filter(op => op.status === 'failed').length;
144
- const skipped = operations.filter(op => op.status === 'skipped').length;
145
-
146
- return {
147
- totalOperations: operations.length,
148
- successful,
149
- failed,
150
- skipped,
151
- successRate: operations.length > 0 ? (successful / operations.length * 100).toFixed(1) : 0,
152
- filesProcessed: refactoringData.filesProcessed || 0,
153
- linesReduced: refactoringData.linesReduced || 0,
154
- modulesCreated: refactoringData.modulesCreated || 0
155
- };
156
- }
157
-
158
- /**
159
- * Generate validation summary
160
- */
161
- generateValidationSummary(validationData) {
162
- const results = validationData.results || [];
163
- const errors = results.filter(r => r.severity === 'error').length;
164
- const warnings = results.filter(r => r.severity === 'warning').length;
165
- const info = results.filter(r => r.severity === 'info').length;
166
-
167
- return {
168
- totalIssues: results.length,
169
- errors,
170
- warnings,
171
- info,
172
- filesValidated: validationData.filesValidated || 0,
173
- passed: errors === 0
174
- };
175
- }
176
-
177
- /**
178
- * Generate compliance summary
179
- */
180
- generateComplianceSummary(complianceData) {
181
- const metrics = complianceData.metrics || {};
182
-
183
- return {
184
- overallScore: metrics.overallScore || 0,
185
- fileComplianceRate: metrics.fileComplianceRate || 0,
186
- lineComplianceRate: metrics.lineComplianceRate || 0,
187
- violationCount: metrics.violationCount || 0,
188
- lastChecked: metrics.lastChecked || new Date().toISOString(),
189
- status: metrics.status || 'unknown'
190
- };
191
- }
192
-
193
- /**
194
- * Generate recommendations
195
- */
196
- generateRecommendations(analysisData) {
197
- const recommendations = [];
198
- const files = analysisData.files || [];
199
-
200
- // Large file recommendations
201
- const largeFiles = files.filter(f => f.lineCount > 555);
202
- if (largeFiles.length > 0) {
203
- recommendations.push({
204
- type: 'urgent',
205
- title: `Refactor ${largeFiles.length} Large Files`,
206
- description: `${largeFiles.length} files exceed the 555-line limit and require immediate refactoring.`,
207
- files: largeFiles.map(f => f.path),
208
- priority: 'high'
209
- });
210
- }
211
-
212
- // Medium file recommendations
213
- const mediumFiles = files.filter(f => f.lineCount > 300 && f.lineCount <= 555);
214
- if (mediumFiles.length > 0) {
215
- recommendations.push({
216
- type: 'planning',
217
- title: `Plan Refactoring for ${mediumFiles.length} Medium Files`,
218
- description: `${mediumFiles.length} files are approaching the size limit and should be planned for refactoring.`,
219
- files: mediumFiles.map(f => f.path),
220
- priority: 'medium'
221
- });
222
- }
223
-
224
- // Package-specific recommendations
225
- const packageStats = this.analyzePackageStats(files);
226
- for (const [pkg, stats] of Object.entries(packageStats)) {
227
- if (stats.complianceRate < 80) {
228
- recommendations.push({
229
- type: 'package',
230
- title: `Improve ${pkg} Package Compliance`,
231
- description: `Package ${pkg} has ${stats.complianceRate}% compliance rate and needs attention.`,
232
- files: stats.files,
233
- priority: 'medium'
234
- });
235
- }
236
- }
237
-
238
- return recommendations;
239
- }
240
-
241
- /**
242
- * Generate statistics
243
- */
244
- generateStatistics(analysisData) {
245
- const files = analysisData.files || [];
246
-
247
- return {
248
- fileSizes: this.calculateSizeDistribution(files),
249
- packageStats: this.analyzePackageStats(files),
250
- fileTypeStats: this.analyzeFileTypeStats(files),
251
- complexityMetrics: this.calculateComplexityMetrics(files)
252
- };
253
- }
254
-
255
- /**
256
- * Calculate size distribution
257
- */
258
- calculateSizeDistribution(files) {
259
- const distribution = {
260
- '0-100': 0,
261
- '101-200': 0,
262
- '201-300': 0,
263
- '301-400': 0,
264
- '401-500': 0,
265
- '501-555': 0,
266
- '556+': 0
267
- };
268
-
269
- for (const file of files) {
270
- const lines = file.lineCount;
271
- if (lines <= 100) distribution['0-100']++;
272
- else if (lines <= 200) distribution['101-200']++;
273
- else if (lines <= 300) distribution['201-300']++;
274
- else if (lines <= 400) distribution['301-400']++;
275
- else if (lines <= 500) distribution['401-500']++;
276
- else if (lines <= 555) distribution['501-555']++;
277
- else distribution['556+']++;
278
- }
279
-
280
- return distribution;
281
- }
282
-
283
- /**
284
- * Analyze package statistics
285
- */
286
- analyzePackageStats(files) {
287
- const packageStats = {};
288
-
289
- for (const file of files) {
290
- const pkg = this.extractPackageFromPath(file.path);
291
- if (!packageStats[pkg]) {
292
- packageStats[pkg] = {
293
- totalFiles: 0,
294
- totalLines: 0,
295
- compliantFiles: 0,
296
- files: []
297
- };
298
- }
299
-
300
- packageStats[pkg].totalFiles++;
301
- packageStats[pkg].totalLines += file.lineCount;
302
- packageStats[pkg].files.push(file.path);
303
-
304
- if (file.lineCount <= 555) {
305
- packageStats[pkg].compliantFiles++;
306
- }
307
- }
308
-
309
- // Calculate compliance rates
310
- for (const stats of Object.values(packageStats)) {
311
- stats.complianceRate = stats.totalFiles > 0
312
- ? (stats.compliantFiles / stats.totalFiles * 100).toFixed(1)
313
- : 0;
314
- stats.averageLines = stats.totalFiles > 0
315
- ? Math.round(stats.totalLines / stats.totalFiles)
316
- : 0;
317
- }
318
-
319
- return packageStats;
320
- }
321
-
322
- /**
323
- * Analyze file type statistics
324
- */
325
- analyzeFileTypeStats(files) {
326
- const typeStats = {};
327
-
328
- for (const file of files) {
329
- const ext = path.extname(file.path);
330
- if (!typeStats[ext]) {
331
- typeStats[ext] = {
332
- count: 0,
333
- totalLines: 0,
334
- averageLines: 0
335
- };
336
- }
337
-
338
- typeStats[ext].count++;
339
- typeStats[ext].totalLines += file.lineCount;
340
- }
341
-
342
- // Calculate averages
343
- for (const stats of Object.values(typeStats)) {
344
- stats.averageLines = stats.count > 0
345
- ? Math.round(stats.totalLines / stats.count)
346
- : 0;
347
- }
348
-
349
- return typeStats;
350
- }
351
-
352
- /**
353
- * Calculate complexity metrics (simplified)
354
- */
355
- calculateComplexityMetrics(files) {
356
- return {
357
- totalComplexity: 0,
358
- averageComplexity: 0,
359
- complexityDistribution: {
360
- low: 0,
361
- medium: 0,
362
- high: 0,
363
- veryHigh: 0
364
- }
365
- };
366
- }
367
-
368
- /**
369
- * Generate compliance metrics
370
- */
371
- generateComplianceMetrics(validationData) {
372
- const results = validationData.results || [];
373
- const filesValidated = validationData.filesValidated || 0;
374
-
375
- const errorCount = results.filter(r => r.severity === 'error').length;
376
- const warningCount = results.filter(r => r.severity === 'warning').length;
377
-
378
- return {
379
- overallScore: filesValidated > 0 ? Math.max(0, 100 - (errorCount * 10 + warningCount * 2)) : 0,
380
- fileComplianceRate: filesValidated > 0 ? ((filesValidated - errorCount) / filesValidated * 100) : 0,
381
- lineComplianceRate: 0, // Would need line-level analysis
382
- violationCount: errorCount,
383
- lastChecked: new Date().toISOString(),
384
- status: errorCount === 0 ? 'compliant' : warningCount > 0 ? 'warning' : 'non-compliant'
385
- };
386
- }
387
-
388
- /**
389
- * Output report in specified format
390
- */
391
- outputReport(format, outputPath) {
392
- switch (format) {
393
- case OUTPUT_FORMATS.JSON:
394
- return this.outputJSON(outputPath);
395
- case OUTPUT_FORMATS.MARKDOWN:
396
- return this.outputMarkdown(outputPath);
397
- case OUTPUT_FORMATS.CONSOLE:
398
- return this.outputConsole();
399
- case OUTPUT_FORMATS.HTML:
400
- return this.outputHTML(outputPath);
401
- default:
402
- throw new Error(`Unsupported output format: ${format}`);
403
- }
404
- }
405
-
406
- /**
407
- * Output JSON format
408
- */
409
- outputJSON(outputPath) {
410
- const json = JSON.stringify(this.reportData, null, 2);
411
-
412
- if (outputPath) {
413
- fs.writeFileSync(outputPath, json, 'utf8');
414
- return { success: true, path: outputPath, format: 'json' };
415
- }
416
-
417
- return { success: true, content: json, format: 'json' };
418
- }
419
-
420
- /**
421
- * Output Markdown format
422
- */
423
- outputMarkdown(outputPath) {
424
- const markdown = this.generateMarkdownReport();
425
-
426
- if (outputPath) {
427
- fs.writeFileSync(outputPath, markdown, 'utf8');
428
- return { success: true, path: outputPath, format: 'markdown' };
429
- }
430
-
431
- return { success: true, content: markdown, format: 'markdown' };
432
- }
433
-
434
- /**
435
- * Output console format
436
- */
437
- outputConsole() {
438
- const consoleOutput = this.generateConsoleReport();
439
- console.log(consoleOutput);
440
- return { success: true, content: consoleOutput, format: 'console' };
441
- }
442
-
443
- /**
444
- * Output HTML format
445
- */
446
- outputHTML(outputPath) {
447
- const html = this.generateHTMLReport();
448
-
449
- if (outputPath) {
450
- fs.writeFileSync(outputPath, html, 'utf8');
451
- return { success: true, path: outputPath, format: 'html' };
452
- }
453
-
454
- return { success: true, content: html, format: 'html' };
455
- }
456
-
457
- /**
458
- * Generate Markdown report
459
- */
460
- generateMarkdownReport() {
461
- const data = this.reportData;
462
- let markdown = `# ${data.type.charAt(0).toUpperCase() + data.type.slice(1)} Report\n\n`;
463
-
464
- // Metadata
465
- markdown += `**Generated:** ${new Date(data.metadata.generatedAt).toLocaleString()}\n`;
466
- markdown += `**Version:** ${data.metadata.version}\n\n`;
467
-
468
- // Summary
469
- if (data.summary) {
470
- markdown += `## Summary\n\n`;
471
- for (const [key, value] of Object.entries(data.summary)) {
472
- markdown += `- **${key}:** ${value}\n`;
473
- }
474
- markdown += `\n`;
475
- }
476
-
477
- // Recommendations
478
- if (data.recommendations && data.recommendations.length > 0) {
479
- markdown += `## Recommendations\n\n`;
480
- for (const rec of data.recommendations) {
481
- markdown += `### ${rec.title} (${rec.priority})\n`;
482
- markdown += `${rec.description}\n\n`;
483
- if (rec.files && rec.files.length > 0) {
484
- markdown += `**Files:**\n`;
485
- for (const file of rec.files) {
486
- markdown += `- \`${file}\`\n`;
487
- }
488
- markdown += `\n`;
489
- }
490
- }
491
- }
492
-
493
- return markdown;
494
- }
495
-
496
- /**
497
- * Generate console report
498
- */
499
- generateConsoleReport() {
500
- const data = this.reportData;
501
- let output = `\n=== ${data.type.toUpperCase()} REPORT ===\n\n`;
502
-
503
- // Summary
504
- if (data.summary) {
505
- output += "SUMMARY:\n";
506
- for (const [key, value] of Object.entries(data.summary)) {
507
- output += ` ${key}: ${value}\n`;
508
- }
509
- output += "\n";
510
- }
511
-
512
- return output;
513
- }
514
-
515
- /**
516
- * Generate HTML report
517
- */
518
- generateHTMLReport() {
519
- const data = this.reportData;
520
-
521
- return `
522
- <!DOCTYPE html>
523
- <html>
524
- <head>
525
- <title>${data.type} Report</title>
526
- <style>
527
- body { font-family: Arial, sans-serif; margin: 20px; }
528
- .header { background: #f5f5f5; padding: 20px; border-radius: 5px; }
529
- .summary { margin: 20px 0; }
530
- .metric { display: inline-block; margin: 10px; padding: 10px; background: #e9ecef; border-radius: 3px; }
531
- table { border-collapse: collapse; width: 100%; }
532
- th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
533
- th { background-color: #f2f2f2; }
534
- </style>
535
- </head>
536
- <body>
537
- <div class="header">
538
- <h1>${data.type} Report</h1>
539
- <p>Generated: ${new Date(data.metadata.generatedAt).toLocaleString()}</p>
540
- </div>
541
-
542
- <div class="summary">
543
- <h2>Summary</h2>
544
- ${Object.entries(data.summary || {}).map(([key, value]) =>
545
- `<div class="metric"><strong>${key}:</strong> ${value}</div>`
546
- ).join('')}
547
- </div>
548
-
549
- <script>
550
- // Add interactive features here if needed
551
- </script>
552
- </body>
553
- </html>`;
554
- }
555
-
556
- /**
557
- * Extract package name from file path
558
- */
559
- extractPackageFromPath(filePath) {
560
- const match = filePath.match(/packages\/([^\/]+)/);
561
- return match ? match[1] : 'root';
64
+ const reportData = this.complianceGenerator.generate(complianceData);
65
+ return FormatHandler.output(reportData, options.format || OUTPUT_FORMATS.JSON, options.outputPath);
562
66
  }
563
67
  }
564
68