vibecodingmachine-core 2026.2.20-438 → 2026.2.26-1739

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 (202) hide show
  1. package/README.md +240 -0
  2. package/package.json +10 -2
  3. package/src/agents/Agent.js +300 -0
  4. package/src/agents/AgentAdditionService.js +311 -0
  5. package/src/agents/AgentCheckService.js +690 -0
  6. package/src/agents/AgentInstallationService.js +140 -0
  7. package/src/agents/AgentSetupService.js +467 -0
  8. package/src/agents/AgentStatus.js +183 -0
  9. package/src/agents/AgentVerificationService.js +634 -0
  10. package/src/agents/ConfigurationSchemaValidator.js +543 -0
  11. package/src/agents/EnvironmentConfigurationManager.js +602 -0
  12. package/src/agents/InstallationErrorHandler.js +372 -0
  13. package/src/agents/InstallationLog.js +363 -0
  14. package/src/agents/InstallationMethod.js +510 -0
  15. package/src/agents/InstallationOrchestrator.js +352 -0
  16. package/src/agents/InstallationProgressReporter.js +372 -0
  17. package/src/agents/InstallationRetryManager.js +322 -0
  18. package/src/agents/InstallationType.js +254 -0
  19. package/src/agents/OperationTypes.js +310 -0
  20. package/src/agents/PerformanceMetricsCollector.js +493 -0
  21. package/src/agents/SecurityValidationService.js +534 -0
  22. package/src/agents/VerificationTest.js +354 -0
  23. package/src/agents/VerificationType.js +226 -0
  24. package/src/agents/WindowsPermissionHandler.js +518 -0
  25. package/src/agents/config/AgentConfigManager.js +393 -0
  26. package/src/agents/config/AgentDefaultsRegistry.js +373 -0
  27. package/src/agents/config/ConfigValidator.js +281 -0
  28. package/src/agents/discovery/AgentDiscoveryService.js +707 -0
  29. package/src/agents/logging/AgentLogger.js +511 -0
  30. package/src/agents/status/AgentStatusManager.js +481 -0
  31. package/src/agents/storage/FileManager.js +454 -0
  32. package/src/agents/verification/AgentCommunicationTester.js +474 -0
  33. package/src/agents/verification/BaseVerifier.js +430 -0
  34. package/src/agents/verification/CommandVerifier.js +480 -0
  35. package/src/agents/verification/FileOperationVerifier.js +453 -0
  36. package/src/agents/verification/ResultAnalyzer.js +707 -0
  37. package/src/agents/verification/TestRequirementManager.js +495 -0
  38. package/src/agents/verification/VerificationRunner.js +433 -0
  39. package/src/agents/windows/BaseWindowsInstaller.js +441 -0
  40. package/src/agents/windows/ChocolateyInstaller.js +509 -0
  41. package/src/agents/windows/DirectInstaller.js +443 -0
  42. package/src/agents/windows/InstallerFactory.js +391 -0
  43. package/src/agents/windows/NpmInstaller.js +505 -0
  44. package/src/agents/windows/PowerShellInstaller.js +458 -0
  45. package/src/agents/windows/WinGetInstaller.js +390 -0
  46. package/src/analysis/analysis-reporter.js +132 -0
  47. package/src/analysis/boundary-detector.js +712 -0
  48. package/src/analysis/categorizer.js +340 -0
  49. package/src/analysis/codebase-scanner.js +384 -0
  50. package/src/analysis/line-counter.js +513 -0
  51. package/src/analysis/priority-calculator.js +679 -0
  52. package/src/analysis/report/analysis-report.js +250 -0
  53. package/src/analysis/report/package-analyzer.js +278 -0
  54. package/src/analysis/report/recommendation-generator.js +382 -0
  55. package/src/analysis/report/statistics-generator.js +515 -0
  56. package/src/analysis/reports/analysis-report-model.js +101 -0
  57. package/src/analysis/reports/recommendation-generator.js +283 -0
  58. package/src/analysis/reports/report-generators.js +191 -0
  59. package/src/analysis/reports/statistics-calculator.js +231 -0
  60. package/src/analysis/reports/trend-analyzer.js +219 -0
  61. package/src/analysis/strategy-generator.js +814 -0
  62. package/src/auto-mode/AutoModeBusinessLogic.js +836 -0
  63. package/src/config/refactoring-config.js +307 -0
  64. package/src/health-tracking/json-storage.js +38 -2
  65. package/src/ide-integration/applescript-manager-core.js +233 -0
  66. package/src/ide-integration/applescript-manager.cjs +357 -28
  67. package/src/ide-integration/applescript-manager.js +89 -3599
  68. package/src/ide-integration/cdp-manager.js +306 -0
  69. package/src/ide-integration/claude-code-cli-manager.cjs +1 -1
  70. package/src/ide-integration/continuation-handler.js +337 -0
  71. package/src/ide-integration/ide-status-checker.js +292 -0
  72. package/src/ide-integration/macos-ide-manager.js +627 -0
  73. package/src/ide-integration/macos-text-sender.js +528 -0
  74. package/src/ide-integration/response-reader.js +548 -0
  75. package/src/ide-integration/windows-automation-manager.js +121 -0
  76. package/src/ide-integration/windows-ide-manager.js +373 -0
  77. package/src/index.cjs +25 -3
  78. package/src/index.js +15 -1
  79. package/src/llm/direct-llm-manager.cjs +90 -2
  80. package/src/models/compliance-report.js +538 -0
  81. package/src/models/file-analysis.js +681 -0
  82. package/src/models/refactoring-plan.js +770 -0
  83. package/src/monitoring/alert-system.js +834 -0
  84. package/src/monitoring/compliance-progress-tracker.js +437 -0
  85. package/src/monitoring/continuous-scan-notifications.js +661 -0
  86. package/src/monitoring/continuous-scanner.js +279 -0
  87. package/src/monitoring/file-monitor/file-analyzer.js +262 -0
  88. package/src/monitoring/file-monitor/file-monitor.js +237 -0
  89. package/src/monitoring/file-monitor/watcher.js +194 -0
  90. package/src/monitoring/file-monitor.js +17 -0
  91. package/src/monitoring/notification-manager.js +437 -0
  92. package/src/monitoring/scanner-core.js +368 -0
  93. package/src/monitoring/scanner-events.js +214 -0
  94. package/src/monitoring/violation-notification-system.js +515 -0
  95. package/src/refactoring/boundaries/cohesion-analyzer.js +316 -0
  96. package/src/refactoring/boundaries/extraction-result.js +285 -0
  97. package/src/refactoring/boundaries/extraction-strategies.js +392 -0
  98. package/src/refactoring/boundaries/module-boundary.js +209 -0
  99. package/src/refactoring/boundary/boundary-detector.js +741 -0
  100. package/src/refactoring/boundary/boundary-types.js +405 -0
  101. package/src/refactoring/boundary/extraction-strategies.js +554 -0
  102. package/src/refactoring/boundary-extraction-result.js +77 -0
  103. package/src/refactoring/boundary-extraction-strategies.js +330 -0
  104. package/src/refactoring/boundary-extractor.js +384 -0
  105. package/src/refactoring/boundary-types.js +46 -0
  106. package/src/refactoring/circular/circular-dependency.js +88 -0
  107. package/src/refactoring/circular/cycle-detection.js +147 -0
  108. package/src/refactoring/circular/dependency-node.js +82 -0
  109. package/src/refactoring/circular/dependency-result.js +107 -0
  110. package/src/refactoring/circular/dependency-types.js +58 -0
  111. package/src/refactoring/circular/graph-builder.js +213 -0
  112. package/src/refactoring/circular/resolution-strategy.js +72 -0
  113. package/src/refactoring/circular/strategy-generator.js +229 -0
  114. package/src/refactoring/circular-dependency-resolver-original.js +809 -0
  115. package/src/refactoring/circular-dependency-resolver.js +200 -0
  116. package/src/refactoring/code-mover.js +761 -0
  117. package/src/refactoring/file-splitter.js +696 -0
  118. package/src/refactoring/functionality-validator.js +816 -0
  119. package/src/refactoring/import-manager.js +774 -0
  120. package/src/refactoring/module-boundary.js +107 -0
  121. package/src/refactoring/refactoring-executor.js +672 -0
  122. package/src/refactoring/refactoring-rollback.js +614 -0
  123. package/src/refactoring/test-validator.js +631 -0
  124. package/src/requirement-management/default-requirement-manager.js +321 -0
  125. package/src/requirement-management/requirement-file-parser.js +159 -0
  126. package/src/requirement-management/requirement-sequencer.js +221 -0
  127. package/src/rui/commands/AgentCommandParser.js +600 -0
  128. package/src/rui/commands/AgentCommands.js +487 -0
  129. package/src/rui/commands/AgentResponseFormatter.js +832 -0
  130. package/src/scripts/verify-full-compliance.js +269 -0
  131. package/src/sync/sync-engine-core.js +1 -0
  132. package/src/sync/sync-engine-remote-handlers.js +135 -0
  133. package/src/task-generation/automated-task-generator.js +351 -0
  134. package/src/task-generation/prioritizer.js +287 -0
  135. package/src/task-generation/task-list-updater.js +215 -0
  136. package/src/task-generation/task-management-integration.js +480 -0
  137. package/src/task-generation/task-manager-integration.js +270 -0
  138. package/src/task-generation/violation-task-generator.js +474 -0
  139. package/src/task-management/continuous-scan-integration.js +342 -0
  140. package/src/timeout-management/index.js +12 -3
  141. package/src/timeout-management/response-time-tracker.js +167 -0
  142. package/src/timeout-management/timeout-calculator.js +159 -0
  143. package/src/timeout-management/timeout-config-manager.js +172 -0
  144. package/src/utils/ast-analyzer.js +417 -0
  145. package/src/utils/current-requirement-manager.js +276 -0
  146. package/src/utils/current-requirement-operations.js +472 -0
  147. package/src/utils/dependency-mapper.js +456 -0
  148. package/src/utils/download-with-progress.js +4 -2
  149. package/src/utils/electron-update-checker.js +4 -1
  150. package/src/utils/file-size-analyzer.js +272 -0
  151. package/src/utils/import-updater.js +280 -0
  152. package/src/utils/refactoring-tools.js +512 -0
  153. package/src/utils/report-generator.js +569 -0
  154. package/src/utils/reports/report-analysis.js +218 -0
  155. package/src/utils/reports/report-types.js +55 -0
  156. package/src/utils/reports/summary-generators.js +102 -0
  157. package/src/utils/requirement-file-management.js +157 -0
  158. package/src/utils/requirement-helpers/requirement-file-ops.js +392 -0
  159. package/src/utils/requirement-helpers/requirement-mover.js +414 -0
  160. package/src/utils/requirement-helpers/requirement-parser.js +326 -0
  161. package/src/utils/requirement-helpers/requirement-status.js +320 -0
  162. package/src/utils/requirement-helpers-new.js +55 -0
  163. package/src/utils/requirement-helpers-refactored.js +367 -0
  164. package/src/utils/requirement-helpers.js +291 -1191
  165. package/src/utils/requirement-movement-operations.js +450 -0
  166. package/src/utils/requirement-movement.js +312 -0
  167. package/src/utils/requirement-parsing-helpers.js +56 -0
  168. package/src/utils/requirement-statistics.js +200 -0
  169. package/src/utils/requirement-text-utils.js +58 -0
  170. package/src/utils/rollback/rollback-handlers.js +125 -0
  171. package/src/utils/rollback/rollback-operation.js +63 -0
  172. package/src/utils/rollback/rollback-recorder.js +166 -0
  173. package/src/utils/rollback/rollback-state-manager.js +175 -0
  174. package/src/utils/rollback/rollback-types.js +33 -0
  175. package/src/utils/rollback/rollback-utils.js +110 -0
  176. package/src/utils/rollback-manager-original.js +569 -0
  177. package/src/utils/rollback-manager.js +202 -0
  178. package/src/utils/smoke-test-cli.js +362 -0
  179. package/src/utils/smoke-test-gui.js +351 -0
  180. package/src/utils/smoke-test-orchestrator.js +321 -0
  181. package/src/utils/smoke-test-runner.js +60 -0
  182. package/src/utils/smoke-test-web.js +347 -0
  183. package/src/utils/specification-helpers.js +39 -13
  184. package/src/utils/specification-migration.js +97 -0
  185. package/src/utils/test-runner.js +579 -0
  186. package/src/utils/validation-framework.js +518 -0
  187. package/src/validation/compliance-analyzer.js +197 -0
  188. package/src/validation/compliance-report-generator.js +343 -0
  189. package/src/validation/compliance-reporter.js +711 -0
  190. package/src/validation/compliance-rules.js +127 -0
  191. package/src/validation/constitution-validator-new.js +196 -0
  192. package/src/validation/constitution-validator.js +17 -0
  193. package/src/validation/file-validators.js +170 -0
  194. package/src/validation/line-limit/file-analyzer.js +201 -0
  195. package/src/validation/line-limit/line-limit-validator.js +208 -0
  196. package/src/validation/line-limit/validation-result.js +144 -0
  197. package/src/validation/line-limit-core.js +225 -0
  198. package/src/validation/line-limit-reporter.js +134 -0
  199. package/src/validation/line-limit-result.js +125 -0
  200. package/src/validation/line-limit-validator.js +41 -0
  201. package/src/validation/metrics-calculator.js +660 -0
  202. package/src/sync/sync-engine-backup.js +0 -559
