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,250 @@
1
+ /**
2
+ * Analysis Report Data Structure
3
+ */
4
+
5
+ const RefactoringConfig = require('../../config/refactoring-config');
6
+
7
+ /**
8
+ * Analysis report class
9
+ */
10
+ class AnalysisReport {
11
+ constructor() {
12
+ this.metadata = {
13
+ generatedAt: new Date().toISOString(),
14
+ version: '1.0.0',
15
+ analysisScope: 'full_codebase',
16
+ config: RefactoringConfig.limits
17
+ };
18
+
19
+ this.summary = {
20
+ totalFiles: 0,
21
+ totalLines: 0,
22
+ filesNeedingRefactoring: 0,
23
+ urgentRefactoring: 0,
24
+ complianceRate: 0,
25
+ averageComplexity: 0
26
+ };
27
+
28
+ this.fileAnalysis = [];
29
+ this.packageAnalysis = {};
30
+ this.recommendations = [];
31
+ this.strategies = [];
32
+ this.statistics = {};
33
+ this.violations = [];
34
+ this.trends = {};
35
+ }
36
+
37
+ /**
38
+ * Add file analysis to report
39
+ * @param {Object} analysis - File analysis data
40
+ */
41
+ addFileAnalysis(analysis) {
42
+ this.fileAnalysis.push(analysis);
43
+ this.updateSummary();
44
+ }
45
+
46
+ /**
47
+ * Update report summary
48
+ */
49
+ updateSummary() {
50
+ this.summary.totalFiles = this.fileAnalysis.length;
51
+ this.summary.totalLines = this.fileAnalysis.reduce((sum, f) => sum + f.lineCount, 0);
52
+ this.summary.filesNeedingRefactoring = this.fileAnalysis.filter(f => f.needsRefactoring).length;
53
+ this.summary.urgentRefactoring = this.fileAnalysis.filter(f => f.urgentRefactoring).length;
54
+ this.summary.complianceRate = this.calculateComplianceRate();
55
+ this.summary.averageComplexity = this.calculateAverageComplexity();
56
+ }
57
+
58
+ /**
59
+ * Calculate compliance rate
60
+ * @returns {string} Compliance rate as percentage
61
+ */
62
+ calculateComplianceRate() {
63
+ if (this.summary.totalFiles === 0) return 0;
64
+ const compliantFiles = this.fileAnalysis.filter(f => !f.needsRefactoring).length;
65
+ return (compliantFiles / this.summary.totalFiles * 100).toFixed(1);
66
+ }
67
+
68
+ /**
69
+ * Calculate average complexity
70
+ * @returns {number} Average complexity score
71
+ */
72
+ calculateAverageComplexity() {
73
+ if (this.fileAnalysis.length === 0) return 0;
74
+ const totalComplexity = this.fileAnalysis.reduce((sum, f) => {
75
+ return sum + (f.getComplexityScore ? f.getComplexityScore() : 0);
76
+ }, 0);
77
+ return Math.round(totalComplexity / this.fileAnalysis.length);
78
+ }
79
+
80
+ /**
81
+ * Add package analysis
82
+ * @param {string} packageName - Package name
83
+ * @param {Object} analysis - Package analysis data
84
+ */
85
+ addPackageAnalysis(packageName, analysis) {
86
+ this.packageAnalysis[packageName] = analysis;
87
+ }
88
+
89
+ /**
90
+ * Add recommendation
91
+ * @param {Object} recommendation - Recommendation data
92
+ */
93
+ addRecommendation(recommendation) {
94
+ this.recommendations.push(recommendation);
95
+ }
96
+
97
+ /**
98
+ * Add strategy
99
+ * @param {Object} strategy - Strategy data
100
+ */
101
+ addStrategy(strategy) {
102
+ this.strategies.push(strategy);
103
+ }
104
+
105
+ /**
106
+ * Add statistics
107
+ * @param {Object} statistics - Statistics data
108
+ */
109
+ addStatistics(statistics) {
110
+ this.statistics = { ...this.statistics, ...statistics };
111
+ }
112
+
113
+ /**
114
+ * Add violation
115
+ * @param {Object} violation - Violation data
116
+ */
117
+ addViolation(violation) {
118
+ this.violations.push(violation);
119
+ }
120
+
121
+ /**
122
+ * Add trend data
123
+ * @param {Object} trends - Trend data
124
+ */
125
+ addTrends(trends) {
126
+ this.trends = { ...this.trends, ...trends };
127
+ }
128
+
129
+ /**
130
+ * Get files needing refactoring
131
+ * @returns {Array} Files that need refactoring
132
+ */
133
+ getFilesNeedingRefactoring() {
134
+ return this.fileAnalysis.filter(f => f.needsRefactoring);
135
+ }
136
+
137
+ /**
138
+ * Get urgent refactoring files
139
+ * @returns {Array} Files needing urgent refactoring
140
+ */
141
+ getUrgentRefactoringFiles() {
142
+ return this.fileAnalysis.filter(f => f.urgentRefactoring);
143
+ }
144
+
145
+ /**
146
+ * Get files by size category
147
+ * @param {string} category - Size category (SMALL, MEDIUM, LARGE, XLARGE)
148
+ * @returns {Array} Files in the specified category
149
+ */
150
+ getFilesBySizeCategory(category) {
151
+ return this.fileAnalysis.filter(f => f.sizeCategory === category);
152
+ }
153
+
154
+ /**
155
+ * Get compliance summary
156
+ * @returns {Object} Compliance summary
157
+ */
158
+ getComplianceSummary() {
159
+ const total = this.summary.totalFiles;
160
+ const compliant = total - this.summary.filesNeedingRefactoring;
161
+ const urgent = this.summary.urgentRefactoring;
162
+
163
+ return {
164
+ total,
165
+ compliant,
166
+ nonCompliant: this.summary.filesNeedingRefactoring,
167
+ urgent,
168
+ complianceRate: parseFloat(this.summary.complianceRate),
169
+ status: this.getComplianceStatus()
170
+ };
171
+ }
172
+
173
+ /**
174
+ * Get compliance status
175
+ * @returns {string} Compliance status
176
+ */
177
+ getComplianceStatus() {
178
+ const rate = parseFloat(this.summary.complianceRate);
179
+ if (rate === 100) return 'COMPLIANT';
180
+ if (rate >= 90) return 'MOSTLY_COMPLIANT';
181
+ if (rate >= 70) return 'PARTIALLY_COMPLIANT';
182
+ return 'NON_COMPLIANT';
183
+ }
184
+
185
+ /**
186
+ * Get package summary
187
+ * @returns {Object} Package summary
188
+ */
189
+ getPackageSummary() {
190
+ const summary = {};
191
+
192
+ for (const [packageName, analysis] of Object.entries(this.packageAnalysis)) {
193
+ summary[packageName] = {
194
+ totalFiles: analysis.totalFiles || 0,
195
+ totalLines: analysis.totalLines || 0,
196
+ filesNeedingRefactoring: analysis.filesNeedingRefactoring || 0,
197
+ complianceRate: analysis.complianceRate || 0,
198
+ status: analysis.status || 'UNKNOWN'
199
+ };
200
+ }
201
+
202
+ return summary;
203
+ }
204
+
205
+ /**
206
+ * Get violation summary
207
+ * @returns {Object} Violation summary
208
+ */
209
+ getViolationSummary() {
210
+ const summary = {
211
+ total: this.violations.length,
212
+ byType: {},
213
+ bySeverity: {},
214
+ byPackage: {}
215
+ };
216
+
217
+ for (const violation of this.violations) {
218
+ // Count by type
219
+ summary.byType[violation.type] = (summary.byType[violation.type] || 0) + 1;
220
+
221
+ // Count by severity
222
+ summary.bySeverity[violation.severity] = (summary.bySeverity[violation.severity] || 0) + 1;
223
+
224
+ // Count by package
225
+ summary.byPackage[violation.packageName] = (summary.byPackage[violation.packageName] || 0) + 1;
226
+ }
227
+
228
+ return summary;
229
+ }
230
+
231
+ /**
232
+ * Convert to JSON
233
+ * @returns {Object} Report as JSON object
234
+ */
235
+ toJSON() {
236
+ return {
237
+ metadata: this.metadata,
238
+ summary: this.summary,
239
+ fileAnalysis: this.fileAnalysis,
240
+ packageAnalysis: this.packageAnalysis,
241
+ recommendations: this.recommendations,
242
+ strategies: this.strategies,
243
+ statistics: this.statistics,
244
+ violations: this.violations,
245
+ trends: this.trends
246
+ };
247
+ }
248
+ }
249
+
250
+ module.exports = AnalysisReport;
@@ -0,0 +1,278 @@
1
+ /**
2
+ * Package Analysis for Reports
3
+ */
4
+
5
+ /**
6
+ * Analyze packages and generate package-level insights
7
+ */
8
+ class PackageAnalyzer {
9
+ constructor() {
10
+ this.packageMetrics = new Map();
11
+ }
12
+
13
+ /**
14
+ * Analyze package from file analyses
15
+ * @param {Array} fileAnalyses - Array of file analyses
16
+ * @returns {Object} Package analysis results
17
+ */
18
+ analyzePackages(fileAnalyses) {
19
+ const packageMap = new Map();
20
+
21
+ // Group files by package
22
+ for (const fileAnalysis of fileAnalyses) {
23
+ const packageName = this.extractPackageName(fileAnalysis.filePath);
24
+
25
+ if (!packageMap.has(packageName)) {
26
+ packageMap.set(packageName, {
27
+ packageName,
28
+ files: [],
29
+ totalLines: 0,
30
+ totalFiles: 0,
31
+ filesNeedingRefactoring: 0,
32
+ urgentRefactoring: 0,
33
+ sizeDistribution: {
34
+ SMALL: 0,
35
+ MEDIUM: 0,
36
+ LARGE: 0,
37
+ XLARGE: 0
38
+ },
39
+ complexityScores: [],
40
+ violations: []
41
+ });
42
+ }
43
+
44
+ const packageData = packageMap.get(packageName);
45
+ packageData.files.push(fileAnalysis);
46
+ packageData.totalLines += fileAnalysis.lineCount;
47
+ packageData.totalFiles += 1;
48
+
49
+ if (fileAnalysis.needsRefactoring) {
50
+ packageData.filesNeedingRefactoring += 1;
51
+ }
52
+
53
+ if (fileAnalysis.urgentRefactoring) {
54
+ packageData.urgentRefactoring += 1;
55
+ }
56
+
57
+ // Track size distribution
58
+ if (fileAnalysis.sizeCategory) {
59
+ packageData.sizeDistribution[fileAnalysis.sizeCategory] += 1;
60
+ }
61
+
62
+ // Track complexity
63
+ if (fileAnalysis.getComplexityScore) {
64
+ packageData.complexityScores.push(fileAnalysis.getComplexityScore());
65
+ }
66
+
67
+ // Track violations
68
+ if (fileAnalysis.violations) {
69
+ packageData.violations.push(...fileAnalysis.violations);
70
+ }
71
+ }
72
+
73
+ // Calculate package metrics
74
+ const results = {};
75
+ for (const [packageName, data] of packageMap) {
76
+ results[packageName] = this.calculatePackageMetrics(data);
77
+ }
78
+
79
+ return results;
80
+ }
81
+
82
+ /**
83
+ * Extract package name from file path
84
+ * @param {string} filePath - File path
85
+ * @returns {string} Package name
86
+ */
87
+ extractPackageName(filePath) {
88
+ const parts = filePath.split('/');
89
+ const packagesIndex = parts.findIndex(part => part === 'packages');
90
+
91
+ if (packagesIndex !== -1 && parts.length > packagesIndex + 1) {
92
+ return parts[packagesIndex + 1];
93
+ }
94
+
95
+ return 'unknown';
96
+ }
97
+
98
+ /**
99
+ * Calculate package metrics
100
+ * @param {Object} packageData - Package data
101
+ * @returns {Object} Package metrics
102
+ */
103
+ calculatePackageMetrics(packageData) {
104
+ const complianceRate = packageData.totalFiles > 0
105
+ ? ((packageData.totalFiles - packageData.filesNeedingRefactoring) / packageData.totalFiles * 100).toFixed(1)
106
+ : 0;
107
+
108
+ const averageComplexity = packageData.complexityScores.length > 0
109
+ ? Math.round(packageData.complexityScores.reduce((sum, score) => sum + score, 0) / packageData.complexityScores.length)
110
+ : 0;
111
+
112
+ const status = this.getPackageStatus(complianceRate, packageData.urgentRefactoring);
113
+
114
+ return {
115
+ packageName: packageData.packageName,
116
+ totalFiles: packageData.totalFiles,
117
+ totalLines: packageData.totalLines,
118
+ filesNeedingRefactoring: packageData.filesNeedingRefactoring,
119
+ urgentRefactoring: packageData.urgentRefactoring,
120
+ complianceRate: parseFloat(complianceRate),
121
+ averageComplexity,
122
+ status,
123
+ sizeDistribution: packageData.sizeDistribution,
124
+ violationCount: packageData.violations.length,
125
+ riskScore: this.calculateRiskScore(packageData, complianceRate),
126
+ recommendations: this.generatePackageRecommendations(packageData, complianceRate)
127
+ };
128
+ }
129
+
130
+ /**
131
+ * Get package status based on metrics
132
+ * @param {number} complianceRate - Compliance rate
133
+ * @param {number} urgentRefactoring - Number of urgent refactoring files
134
+ * @returns {string} Package status
135
+ */
136
+ getPackageStatus(complianceRate, urgentRefactoring) {
137
+ if (complianceRate === 100 && urgentRefactoring === 0) {
138
+ return 'COMPLIANT';
139
+ } else if (complianceRate >= 90 && urgentRefactoring === 0) {
140
+ return 'MOSTLY_COMPLIANT';
141
+ } else if (urgentRefactoring > 0) {
142
+ return 'URGENT_ATTENTION';
143
+ } else if (complianceRate >= 70) {
144
+ return 'PARTIALLY_COMPLIANT';
145
+ } else {
146
+ return 'NON_COMPLIANT';
147
+ }
148
+ }
149
+
150
+ /**
151
+ * Calculate risk score for package
152
+ * @param {Object} packageData - Package data
153
+ * @param {number} complianceRate - Compliance rate
154
+ * @returns {number} Risk score (0-100)
155
+ */
156
+ calculateRiskScore(packageData, complianceRate) {
157
+ let riskScore = 0;
158
+
159
+ // Base risk from non-compliance
160
+ riskScore += (100 - complianceRate) * 0.5;
161
+
162
+ // Risk from urgent files
163
+ riskScore += packageData.urgentRefactoring * 10;
164
+
165
+ // Risk from large files
166
+ riskScore += packageData.sizeDistribution.XLARGE * 15;
167
+ riskScore += packageData.sizeDistribution.LARGE * 8;
168
+
169
+ // Risk from violations
170
+ riskScore += packageData.violations.length * 5;
171
+
172
+ // Risk from complexity
173
+ if (packageData.averageComplexity > 50) {
174
+ riskScore += 20;
175
+ } else if (packageData.averageComplexity > 30) {
176
+ riskScore += 10;
177
+ }
178
+
179
+ return Math.min(100, Math.round(riskScore));
180
+ }
181
+
182
+ /**
183
+ * Generate package recommendations
184
+ * @param {Object} packageData - Package data
185
+ * @param {number} complianceRate - Compliance rate
186
+ * @returns {Array} Array of recommendations
187
+ */
188
+ generatePackageRecommendations(packageData, complianceRate) {
189
+ const recommendations = [];
190
+
191
+ if (packageData.urgentRefactoring > 0) {
192
+ recommendations.push({
193
+ type: 'URGENT',
194
+ priority: 'HIGH',
195
+ message: `Package has ${packageData.urgentRefactoring} files requiring urgent refactoring`,
196
+ action: 'Address urgent files first to reduce technical debt'
197
+ });
198
+ }
199
+
200
+ if (packageData.sizeDistribution.XLARGE > 0) {
201
+ recommendations.push({
202
+ type: 'SIZE',
203
+ priority: 'HIGH',
204
+ message: `Package contains ${packageData.sizeDistribution.XLARGE} XLARGE files (>1000 lines)`,
205
+ action: 'Break down large files into smaller, focused modules'
206
+ });
207
+ }
208
+
209
+ if (packageData.sizeDistribution.LARGE > 2) {
210
+ recommendations.push({
211
+ type: 'SIZE',
212
+ priority: 'MEDIUM',
213
+ message: `Package contains ${packageData.sizeDistribution.LARGE} LARGE files (555-1000 lines)`,
214
+ action: 'Consider refactoring large files to improve maintainability'
215
+ });
216
+ }
217
+
218
+ if (complianceRate < 70) {
219
+ recommendations.push({
220
+ type: 'COMPLIANCE',
221
+ priority: 'HIGH',
222
+ message: `Package compliance rate is ${complianceRate}%`,
223
+ action: 'Focus on bringing files under the 555-line limit'
224
+ });
225
+ }
226
+
227
+ if (packageData.violations.length > 5) {
228
+ recommendations.push({
229
+ type: 'VIOLATIONS',
230
+ priority: 'MEDIUM',
231
+ message: `Package has ${packageData.violations.length} code violations`,
232
+ action: 'Address code quality issues to improve maintainability'
233
+ });
234
+ }
235
+
236
+ return recommendations;
237
+ }
238
+
239
+ /**
240
+ * Get package ranking by priority
241
+ * @param {Object} packageAnalyses - Package analysis results
242
+ * @returns {Array} Sorted package list by priority
243
+ */
244
+ getPackageRanking(packageAnalyses) {
245
+ return Object.entries(packageAnalyses)
246
+ .map(([packageName, analysis]) => ({
247
+ packageName,
248
+ ...analysis,
249
+ priority: this.calculatePackagePriority(analysis)
250
+ }))
251
+ .sort((a, b) => b.priority - a.priority);
252
+ }
253
+
254
+ /**
255
+ * Calculate package priority for refactoring
256
+ * @param {Object} analysis - Package analysis
257
+ * @returns {number} Priority score
258
+ */
259
+ calculatePackagePriority(analysis) {
260
+ let priority = 0;
261
+
262
+ // Priority from urgent files
263
+ priority += analysis.urgentRefactoring * 50;
264
+
265
+ // Priority from non-compliance
266
+ priority += (100 - analysis.complianceRate) * 2;
267
+
268
+ // Priority from risk score
269
+ priority += analysis.riskScore * 0.5;
270
+
271
+ // Priority from total lines (larger packages get higher priority)
272
+ priority += Math.log(analysis.totalLines + 1) * 0.1;
273
+
274
+ return Math.round(priority);
275
+ }
276
+ }
277
+
278
+ module.exports = PackageAnalyzer;