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,538 @@
1
+ /**
2
+ * Compliance Report Data Model
3
+ *
4
+ * Defines the structure and behavior of compliance reports for tracking
5
+ * file size compliance and constitutional adherence across the codebase.
6
+ */
7
+
8
+ /**
9
+ * Compliance status levels
10
+ */
11
+ const COMPLIANCE_STATUS = {
12
+ COMPLIANT: 'compliant',
13
+ WARNING: 'warning',
14
+ VIOLATION: 'violation',
15
+ CRITICAL: 'critical',
16
+ UNKNOWN: 'unknown'
17
+ };
18
+
19
+ /**
20
+ * Compliance categories
21
+ */
22
+ const COMPLIANCE_CATEGORIES = {
23
+ FILE_SIZE: 'file_size',
24
+ CODE_STRUCTURE: 'code_structure',
25
+ TESTING: 'testing',
26
+ DOCUMENTATION: 'documentation',
27
+ IMPORTS: 'imports',
28
+ NAMING: 'naming',
29
+ SECURITY: 'security',
30
+ PERFORMANCE: 'performance'
31
+ };
32
+
33
+ /**
34
+ * Individual compliance issue
35
+ */
36
+ class ComplianceIssue {
37
+ constructor(data = {}) {
38
+ this.id = data.id || this.generateId();
39
+ this.filePath = data.filePath || '';
40
+ this.category = data.category || COMPLIANCE_CATEGORIES.FILE_SIZE;
41
+ this.severity = data.severity || 'warning';
42
+ this.status = data.status || COMPLIANCE_STATUS.WARNING;
43
+ this.rule = data.rule || '';
44
+ this.message = data.message || '';
45
+ this.description = data.description || '';
46
+ this.suggestion = data.suggestion || '';
47
+ this.lineNumber = data.lineNumber || null;
48
+ this.columnNumber = data.columnNumber || null;
49
+ this.metadata = {
50
+ createdAt: data.createdAt || new Date().toISOString(),
51
+ updatedAt: data.updatedAt || new Date().toISOString(),
52
+ validator: data.validator || 'unknown',
53
+ version: data.version || '1.0.0',
54
+ ...data.metadata
55
+ };
56
+ }
57
+
58
+ generateId() {
59
+ return `issue_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
60
+ }
61
+
62
+ update(updates = {}) {
63
+ Object.assign(this, updates);
64
+ this.metadata.updatedAt = new Date().toISOString();
65
+ return this;
66
+ }
67
+
68
+ toJSON() {
69
+ return {
70
+ id: this.id,
71
+ filePath: this.filePath,
72
+ category: this.category,
73
+ severity: this.severity,
74
+ status: this.status,
75
+ rule: this.rule,
76
+ message: this.message,
77
+ description: this.description,
78
+ suggestion: this.suggestion,
79
+ lineNumber: this.lineNumber,
80
+ columnNumber: this.columnNumber,
81
+ metadata: this.metadata
82
+ };
83
+ }
84
+
85
+ static fromJSON(data) {
86
+ return new ComplianceIssue(data);
87
+ }
88
+ }
89
+
90
+ /**
91
+ * File compliance summary
92
+ */
93
+ class FileComplianceSummary {
94
+ constructor(data = {}) {
95
+ this.filePath = data.filePath || '';
96
+ this.totalIssues = data.totalIssues || 0;
97
+ this.compliantIssues = data.compliantIssues || 0;
98
+ this.warningIssues = data.warningIssues || 0;
99
+ this.violationIssues = data.violationIssues || 0;
100
+ this.criticalIssues = data.criticalIssues || 0;
101
+ this.lineCount = data.lineCount || 0;
102
+ this.fileSize = data.fileSize || 0;
103
+ this.status = data.status || COMPLIANCE_STATUS.COMPLIANT;
104
+ this.complianceScore = data.complianceScore || 100;
105
+ this.issues = (data.issues || []).map(issue =>
106
+ issue instanceof ComplianceIssue ? issue : ComplianceIssue.fromJSON(issue)
107
+ );
108
+ this.metadata = {
109
+ analyzedAt: data.analyzedAt || new Date().toISOString(),
110
+ analyzer: data.analyzer || 'unknown',
111
+ version: data.version || '1.0.0',
112
+ ...data.metadata
113
+ };
114
+ }
115
+
116
+ addIssue(issue) {
117
+ const complianceIssue = issue instanceof ComplianceIssue ?
118
+ issue : new ComplianceIssue(issue);
119
+
120
+ this.issues.push(complianceIssue);
121
+ this.totalIssues++;
122
+
123
+ // Update category counts
124
+ switch (complianceIssue.severity) {
125
+ case 'critical':
126
+ this.criticalIssues++;
127
+ this.status = COMPLIANCE_STATUS.CRITICAL;
128
+ break;
129
+ case 'error':
130
+ this.violationIssues++;
131
+ if (this.status !== COMPLIANCE_STATUS.CRITICAL) {
132
+ this.status = COMPLIANCE_STATUS.VIOLATION;
133
+ }
134
+ break;
135
+ case 'warning':
136
+ this.warningIssues++;
137
+ if (this.status === COMPLIANCE_STATUS.COMPLIANT) {
138
+ this.status = COMPLIANCE_STATUS.WARNING;
139
+ }
140
+ break;
141
+ default:
142
+ this.compliantIssues++;
143
+ break;
144
+ }
145
+
146
+ // Recalculate compliance score
147
+ this.calculateComplianceScore();
148
+ this.metadata.analyzedAt = new Date().toISOString();
149
+
150
+ return this;
151
+ }
152
+
153
+ calculateComplianceScore() {
154
+ if (this.totalIssues === 0) {
155
+ this.complianceScore = 100;
156
+ return;
157
+ }
158
+
159
+ // Weight issues by severity
160
+ const weights = {
161
+ info: 1,
162
+ warning: 5,
163
+ error: 15,
164
+ critical: 30
165
+ };
166
+
167
+ let totalWeight = 0;
168
+ for (const issue of this.issues) {
169
+ totalWeight += weights[issue.severity] || 1;
170
+ }
171
+
172
+ // Calculate score (0-100)
173
+ const maxPossibleWeight = this.totalIssues * 30; // All critical would be worst
174
+ this.complianceScore = Math.max(0, 100 - (totalWeight / maxPossibleWeight * 100));
175
+ }
176
+
177
+ getIssuesByCategory(category) {
178
+ return this.issues.filter(issue => issue.category === category);
179
+ }
180
+
181
+ getIssuesBySeverity(severity) {
182
+ return this.issues.filter(issue => issue.severity === severity);
183
+ }
184
+
185
+ toJSON() {
186
+ return {
187
+ filePath: this.filePath,
188
+ totalIssues: this.totalIssues,
189
+ compliantIssues: this.compliantIssues,
190
+ warningIssues: this.warningIssues,
191
+ violationIssues: this.violationIssues,
192
+ criticalIssues: this.criticalIssues,
193
+ lineCount: this.lineCount,
194
+ fileSize: this.fileSize,
195
+ status: this.status,
196
+ complianceScore: this.complianceScore,
197
+ issues: this.issues.map(issue => issue.toJSON()),
198
+ metadata: this.metadata
199
+ };
200
+ }
201
+
202
+ static fromJSON(data) {
203
+ return new FileComplianceSummary(data);
204
+ }
205
+ }
206
+
207
+ /**
208
+ * Main compliance report
209
+ */
210
+ class ComplianceReport {
211
+ constructor(data = {}) {
212
+ this.id = data.id || this.generateId();
213
+ this.title = data.title || 'Codebase Compliance Report';
214
+ this.description = data.description || '';
215
+ this.generatedAt = data.generatedAt || new Date().toISOString();
216
+ this.scope = data.scope || 'full'; // 'full', 'package', 'directory', 'file'
217
+ this.scopePath = data.scopePath || '';
218
+ this.version = data.version || '1.0.0';
219
+
220
+ // Summary statistics
221
+ this.summary = {
222
+ totalFiles: data.totalFiles || 0,
223
+ totalIssues: data.totalIssues || 0,
224
+ compliantFiles: data.compliantFiles || 0,
225
+ warningFiles: data.warningFiles || 0,
226
+ violationFiles: data.violationFiles || 0,
227
+ criticalFiles: data.criticalFiles || 0,
228
+ overallComplianceScore: data.overallComplianceScore || 100,
229
+ totalLines: data.totalLines || 0,
230
+ averageLines: data.averageLines || 0,
231
+ largestFile: data.largestFile || null,
232
+ smallestFile: data.smallestFile || null,
233
+ ...data.summary
234
+ };
235
+
236
+ // Issues by category
237
+ this.issuesByCategory = {};
238
+ for (const category of Object.values(COMPLIANCE_CATEGORIES)) {
239
+ this.issuesByCategory[category] = data.issuesByCategory?.[category] || 0;
240
+ }
241
+
242
+ // File summaries
243
+ this.fileSummaries = (data.fileSummaries || []).map(summary =>
244
+ summary instanceof FileComplianceSummary ? summary : FileComplianceSummary.fromJSON(summary)
245
+ );
246
+
247
+ // Recommendations
248
+ this.recommendations = data.recommendations || [];
249
+
250
+ // Metadata
251
+ this.metadata = {
252
+ generator: data.generator || 'ComplianceReport',
253
+ config: data.config || {},
254
+ duration: data.duration || 0,
255
+ ...data.metadata
256
+ };
257
+ }
258
+
259
+ generateId() {
260
+ return `report_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
261
+ }
262
+
263
+ addFileSummary(fileSummary) {
264
+ const summary = fileSummary instanceof FileComplianceSummary ?
265
+ fileSummary : new FileComplianceSummary(fileSummary);
266
+
267
+ this.fileSummaries.push(summary);
268
+ this.updateSummary();
269
+ return this;
270
+ }
271
+
272
+ updateSummary() {
273
+ // Reset counters
274
+ this.summary.totalFiles = this.fileSummaries.length;
275
+ this.summary.compliantFiles = 0;
276
+ this.summary.warningFiles = 0;
277
+ this.summary.violationFiles = 0;
278
+ this.summary.criticalFiles = 0;
279
+ this.summary.totalIssues = 0;
280
+ this.summary.totalLines = 0;
281
+
282
+ // Reset category counts
283
+ for (const category of Object.values(COMPLIANCE_CATEGORIES)) {
284
+ this.issuesByCategory[category] = 0;
285
+ }
286
+
287
+ let totalComplianceScore = 0;
288
+ let largestFile = null;
289
+ let smallestFile = null;
290
+
291
+ // Aggregate from file summaries
292
+ for (const fileSummary of this.fileSummaries) {
293
+ // Count files by status
294
+ switch (fileSummary.status) {
295
+ case COMPLIANCE_STATUS.COMPLIANT:
296
+ this.summary.compliantFiles++;
297
+ break;
298
+ case COMPLIANCE_STATUS.WARNING:
299
+ this.summary.warningFiles++;
300
+ break;
301
+ case COMPLIANCE_STATUS.VIOLATION:
302
+ this.summary.violationFiles++;
303
+ break;
304
+ case COMPLIANCE_STATUS.CRITICAL:
305
+ this.summary.criticalFiles++;
306
+ break;
307
+ }
308
+
309
+ // Aggregate issues
310
+ this.summary.totalIssues += fileSummary.totalIssues;
311
+ totalComplianceScore += fileSummary.complianceScore;
312
+ this.summary.totalLines += fileSummary.lineCount;
313
+
314
+ // Track largest and smallest files
315
+ if (!largestFile || fileSummary.lineCount > largestFile.lineCount) {
316
+ largestFile = fileSummary;
317
+ }
318
+
319
+ if (!smallestFile || fileSummary.lineCount < smallestFile.lineCount) {
320
+ smallestFile = fileSummary;
321
+ }
322
+
323
+ // Aggregate issues by category
324
+ for (const issue of fileSummary.issues) {
325
+ this.issuesByCategory[issue.category] = (this.issuesByCategory[issue.category] || 0) + 1;
326
+ }
327
+ }
328
+
329
+ // Calculate averages
330
+ this.summary.averageLines = this.summary.totalFiles > 0 ?
331
+ Math.round(this.summary.totalLines / this.summary.totalFiles) : 0;
332
+
333
+ this.summary.overallComplianceScore = this.summary.totalFiles > 0 ?
334
+ totalComplianceScore / this.summary.totalFiles : 100;
335
+
336
+ this.summary.largestFile = largestFile ? {
337
+ filePath: largestFile.filePath,
338
+ lineCount: largestFile.lineCount,
339
+ status: largestFile.status
340
+ } : null;
341
+
342
+ this.summary.smallestFile = smallestFile ? {
343
+ filePath: smallestFile.filePath,
344
+ lineCount: smallestFile.lineCount,
345
+ status: smallestFile.status
346
+ } : null;
347
+
348
+ // Update recommendations
349
+ this.generateRecommendations();
350
+ }
351
+
352
+ generateRecommendations() {
353
+ this.recommendations = [];
354
+
355
+ // Critical issues
356
+ if (this.summary.criticalFiles > 0) {
357
+ this.recommendations.push({
358
+ priority: 'critical',
359
+ category: COMPLIANCE_CATEGORIES.FILE_SIZE,
360
+ title: `Address ${this.summary.criticalFiles} Critical Files`,
361
+ description: `${this.summary.criticalFiles} files have critical compliance violations requiring immediate attention.`,
362
+ action: 'Immediately address all critical violations',
363
+ affectedFiles: this.getFileSummariesByStatus(COMPLIANCE_STATUS.CRITICAL).map(s => s.filePath)
364
+ });
365
+ }
366
+
367
+ // Violation files
368
+ if (this.summary.violationFiles > 0) {
369
+ this.recommendations.push({
370
+ priority: 'high',
371
+ category: COMPLIANCE_CATEGORIES.CODE_STRUCTURE,
372
+ title: `Fix ${this.summary.violationFiles} Files with Violations`,
373
+ description: `${this.summary.violationFiles} files have compliance violations that should be addressed.`,
374
+ action: 'Fix all compliance violations',
375
+ affectedFiles: this.getFileSummariesByStatus(COMPLIANCE_STATUS.VIOLATION).map(s => s.filePath)
376
+ });
377
+ }
378
+
379
+ // Warning files
380
+ if (this.summary.warningFiles > 0) {
381
+ this.recommendations.push({
382
+ priority: 'medium',
383
+ category: COMPLIANCE_CATEGORIES.FILE_SIZE,
384
+ title: `Monitor ${this.summary.warningFiles} Files with Warnings`,
385
+ description: `${this.summary.warningFiles} files have warnings that should be monitored and addressed.`,
386
+ action: 'Review and address warning-level issues',
387
+ affectedFiles: this.getFileSummariesByStatus(COMPLIANCE_STATUS.WARNING).map(s => s.filePath)
388
+ });
389
+ }
390
+
391
+ // File size issues
392
+ const file_size_issues = this.issuesByCategory[COMPLIANCE_CATEGORIES.FILE_SIZE];
393
+ if (file_size_issues > 0) {
394
+ this.recommendations.push({
395
+ priority: 'high',
396
+ category: COMPLIANCE_CATEGORIES.FILE_SIZE,
397
+ title: 'Optimize File Sizes',
398
+ description: `${file_size_issues} file size compliance issues detected.`,
399
+ action: 'Refactor files to comply with 555-line limit',
400
+ affectedFiles: this.getFileSummariesWithCategoryIssues(COMPLIANCE_CATEGORIES.FILE_SIZE).map(s => s.filePath)
401
+ });
402
+ }
403
+
404
+ // Overall compliance score
405
+ if (this.summary.overallComplianceScore < 80) {
406
+ this.recommendations.push({
407
+ priority: 'high',
408
+ category: 'overall',
409
+ title: 'Improve Overall Compliance',
410
+ description: `Overall compliance score is ${this.summary.overallComplianceScore.toFixed(1)}%. Target is >90%.`,
411
+ action: 'Address violations to improve overall compliance',
412
+ affectedFiles: []
413
+ });
414
+ }
415
+ }
416
+
417
+ getFileSummariesByStatus(status) {
418
+ return this.fileSummaries.filter(summary => summary.status === status);
419
+ }
420
+
421
+ getFileSummariesWithCategoryIssues(category) {
422
+ return this.fileSummaries.filter(summary =>
423
+ summary.issues.some(issue => issue.category === category)
424
+ );
425
+ }
426
+
427
+ getFilesByComplianceScore(minScore = 0, maxScore = 100) {
428
+ return this.fileSummaries.filter(summary =>
429
+ summary.complianceScore >= minScore && summary.complianceScore <= maxScore
430
+ );
431
+ }
432
+
433
+ getTopViolations(limit = 10) {
434
+ return this.fileSummaries
435
+ .filter(summary => summary.status === COMPLIANCE_STATUS.VIOLATION || summary.status === COMPLIANCE_STATUS.CRITICAL)
436
+ .sort((a, b) => b.complianceScore - a.complianceScore)
437
+ .slice(0, limit);
438
+ }
439
+
440
+ toJSON() {
441
+ return {
442
+ id: this.id,
443
+ title: this.title,
444
+ description: this.description,
445
+ generatedAt: this.generatedAt,
446
+ scope: this.scope,
447
+ scopePath: this.scopePath,
448
+ version: this.version,
449
+ summary: this.summary,
450
+ issuesByCategory: this.issuesByCategory,
451
+ fileSummaries: this.fileSummaries.map(summary => summary.toJSON()),
452
+ recommendations: this.recommendations,
453
+ metadata: this.metadata
454
+ };
455
+ }
456
+
457
+ static fromJSON(data) {
458
+ return new ComplianceReport(data);
459
+ }
460
+
461
+ // Export to different formats
462
+ export(format = 'json') {
463
+ switch (format.toLowerCase()) {
464
+ case 'json':
465
+ return JSON.stringify(this.toJSON(), null, 2);
466
+ case 'summary':
467
+ return this.generateSummaryReport();
468
+ case 'detailed':
469
+ return this.generateDetailedReport();
470
+ default:
471
+ return this.toJSON();
472
+ }
473
+ }
474
+
475
+ generateSummaryReport() {
476
+ let report = `# ${this.title}\n\n`;
477
+ report += `**Generated:** ${new Date(this.generatedAt).toLocaleString()}\n`;
478
+ report += `**Scope:** ${this.scope} (${this.scopePath})\n`;
479
+ report += `**Overall Compliance Score:** ${this.summary.overallComplianceScore.toFixed(1)}%\n\n`;
480
+
481
+ report += `## Summary\n\n`;
482
+ report += `- **Total Files:** ${this.summary.totalFiles}\n`;
483
+ report += `- **Compliant Files:** ${this.summary.compliantFiles}\n`;
484
+ report += `- **Warning Files:** ${this.summary.warningFiles}\n`;
485
+ report += `- **Violation Files:** ${this.summary.violationFiles}\n`;
486
+ report += `- **Critical Files:** ${this.summary.criticalFiles}\n`;
487
+ report += `- **Total Issues:** ${this.summary.totalIssues}\n`;
488
+ report += `- **Total Lines:** ${this.summary.totalLines}\n`;
489
+ report += `- **Average Lines:** ${this.summary.averageLines}\n\n`;
490
+
491
+ if (this.recommendations.length > 0) {
492
+ report += `## Recommendations\n\n`;
493
+ for (const rec of this.recommendations) {
494
+ report += `### ${rec.title} (${rec.priority})\n`;
495
+ report += `${rec.description}\n\n`;
496
+ report += `**Action:** ${rec.action}\n\n`;
497
+ }
498
+ }
499
+
500
+ return report;
501
+ }
502
+
503
+ generateDetailedReport() {
504
+ let report = this.generateSummaryReport();
505
+
506
+ // Issues by category
507
+ report += `## Issues by Category\n\n`;
508
+ for (const [category, count] of Object.entries(this.issuesByCategory)) {
509
+ if (count > 0) {
510
+ report += `- **${category}:** ${count}\n`;
511
+ }
512
+ }
513
+ report += '\n';
514
+
515
+ // File details
516
+ report += `## File Details\n\n`;
517
+ report += `| File | Lines | Status | Score | Issues |\n`;
518
+ report += `|------|------|--------|-------|--------|\n`;
519
+
520
+ for (const fileSummary of this.fileSummaries.sort((a, b) => b.lineCount - a.lineCount)) {
521
+ const statusIcon = fileSummary.status === 'compliant' ? '✅' :
522
+ fileSummary.status === 'warning' ? '⚠️' :
523
+ fileSummary.status === 'violation' ? '❌' : '🚨';
524
+
525
+ report += `| \`${fileSummary.filePath}\` | ${fileSummary.lineCount} | ${statusIcon} ${fileSummary.status} | ${fileSummary.complianceScore.toFixed(1)}% | ${fileSummary.totalIssues} |\n`;
526
+ }
527
+
528
+ return report;
529
+ }
530
+ }
531
+
532
+ module.exports = {
533
+ ComplianceReport,
534
+ FileComplianceSummary,
535
+ ComplianceIssue,
536
+ COMPLIANCE_STATUS,
537
+ COMPLIANCE_CATEGORIES
538
+ };