@@ -0,0 +1,711 @@
1
+ /**
2
+ * Compliance Report Generator
3
+ *
4
+ * Generates comprehensive compliance reports in various formats,
5
+ * integrating validation results, metrics, and recommendations.
6
+ */
7
+
8
+ const fs = require('fs');
9
+ const path = require('path');
10
+ const { ComplianceReport, FileComplianceSummary, ComplianceIssue } = require('../models/compliance-report');
11
+ const MetricsCalculator = require('./metrics-calculator');
12
+ const ReportGenerator = require('../utils/report-generator');
13
+
14
+ /**
15
+ * Report generator class
16
+ */
17
+ class ComplianceReporter {
18
+ constructor(options = {}) {
19
+ this.options = {
20
+ outputDir: options.outputDir || './reports',
21
+ formats: options.formats || ['json', 'html', 'markdown'],
22
+ includeMetrics: options.includeMetrics !== false,
23
+ includeRecommendations: options.includeRecommendations !== false,
24
+ includeCharts: options.includeCharts !== false,
25
+ ...options
26
+ };
27
+
28
+ this.metricsCalculator = new MetricsCalculator();
29
+ this.reportGenerator = ReportGenerator || this.createFallbackReportGenerator();
30
+ }
31
+
32
+ /**
33
+ * Generate comprehensive compliance report
34
+ */
35
+ async generateReport(validationResults, options = {}) {
36
+ const reportOptions = { ...this.options, ...options };
37
+
38
+ try {
39
+ // Create compliance report
40
+ const complianceReport = this.createComplianceReport(validationResults, reportOptions);
41
+
42
+ // Calculate metrics if enabled
43
+ if (reportOptions.includeMetrics) {
44
+ complianceReport.metrics = this.metricsCalculator.calculateMetrics(complianceReport);
45
+ }
46
+
47
+ // Generate reports in requested formats
48
+ const generatedReports = await this.generateReportsInFormats(complianceReport, reportOptions);
49
+
50
+ return {
51
+ report: complianceReport,
52
+ files: generatedReports,
53
+ summary: this.generateReportSummary(complianceReport, generatedReports)
54
+ };
55
+
56
+ } catch (error) {
57
+ throw new Error(`Failed to generate compliance report: ${error.message}`);
58
+ }
59
+ }
60
+
61
+ /**
62
+ * Create compliance report from validation results
63
+ */
64
+ createComplianceReport(validationResults, options) {
65
+ const report = new ComplianceReport({
66
+ title: options.title || 'Codebase Compliance Report',
67
+ description: options.description || 'Comprehensive analysis of codebase compliance with constitutional requirements',
68
+ scope: options.scope || 'full',
69
+ scopePath: options.scopePath || process.cwd(),
70
+ generatedAt: new Date().toISOString()
71
+ });
72
+
73
+ // Process validation results
74
+ for (const validationResult of validationResults) {
75
+ const fileSummary = this.createFileSummary(validationResult);
76
+ report.addFileSummary(fileSummary);
77
+ }
78
+
79
+ return report;
80
+ }
81
+
82
+ /**
83
+ * Create file summary from validation result
84
+ */
85
+ createFileSummary(validationResult) {
86
+ const fileSummary = new FileComplianceSummary({
87
+ filePath: validationResult.filePath,
88
+ lineCount: validationResult.lineCount || 0,
89
+ fileSize: validationResult.fileSize || 0
90
+ });
91
+
92
+ // Add issues from validation result
93
+ if (validationResult.issues) {
94
+ for (const issue of validationResult.issues) {
95
+ fileSummary.addIssue(new ComplianceIssue({
96
+ filePath: validationResult.filePath,
97
+ ...issue
98
+ }));
99
+ }
100
+ }
101
+
102
+ // Add line limit violations
103
+ if (validationResult.lineLimitViolation) {
104
+ fileSummary.addIssue(new ComplianceIssue({
105
+ filePath: validationResult.filePath,
106
+ category: 'file_size',
107
+ severity: validationResult.lineLimitViolation.severity || 'error',
108
+ rule: 'file_size_limit',
109
+ message: validationResult.lineLimitViolation.message,
110
+ description: `File exceeds 555-line limit with ${validationResult.lineCount} lines`,
111
+ suggestion: 'Refactor file into smaller modules',
112
+ lineNumber: null
113
+ }));
114
+ }
115
+
116
+ return fileSummary;
117
+ }
118
+
119
+ /**
120
+ * Generate reports in multiple formats
121
+ */
122
+ async generateReportsInFormats(complianceReport, options) {
123
+ const generatedFiles = [];
124
+ const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
125
+ const baseName = `compliance-report-${timestamp}`;
126
+
127
+ // Ensure output directory exists
128
+ if (!fs.existsSync(options.outputDir)) {
129
+ fs.mkdirSync(options.outputDir, { recursive: true });
130
+ }
131
+
132
+ for (const format of options.formats) {
133
+ try {
134
+ const fileName = `${baseName}.${format}`;
135
+ const filePath = path.join(options.outputDir, fileName);
136
+
137
+ await this.generateReportInFormat(complianceReport, format, filePath, options);
138
+
139
+ generatedFiles.push({
140
+ format,
141
+ fileName,
142
+ filePath,
143
+ size: fs.statSync(filePath).size
144
+ });
145
+
146
+ } catch (error) {
147
+ console.warn(`Failed to generate ${format} report: ${error.message}`);
148
+ }
149
+ }
150
+
151
+ return generatedFiles;
152
+ }
153
+
154
+ /**
155
+ * Generate report in specific format
156
+ */
157
+ async generateReportInFormat(complianceReport, format, filePath, options) {
158
+ switch (format.toLowerCase()) {
159
+ case 'json':
160
+ await this.generateJsonReport(complianceReport, filePath, options);
161
+ break;
162
+ case 'html':
163
+ await this.generateHtmlReport(complianceReport, filePath, options);
164
+ break;
165
+ case 'markdown':
166
+ await this.generateMarkdownReport(complianceReport, filePath, options);
167
+ break;
168
+ case 'csv':
169
+ await this.generateCsvReport(complianceReport, filePath, options);
170
+ break;
171
+ case 'pdf':
172
+ await this.generatePdfReport(complianceReport, filePath, options);
173
+ break;
174
+ default:
175
+ throw new Error(`Unsupported report format: ${format}`);
176
+ }
177
+ }
178
+
179
+ /**
180
+ * Generate JSON report
181
+ */
182
+ async generateJsonReport(complianceReport, filePath, options) {
183
+ const reportData = {
184
+ metadata: {
185
+ generatedAt: complianceReport.generatedAt,
186
+ generator: 'ComplianceReporter',
187
+ version: '1.0.0',
188
+ options: options
189
+ },
190
+ report: complianceReport.toJSON()
191
+ };
192
+
193
+ fs.writeFileSync(filePath, JSON.stringify(reportData, null, 2), 'utf8');
194
+ }
195
+
196
+ /**
197
+ * Generate HTML report
198
+ */
199
+ async generateHtmlReport(complianceReport, filePath, options) {
200
+ const html = this.generateHtmlContent(complianceReport, options);
201
+ fs.writeFileSync(filePath, html, 'utf8');
202
+ }
203
+
204
+ /**
205
+ * Generate Markdown report
206
+ */
207
+ async generateMarkdownReport(complianceReport, filePath, options) {
208
+ const markdown = complianceReport.generateDetailedReport();
209
+ fs.writeFileSync(filePath, markdown, 'utf8');
210
+ }
211
+
212
+ /**
213
+ * Generate CSV report
214
+ */
215
+ async generateCsvReport(complianceReport, filePath, options) {
216
+ let csv = 'File Path,Line Count,Status,Compliance Score,Total Issues,Critical Issues,Violation Issues,Warning Issues\n';
217
+
218
+ for (const fileSummary of complianceReport.fileSummaries) {
219
+ csv += `"${fileSummary.filePath}",${fileSummary.lineCount},${fileSummary.status},${fileSummary.complianceScore},${fileSummary.totalIssues},${fileSummary.criticalIssues},${fileSummary.violationIssues},${fileSummary.warningIssues}\n`;
220
+ }
221
+
222
+ fs.writeFileSync(filePath, csv, 'utf8');
223
+ }
224
+
225
+ /**
226
+ * Generate PDF report (placeholder implementation)
227
+ */
228
+ async generatePdfReport(complianceReport, filePath, options) {
229
+ // This would typically use a PDF generation library
230
+ // For now, generate a text file as placeholder
231
+ const text = complianceReport.generateDetailedReport();
232
+ fs.writeFileSync(filePath.replace('.pdf', '.txt'), text, 'utf8');
233
+ }
234
+
235
+ /**
236
+ * Generate HTML content
237
+ */
238
+ generateHtmlContent(complianceReport, options) {
239
+ const summary = complianceReport.summary;
240
+ const metrics = complianceReport.metrics;
241
+
242
+ let html = `
243
+ <!DOCTYPE html>
244
+ <html lang="en">
245
+ <head>
246
+ <meta charset="UTF-8">
247
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
248
+ <title>${complianceReport.title}</title>
249
+ <style>
250
+ body { font-family: Arial, sans-serif; margin: 20px; line-height: 1.6; }
251
+ .header { background: #f4f4f4; padding: 20px; border-radius: 5px; margin-bottom: 20px; }
252
+ .summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; margin-bottom: 30px; }
253
+ .metric { background: #f9f9f9; padding: 15px; border-radius: 5px; text-align: center; }
254
+ .metric h3 { margin: 0 0 10px 0; color: #333; }
255
+ .metric .value { font-size: 2em; font-weight: bold; margin: 10px 0; }
256
+ .compliant { color: #28a745; }
257
+ .warning { color: #ffc107; }
258
+ .violation { color: #dc3545; }
259
+ .critical { color: #6f42c1; }
260
+ table { width: 100%; border-collapse: collapse; margin-bottom: 20px; }
261
+ th, td { padding: 10px; text-align: left; border-bottom: 1px solid #ddd; }
262
+ th { background: #f4f4f4; }
263
+ .status-icon { margin-right: 5px; }
264
+ .recommendations { background: #e7f3ff; padding: 15px; border-radius: 5px; margin-top: 20px; }
265
+ .chart { margin: 20px 0; text-align: center; }
266
+ </style>
267
+ </head>
268
+ <body>
269
+ <div class="header">
270
+ <h1>${complianceReport.title}</h1>
271
+ <p><strong>Generated:</strong> ${new Date(complianceReport.generatedAt).toLocaleString()}</p>
272
+ <p><strong>Scope:</strong> ${complianceReport.scope} (${complianceReport.scopePath})</p>
273
+ <p><strong>Overall Compliance Score:</strong> <span class="value ${this.getScoreClass(summary.overallComplianceScore)}">${summary.overallComplianceScore.toFixed(1)}%</span></p>
274
+ </div>
275
+
276
+ <div class="summary">
277
+ <div class="metric">
278
+ <h3>Total Files</h3>
279
+ <div class="value">${summary.totalFiles}</div>
280
+ </div>
281
+ <div class="metric">
282
+ <h3>Compliant Files</h3>
283
+ <div class="value compliant">${summary.compliantFiles}</div>
284
+ </div>
285
+ <div class="metric">
286
+ <h3>Warning Files</h3>
287
+ <div class="value warning">${summary.warningFiles}</div>
288
+ </div>
289
+ <div class="metric">
290
+ <h3>Violation Files</h3>
291
+ <div class="value violation">${summary.violationFiles}</div>
292
+ </div>
293
+ <div class="metric">
294
+ <h3>Critical Files</h3>
295
+ <div class="value critical">${summary.criticalFiles}</div>
296
+ </div>
297
+ <div class="metric">
298
+ <h3>Total Issues</h3>
299
+ <div class="value">${summary.totalIssues}</div>
300
+ </div>
301
+ </div>
302
+ `;
303
+
304
+ // Add metrics section if available
305
+ if (metrics) {
306
+ html += this.generateMetricsSection(metrics);
307
+ }
308
+
309
+ // Add file details table
310
+ html += `
311
+ <h2>File Details</h2>
312
+ <table>
313
+ <thead>
314
+ <tr>
315
+ <th>File</th>
316
+ <th>Lines</th>
317
+ <th>Status</th>
318
+ <th>Score</th>
319
+ <th>Issues</th>
320
+ <th>Details</th>
321
+ </tr>
322
+ </thead>
323
+ <tbody>
324
+ `;
325
+
326
+ for (const fileSummary of complianceReport.fileSummaries.sort((a, b) => b.lineCount - a.lineCount)) {
327
+ const statusIcon = this.getStatusIcon(fileSummary.status);
328
+ const statusClass = this.getScoreClass(fileSummary.complianceScore);
329
+
330
+ html += `
331
+ <tr>
332
+ <td><code>${fileSummary.filePath}</code></td>
333
+ <td>${fileSummary.lineCount}</td>
334
+ <td><span class="status-icon">${statusIcon}</span>${fileSummary.status}</td>
335
+ <td><span class="${statusClass}">${fileSummary.complianceScore.toFixed(1)}%</span></td>
336
+ <td>${fileSummary.totalIssues}</td>
337
+ <td>
338
+ ${fileSummary.criticalIssues > 0 ? `${fileSummary.criticalIssues} critical` : ''}
339
+ ${fileSummary.violationIssues > 0 ? `${fileSummary.violationIssues} violations` : ''}
340
+ ${fileSummary.warningIssues > 0 ? `${fileSummary.warningIssues} warnings` : ''}
341
+ </td>
342
+ </tr>
343
+ `;
344
+ }
345
+
346
+ html += `
347
+ </tbody>
348
+ </table>
349
+ `;
350
+
351
+ // Add recommendations
352
+ if (complianceReport.recommendations.length > 0) {
353
+ html += this.generateRecommendationsSection(complianceReport.recommendations);
354
+ }
355
+
356
+ html += `
357
+ </body>
358
+ </html>`;
359
+
360
+ return html;
361
+ }
362
+
363
+ /**
364
+ * Generate metrics section for HTML report
365
+ */
366
+ generateMetricsSection(metrics) {
367
+ let html = `
368
+ <h2>Metrics Analysis</h2>
369
+ <div class="summary">
370
+ `;
371
+
372
+ // Overview metrics
373
+ if (metrics.overview) {
374
+ html += `
375
+ <div class="metric">
376
+ <h3>Compliance Rate</h3>
377
+ <div class="value ${this.getScoreClass(metrics.overview.complianceRate)}">${metrics.overview.complianceRate.toFixed(1)}%</div>
378
+ </div>
379
+ <div class="metric">
380
+ <h3>Health Status</h3>
381
+ <div class="value">${metrics.overview.healthStatus}</div>
382
+ </div>
383
+ <div class="metric">
384
+ <h3>Avg Issues/File</h3>
385
+ <div class="value">${metrics.overview.averageIssuesPerFile.toFixed(1)}</div>
386
+ </div>
387
+ `;
388
+ }
389
+
390
+ html += `
391
+ </div>
392
+ `;
393
+
394
+ return html;
395
+ }
396
+
397
+ /**
398
+ * Generate recommendations section
399
+ */
400
+ generateRecommendationsSection(recommendations) {
401
+ let html = `
402
+ <div class="recommendations">
403
+ <h2>Recommendations</h2>
404
+ `;
405
+
406
+ for (const rec of recommendations) {
407
+ const priorityClass = rec.priority === 'critical' ? 'critical' :
408
+ rec.priority === 'high' ? 'violation' :
409
+ rec.priority === 'medium' ? 'warning' : 'compliant';
410
+
411
+ html += `
412
+ <div style="margin-bottom: 15px;">
413
+ <h3><span class="${priorityClass}">${rec.title}</span> (${rec.priority})</h3>
414
+ <p>${rec.description}</p>
415
+ <p><strong>Action:</strong> ${rec.action}</p>
416
+ </div>
417
+ `;
418
+ }
419
+
420
+ html += `
421
+ </div>
422
+ `;
423
+
424
+ return html;
425
+ }
426
+
427
+ /**
428
+ * Get status icon
429
+ */
430
+ getStatusIcon(status) {
431
+ const icons = {
432
+ compliant: '✅',
433
+ warning: '⚠️',
434
+ violation: '❌',
435
+ critical: '🚨'
436
+ };
437
+ return icons[status] || '❓';
438
+ }
439
+
440
+ /**
441
+ * Get score class for styling
442
+ */
443
+ getScoreClass(score) {
444
+ if (score >= 90) return 'compliant';
445
+ if (score >= 70) return 'warning';
446
+ if (score >= 50) return 'violation';
447
+ return 'critical';
448
+ }
449
+
450
+ /**
451
+ * Generate report summary
452
+ */
453
+ generateReportSummary(complianceReport, generatedFiles) {
454
+ return {
455
+ reportId: complianceReport.id,
456
+ generatedAt: complianceReport.generatedAt,
457
+ totalFiles: complianceReport.summary.totalFiles,
458
+ overallComplianceScore: complianceReport.summary.overallComplianceScore,
459
+ totalIssues: complianceReport.summary.totalIssues,
460
+ generatedFiles: generatedFiles.map(f => ({
461
+ format: f.format,
462
+ fileName: f.fileName,
463
+ size: f.size
464
+ })),
465
+ healthStatus: this.metricsCalculator.getHealthStatus(complianceReport.summary.overallComplianceScore)
466
+ };
467
+ }
468
+
469
+ /**
470
+ * Generate executive summary
471
+ */
472
+ generateExecutiveSummary(complianceReport) {
473
+ const summary = complianceReport.summary;
474
+ const metrics = complianceReport.metrics;
475
+
476
+ return {
477
+ overview: {
478
+ totalFiles: summary.totalFiles,
479
+ complianceScore: summary.overallComplianceScore,
480
+ healthStatus: metrics?.overview?.healthStatus || 'unknown',
481
+ totalIssues: summary.totalIssues
482
+ },
483
+ keyFindings: this.extractKeyFindings(complianceReport),
484
+ priorityActions: this.extractPriorityActions(complianceReport),
485
+ riskAssessment: this.assessOverallRisk(complianceReport),
486
+ recommendations: complianceReport.recommendations.slice(0, 5) // Top 5 recommendations
487
+ };
488
+ }
489
+
490
+ /**
491
+ * Extract key findings
492
+ */
493
+ extractKeyFindings(complianceReport) {
494
+ const findings = [];
495
+ const summary = complianceReport.summary;
496
+
497
+ if (summary.criticalFiles > 0) {
498
+ findings.push(`${summary.criticalFiles} files have critical compliance violations`);
499
+ }
500
+
501
+ if (summary.violationFiles > 0) {
502
+ findings.push(`${summary.violationFiles} files exceed the 555-line limit`);
503
+ }
504
+
505
+ if (summary.overallComplianceScore < 80) {
506
+ findings.push(`Overall compliance score is ${summary.overallComplianceScore.toFixed(1)}%, below target of 90%`);
507
+ }
508
+
509
+ const largestFile = summary.largestFile;
510
+ if (largestFile && largestFile.lineCount > 800) {
511
+ findings.push(`Largest file has ${largestFile.lineCount} lines and requires immediate refactoring`);
512
+ }
513
+
514
+ return findings;
515
+ }
516
+
517
+ /**
518
+ * Extract priority actions
519
+ */
520
+ extractPriorityActions(complianceReport) {
521
+ const actions = [];
522
+
523
+ if (complianceReport.summary.criticalFiles > 0) {
524
+ actions.push({
525
+ priority: 1,
526
+ action: 'Address critical violations',
527
+ description: 'Fix all critical compliance issues immediately'
528
+ });
529
+ }
530
+
531
+ if (complianceReport.summary.violationFiles > 0) {
532
+ actions.push({
533
+ priority: 2,
534
+ action: 'Refactor oversized files',
535
+ description: 'Reduce file sizes to comply with 555-line limit'
536
+ });
537
+ }
538
+
539
+ if (complianceReport.summary.overallComplianceScore < 90) {
540
+ actions.push({
541
+ priority: 3,
542
+ action: 'Improve compliance score',
543
+ description: 'Address violations to achieve 90%+ compliance rate'
544
+ });
545
+ }
546
+
547
+ return actions;
548
+ }
549
+
550
+ /**
551
+ * Assess overall risk
552
+ */
553
+ assessOverallRisk(complianceReport) {
554
+ const score = complianceReport.summary.overallComplianceScore;
555
+ const criticalFiles = complianceReport.summary.criticalFiles;
556
+ const violationFiles = complianceReport.summary.violationFiles;
557
+
558
+ let riskLevel = 'low';
559
+ let riskFactors = [];
560
+
561
+ if (criticalFiles > 0) {
562
+ riskLevel = 'critical';
563
+ riskFactors.push(`${criticalFiles} critical files`);
564
+ } else if (violationFiles > 0) {
565
+ riskLevel = 'high';
566
+ riskFactors.push(`${violationFiles} files with violations`);
567
+ } else if (score < 80) {
568
+ riskLevel = 'medium';
569
+ riskFactors.push('Low compliance score');
570
+ }
571
+
572
+ return {
573
+ level: riskLevel,
574
+ score: score,
575
+ factors: riskFactors,
576
+ mitigation: this.getMitigationStrategies(riskLevel)
577
+ };
578
+ }
579
+
580
+ /**
581
+ * Get mitigation strategies
582
+ */
583
+ getMitigationStrategies(riskLevel) {
584
+ const strategies = {
585
+ critical: [
586
+ 'Immediately address all critical violations',
587
+ 'Implement daily compliance monitoring',
588
+ 'Establish mandatory code review for large files'
589
+ ],
590
+ high: [
591
+ 'Refactor all files exceeding size limits',
592
+ 'Implement pre-commit hooks for validation',
593
+ 'Schedule regular compliance reviews'
594
+ ],
595
+ medium: [
596
+ 'Monitor files approaching size limits',
597
+ 'Provide developer training on compliance',
598
+ 'Implement automated compliance checks'
599
+ ],
600
+ low: [
601
+ 'Maintain current compliance practices',
602
+ 'Continue regular monitoring',
603
+ 'Focus on prevention'
604
+ ]
605
+ };
606
+
607
+ return strategies[riskLevel] || strategies.low;
608
+ }
609
+
610
+ /**
611
+ * Create fallback report generator
612
+ */
613
+ createFallbackReportGenerator() {
614
+ return {
615
+ generateReport: (data, format) => {
616
+ switch (format) {
617
+ case 'json':
618
+ return JSON.stringify(data, null, 2);
619
+ case 'text':
620
+ return JSON.stringify(data, null, 2);
621
+ default:
622
+ return JSON.stringify(data, null, 2);
623
+ }
624
+ }
625
+ };
626
+ }
627
+
628
+ /**
629
+ * Generate comparison report (comparing two reports)
630
+ */
631
+ async generateComparisonReport(oldReport, newReport, options = {}) {
632
+ const comparison = {
633
+ metadata: {
634
+ generatedAt: new Date().toISOString(),
635
+ oldReportId: oldReport.id,
636
+ newReportId: newReport.id,
637
+ comparisonPeriod: this.calculatePeriod(oldReport.generatedAt, newReport.generatedAt)
638
+ },
639
+ changes: {
640
+ filesAdded: newReport.summary.totalFiles - oldReport.summary.totalFiles,
641
+ filesRemoved: 0, // Would need more complex logic to calculate
642
+ complianceScoreChange: newReport.summary.overallComplianceScore - oldReport.summary.overallComplianceScore,
643
+ issuesChange: newReport.summary.totalIssues - oldReport.summary.totalFiles
644
+ },
645
+ trends: this.calculateTrends(oldReport, newReport),
646
+ recommendations: this.generateComparisonRecommendations(oldReport, newReport)
647
+ };
648
+
649
+ const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
650
+ const filePath = path.join(options.outputDir || './reports', `comparison-report-${timestamp}.json`);
651
+
652
+ fs.writeFileSync(filePath, JSON.stringify(comparison, null, 2), 'utf8');
653
+
654
+ return {
655
+ comparison,
656
+ filePath
657
+ };
658
+ }
659
+
660
+ /**
661
+ * Calculate period between reports
662
+ */
663
+ calculatePeriod(oldDate, newDate) {
664
+ const old = new Date(oldDate);
665
+ const now = new Date(newDate);
666
+ const days = Math.floor((now - old) / (1000 * 60 * 60 * 24));
667
+
668
+ return `${days} days`;
669
+ }
670
+
671
+ /**
672
+ * Calculate trends between reports
673
+ */
674
+ calculateTrends(oldReport, newReport) {
675
+ return {
676
+ complianceTrend: newReport.summary.overallComplianceScore > oldReport.summary.overallComplianceScore ? 'improving' : 'declining',
677
+ issueTrend: newReport.summary.totalIssues < oldReport.summary.totalIssues ? 'decreasing' : 'increasing',
678
+ fileTrend: newReport.summary.totalFiles > oldReport.summary.totalFiles ? 'growing' : 'stable'
679
+ };
680
+ }
681
+
682
+ /**
683
+ * Generate comparison recommendations
684
+ */
685
+ generateComparisonRecommendations(oldReport, newReport) {
686
+ const recommendations = [];
687
+ const scoreChange = newReport.summary.overallComplianceScore - oldReport.summary.overallComplianceScore;
688
+
689
+ if (scoreChange < -5) {
690
+ recommendations.push({
691
+ type: 'urgent',
692
+ title: 'Compliance Score Declining',
693
+ description: `Compliance score decreased by ${Math.abs(scoreChange).toFixed(1)}%`,
694
+ action: 'Investigate and address causes of compliance decline'
695
+ });
696
+ }
697
+
698
+ if (scoreChange > 5) {
699
+ recommendations.push({
700
+ type: 'positive',
701
+ title: 'Compliance Improving',
702
+ description: `Compliance score improved by ${scoreChange.toFixed(1)}%`,
703
+ action: 'Continue current compliance practices'
704
+ });
705
+ }
706
+
707
+ return recommendations;
708
+ }
709
+ }
710
+
711
+ module.exports = ComplianceReporter;