vibecodingmachine-core 2026.2.20-438 → 2026.2.26-1642

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,814 @@
1
+ /**
2
+ * Refactoring Strategy Generator
3
+ *
4
+ * Generates comprehensive refactoring strategies based on analysis results.
5
+ * Provides prioritized, actionable refactoring plans.
6
+ */
7
+
8
+ const path = require('path');
9
+ const RefactoringConfig = require('../config/refactoring-config');
10
+
11
+ /**
12
+ * Strategy types
13
+ */
14
+ const STRATEGY_TYPES = {
15
+ SPLIT_FILE: 'split_file',
16
+ EXTRACT_FUNCTIONS: 'extract_functions',
17
+ EXTRACT_CLASSES: 'extract_classes',
18
+ EXTRACT_UTILITIES: 'extract_utilities',
19
+ EXTRACT_CONSTANTS: 'extract_constants',
20
+ REORGANIZE_IMPORTS: 'reorganize_imports',
21
+ MERGE_SMALL_FILES: 'merge_small_files',
22
+ RESTRUCTURE_DIRECTORIES: 'restructure_directories',
23
+ OPTIMIZE_DEPENDENCIES: 'optimize_dependencies'
24
+ };
25
+
26
+ /**
27
+ * Priority levels
28
+ */
29
+ const PRIORITY_LEVELS = {
30
+ CRITICAL: 'critical',
31
+ HIGH: 'high',
32
+ MEDIUM: 'medium',
33
+ LOW: 'low'
34
+ };
35
+
36
+ /**
37
+ * Refactoring strategy class
38
+ */
39
+ class RefactoringStrategy {
40
+ constructor(type, targetPath, priority = PRIORITY_LEVELS.MEDIUM) {
41
+ this.id = this.generateId();
42
+ this.type = type;
43
+ this.targetPath = targetPath;
44
+ this.priority = priority;
45
+ this.description = '';
46
+ this.steps = [];
47
+ this.estimatedEffort = 0;
48
+ this.riskLevel = 'medium';
49
+ this.dependencies = [];
50
+ this.impact = {
51
+ files: [],
52
+ lines: 0,
53
+ complexity: 'unknown'
54
+ };
55
+ this.metadata = {
56
+ createdAt: new Date().toISOString(),
57
+ status: 'pending'
58
+ };
59
+ }
60
+
61
+ generateId() {
62
+ return `strategy_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
63
+ }
64
+
65
+ addStep(step) {
66
+ this.steps.push(step);
67
+ }
68
+
69
+ addDependency(dependency) {
70
+ this.dependencies.push(dependency);
71
+ }
72
+
73
+ setEstimatedEffort(effort) {
74
+ this.estimatedEffort = effort;
75
+ }
76
+
77
+ setRiskLevel(risk) {
78
+ this.riskLevel = risk;
79
+ }
80
+
81
+ setImpact(impact) {
82
+ this.impact = { ...this.impact, ...impact };
83
+ }
84
+ }
85
+
86
+ /**
87
+ * Strategy generator class
88
+ */
89
+ class StrategyGenerator {
90
+ constructor(config = RefactoringConfig) {
91
+ this.config = config;
92
+ this.strategies = [];
93
+ this.analysisResults = null;
94
+ }
95
+
96
+ /**
97
+ * Generate strategies based on analysis results
98
+ */
99
+ generateStrategies(analysisResults) {
100
+ this.analysisResults = analysisResults;
101
+ this.strategies = [];
102
+
103
+ // Generate strategies for each file that needs refactoring
104
+ for (const fileAnalysis of analysisResults.files || []) {
105
+ if (fileAnalysis.needsRefactoring || fileAnalysis.urgentRefactoring) {
106
+ const fileStrategies = this.generateFileStrategies(fileAnalysis);
107
+ this.strategies.push(...fileStrategies);
108
+ }
109
+ }
110
+
111
+ // Generate global strategies
112
+ const globalStrategies = this.generateGlobalStrategies();
113
+ this.strategies.push(...globalStrategies);
114
+
115
+ // Prioritize strategies
116
+ this.prioritizeStrategies();
117
+
118
+ return this.strategies;
119
+ }
120
+
121
+ /**
122
+ * Generate strategies for a specific file
123
+ */
124
+ generateFileStrategies(fileAnalysis) {
125
+ const strategies = [];
126
+ const { filePath, lineCount, categorization, boundaries } = fileAnalysis;
127
+
128
+ // Determine priority based on file analysis
129
+ const priority = this.determinePriority(fileAnalysis);
130
+
131
+ // Large file splitting strategy
132
+ if (lineCount > 555) {
133
+ const splitStrategy = this.generateSplitFileStrategy(fileAnalysis, priority);
134
+ strategies.push(splitStrategy);
135
+ }
136
+
137
+ // Function extraction strategies
138
+ if (boundaries && boundaries.functions) {
139
+ const largeFunctions = boundaries.functions.filter(f => f.lineCount > 30);
140
+ if (largeFunctions.length > 0) {
141
+ const extractStrategy = this.generateExtractFunctionsStrategy(fileAnalysis, largeFunctions, priority);
142
+ strategies.push(extractStrategy);
143
+ }
144
+ }
145
+
146
+ // Class extraction strategies
147
+ if (boundaries && boundaries.classes) {
148
+ const largeClasses = boundaries.classes.filter(c => c.lineCount > 150);
149
+ if (largeClasses.length > 0) {
150
+ const extractStrategy = this.generateExtractClassesStrategy(fileAnalysis, largeClasses, priority);
151
+ strategies.push(extractStrategy);
152
+ }
153
+ }
154
+
155
+ // Utility extraction strategy
156
+ if (boundaries && boundaries.utilities && boundaries.utilities.length > 0) {
157
+ const utilityStrategy = this.generateExtractUtilitiesStrategy(fileAnalysis, priority);
158
+ strategies.push(utilityStrategy);
159
+ }
160
+
161
+ // Import reorganization strategy
162
+ if (boundaries && boundaries.imports && boundaries.imports.length > 10) {
163
+ const importStrategy = this.generateReorganizeImportsStrategy(fileAnalysis, priority);
164
+ strategies.push(importStrategy);
165
+ }
166
+
167
+ return strategies;
168
+ }
169
+
170
+ /**
171
+ * Generate split file strategy
172
+ */
173
+ generateSplitFileStrategy(fileAnalysis, priority) {
174
+ const strategy = new RefactoringStrategy(
175
+ STRATEGY_TYPES.SPLIT_FILE,
176
+ fileAnalysis.filePath,
177
+ priority
178
+ );
179
+
180
+ strategy.description = `Split large file (${fileAnalysis.lineCount} lines) into smaller, focused modules`;
181
+
182
+ // Determine split points based on boundaries
183
+ const splitPoints = this.identifySplitPoints(fileAnalysis);
184
+
185
+ strategy.addStep({
186
+ action: 'analyze_boundaries',
187
+ description: 'Analyze file structure to identify logical split points',
188
+ command: 'analyze-boundaries',
189
+ target: fileAnalysis.filePath
190
+ });
191
+
192
+ strategy.addStep({
193
+ action: 'create_backup',
194
+ description: 'Create backup of original file',
195
+ command: 'backup-file',
196
+ target: fileAnalysis.filePath
197
+ });
198
+
199
+ for (let i = 0; i < splitPoints.length; i++) {
200
+ const point = splitPoints[i];
201
+ strategy.addStep({
202
+ action: 'extract_module',
203
+ description: `Extract ${point.type} "${point.name}" to separate file`,
204
+ command: 'extract-module',
205
+ target: fileAnalysis.filePath,
206
+ output: point.suggestedPath,
207
+ lines: `${point.startLine}-${point.endLine}`
208
+ });
209
+ }
210
+
211
+ strategy.addStep({
212
+ action: 'update_imports',
213
+ description: 'Update import statements in dependent files',
214
+ command: 'update-imports',
215
+ target: fileAnalysis.filePath
216
+ });
217
+
218
+ strategy.addStep({
219
+ action: 'validate_refactoring',
220
+ description: 'Run tests to validate refactoring',
221
+ command: 'run-tests',
222
+ target: 'all'
223
+ });
224
+
225
+ strategy.addStep({
226
+ action: 'cleanup_original',
227
+ description: 'Clean up original file (remove extracted code)',
228
+ command: 'cleanup-file',
229
+ target: fileAnalysis.filePath
230
+ });
231
+
232
+ // Estimate effort
233
+ strategy.setEstimatedEffort(this.estimateSplitEffort(fileAnalysis, splitPoints));
234
+ strategy.setRiskLevel(this.assessSplitRisk(fileAnalysis));
235
+ strategy.setImpact({
236
+ files: [fileAnalysis.filePath, ...splitPoints.map(p => p.suggestedPath)],
237
+ lines: fileAnalysis.lineCount,
238
+ complexity: 'high'
239
+ });
240
+
241
+ return strategy;
242
+ }
243
+
244
+ /**
245
+ * Generate extract functions strategy
246
+ */
247
+ generateExtractFunctionsStrategy(fileAnalysis, largeFunctions, priority) {
248
+ const strategy = new RefactoringStrategy(
249
+ STRATEGY_TYPES.EXTRACT_FUNCTIONS,
250
+ fileAnalysis.filePath,
251
+ priority
252
+ );
253
+
254
+ strategy.description = `Extract ${largeFunctions.length} large functions to separate utility modules`;
255
+
256
+ strategy.addStep({
257
+ action: 'analyze_functions',
258
+ description: 'Analyze function dependencies and usage',
259
+ command: 'analyze-functions',
260
+ target: fileAnalysis.filePath
261
+ });
262
+
263
+ strategy.addStep({
264
+ action: 'create_backup',
265
+ description: 'Create backup of original file',
266
+ command: 'backup-file',
267
+ target: fileAnalysis.filePath
268
+ });
269
+
270
+ for (const func of largeFunctions) {
271
+ strategy.addStep({
272
+ action: 'extract_function',
273
+ description: `Extract function "${func.name}" to utility module`,
274
+ command: 'extract-function',
275
+ target: fileAnalysis.filePath,
276
+ functionName: func.name,
277
+ lines: `${func.startLine}-${func.endLine}`,
278
+ output: this.suggestUtilityPath(fileAnalysis.filePath, func.name)
279
+ });
280
+ }
281
+
282
+ strategy.addStep({
283
+ action: 'update_function_calls',
284
+ description: 'Update function calls and imports',
285
+ command: 'update-calls',
286
+ target: fileAnalysis.filePath
287
+ });
288
+
289
+ strategy.addStep({
290
+ action: 'validate_extraction',
291
+ description: 'Run tests to validate function extraction',
292
+ command: 'run-tests',
293
+ target: 'all'
294
+ });
295
+
296
+ strategy.setEstimatedEffort(largeFunctions.length * 2); // 2 effort units per function
297
+ strategy.setRiskLevel('medium');
298
+ strategy.setImpact({
299
+ files: [fileAnalysis.filePath],
300
+ lines: largeFunctions.reduce((sum, f) => sum + f.lineCount, 0),
301
+ complexity: 'medium'
302
+ });
303
+
304
+ return strategy;
305
+ }
306
+
307
+ /**
308
+ * Generate extract classes strategy
309
+ */
310
+ generateExtractClassesStrategy(fileAnalysis, largeClasses, priority) {
311
+ const strategy = new RefactoringStrategy(
312
+ STRATEGY_TYPES.EXTRACT_CLASSES,
313
+ fileAnalysis.filePath,
314
+ priority
315
+ );
316
+
317
+ strategy.description = `Extract ${largeClasses.length} large classes to separate modules`;
318
+
319
+ strategy.addStep({
320
+ action: 'analyze_classes',
321
+ description: 'Analyze class dependencies and inheritance',
322
+ command: 'analyze-classes',
323
+ target: fileAnalysis.filePath
324
+ });
325
+
326
+ strategy.addStep({
327
+ action: 'create_backup',
328
+ description: 'Create backup of original file',
329
+ command: 'backup-file',
330
+ target: fileAnalysis.filePath
331
+ });
332
+
333
+ for (const cls of largeClasses) {
334
+ strategy.addStep({
335
+ action: 'extract_class',
336
+ description: `Extract class "${cls.name}" to separate module`,
337
+ command: 'extract-class',
338
+ target: fileAnalysis.filePath,
339
+ className: cls.name,
340
+ lines: `${cls.startLine}-${cls.endLine}`,
341
+ output: this.suggestClassPath(fileAnalysis.filePath, cls.name)
342
+ });
343
+ }
344
+
345
+ strategy.addStep({
346
+ action: 'update_class_references',
347
+ description: 'Update class references and imports',
348
+ command: 'update-references',
349
+ target: fileAnalysis.filePath
350
+ });
351
+
352
+ strategy.addStep({
353
+ action: 'validate_extraction',
354
+ description: 'Run tests to validate class extraction',
355
+ command: 'run-tests',
356
+ target: 'all'
357
+ });
358
+
359
+ strategy.setEstimatedEffort(largeClasses.length * 3); // 3 effort units per class
360
+ strategy.setRiskLevel('high');
361
+ strategy.setImpact({
362
+ files: [fileAnalysis.filePath],
363
+ lines: largeClasses.reduce((sum, c) => sum + c.lineCount, 0),
364
+ complexity: 'high'
365
+ });
366
+
367
+ return strategy;
368
+ }
369
+
370
+ /**
371
+ * Generate extract utilities strategy
372
+ */
373
+ generateExtractUtilitiesStrategy(fileAnalysis, priority) {
374
+ const strategy = new RefactoringStrategy(
375
+ STRATEGY_TYPES.EXTRACT_UTILITIES,
376
+ fileAnalysis.filePath,
377
+ priority
378
+ );
379
+
380
+ strategy.description = 'Extract utility functions and constants to separate modules';
381
+
382
+ strategy.addStep({
383
+ action: 'identify_utilities',
384
+ description: 'Identify utility functions and constants',
385
+ command: 'identify-utilities',
386
+ target: fileAnalysis.filePath
387
+ });
388
+
389
+ strategy.addStep({
390
+ action: 'create_backup',
391
+ description: 'Create backup of original file',
392
+ command: 'backup-file',
393
+ target: fileAnalysis.filePath
394
+ });
395
+
396
+ strategy.addStep({
397
+ action: 'extract_utilities',
398
+ description: 'Extract utilities to utility modules',
399
+ command: 'extract-utilities',
400
+ target: fileAnalysis.filePath,
401
+ output: this.suggestUtilityPath(fileAnalysis.filePath, 'utils')
402
+ });
403
+
404
+ strategy.addStep({
405
+ action: 'update_utility_imports',
406
+ description: 'Update utility imports and references',
407
+ command: 'update-imports',
408
+ target: fileAnalysis.filePath
409
+ });
410
+
411
+ strategy.addStep({
412
+ action: 'validate_extraction',
413
+ description: 'Run tests to validate utility extraction',
414
+ command: 'run-tests',
415
+ target: 'all'
416
+ });
417
+
418
+ strategy.setEstimatedEffort(2);
419
+ strategy.setRiskLevel('low');
420
+ strategy.setImpact({
421
+ files: [fileAnalysis.filePath],
422
+ lines: 0, // Depends on analysis
423
+ complexity: 'low'
424
+ });
425
+
426
+ return strategy;
427
+ }
428
+
429
+ /**
430
+ * Generate reorganize imports strategy
431
+ */
432
+ generateReorganizeImportsStrategy(fileAnalysis, priority) {
433
+ const strategy = new RefactoringStrategy(
434
+ STRATEGY_TYPES.REORGANIZE_IMPORTS,
435
+ fileAnalysis.filePath,
436
+ priority
437
+ );
438
+
439
+ strategy.description = 'Reorganize and optimize import statements';
440
+
441
+ strategy.addStep({
442
+ action: 'analyze_imports',
443
+ description: 'Analyze import structure and dependencies',
444
+ command: 'analyze-imports',
445
+ target: fileAnalysis.filePath
446
+ });
447
+
448
+ strategy.addStep({
449
+ action: 'create_backup',
450
+ description: 'Create backup of original file',
451
+ command: 'backup-file',
452
+ target: fileAnalysis.filePath
453
+ });
454
+
455
+ strategy.addStep({
456
+ action: 'reorganize_imports',
457
+ description: 'Reorganize imports by type and source',
458
+ command: 'reorganize-imports',
459
+ target: fileAnalysis.filePath
460
+ });
461
+
462
+ strategy.addStep({
463
+ action: 'remove_unused_imports',
464
+ description: 'Remove unused import statements',
465
+ command: 'remove-unused-imports',
466
+ target: fileAnalysis.filePath
467
+ });
468
+
469
+ strategy.addStep({
470
+ action: 'validate_reorganization',
471
+ description: 'Run tests to validate import reorganization',
472
+ command: 'run-tests',
473
+ target: 'all'
474
+ });
475
+
476
+ strategy.setEstimatedEffort(1);
477
+ strategy.setRiskLevel('low');
478
+ strategy.setImpact({
479
+ files: [fileAnalysis.filePath],
480
+ lines: 0,
481
+ complexity: 'low'
482
+ });
483
+
484
+ return strategy;
485
+ }
486
+
487
+ /**
488
+ * Generate global strategies
489
+ */
490
+ generateGlobalStrategies() {
491
+ const strategies = [];
492
+
493
+ // Merge small files strategy
494
+ const smallFilesStrategy = this.generateMergeSmallFilesStrategy();
495
+ if (smallFilesStrategy) {
496
+ strategies.push(smallFilesStrategy);
497
+ }
498
+
499
+ // Directory restructuring strategy
500
+ const restructureStrategy = this.generateRestructureDirectoriesStrategy();
501
+ if (restructureStrategy) {
502
+ strategies.push(restructureStrategy);
503
+ }
504
+
505
+ // Dependency optimization strategy
506
+ const optimizeStrategy = this.generateOptimizeDependenciesStrategy();
507
+ if (optimizeStrategy) {
508
+ strategies.push(optimizeStrategy);
509
+ }
510
+
511
+ return strategies;
512
+ }
513
+
514
+ /**
515
+ * Generate merge small files strategy
516
+ */
517
+ generateMergeSmallFilesStrategy() {
518
+ const smallFiles = this.findSmallFiles();
519
+
520
+ if (smallFiles.length < 2) {
521
+ return null;
522
+ }
523
+
524
+ const strategy = new RefactoringStrategy(
525
+ STRATEGY_TYPES.MERGE_SMALL_FILES,
526
+ 'multiple',
527
+ PRIORITY_LEVELS.LOW
528
+ );
529
+
530
+ strategy.description = `Merge ${smallFiles.length} small files into cohesive modules`;
531
+
532
+ // Group small files by package and type
533
+ const fileGroups = this.groupSmallFiles(smallFiles);
534
+
535
+ for (const [groupKey, files] of Object.entries(fileGroups)) {
536
+ strategy.addStep({
537
+ action: 'merge_files',
538
+ description: `Merge ${files.length} small files in ${groupKey}`,
539
+ command: 'merge-files',
540
+ target: files.map(f => f.path),
541
+ output: this.suggestMergedPath(files)
542
+ });
543
+ }
544
+
545
+ strategy.setEstimatedEffort(fileGroups.length * 2);
546
+ strategy.setRiskLevel('medium');
547
+ strategy.setImpact({
548
+ files: smallFiles.map(f => f.path),
549
+ lines: smallFiles.reduce((sum, f) => sum + f.lineCount, 0),
550
+ complexity: 'medium'
551
+ });
552
+
553
+ return strategy;
554
+ }
555
+
556
+ /**
557
+ * Generate restructure directories strategy
558
+ */
559
+ generateRestructureDirectoriesStrategy() {
560
+ // This would analyze directory structure and suggest improvements
561
+ // For now, return null as it's complex to implement
562
+ return null;
563
+ }
564
+
565
+ /**
566
+ * Generate optimize dependencies strategy
567
+ */
568
+ generateOptimizeDependenciesStrategy() {
569
+ // This would analyze dependencies and suggest optimizations
570
+ // For now, return null as it's complex to implement
571
+ return null;
572
+ }
573
+
574
+ /**
575
+ * Identify split points in a file
576
+ */
577
+ identifySplitPoints(fileAnalysis) {
578
+ const splitPoints = [];
579
+ const { boundaries } = fileAnalysis;
580
+
581
+ if (!boundaries) return splitPoints;
582
+
583
+ // Add large functions as split points
584
+ if (boundaries.functions) {
585
+ for (const func of boundaries.functions.filter(f => f.lineCount > 30)) {
586
+ splitPoints.push({
587
+ type: 'function',
588
+ name: func.name,
589
+ startLine: func.startLine,
590
+ endLine: func.endLine,
591
+ suggestedPath: this.suggestFunctionPath(fileAnalysis.filePath, func.name)
592
+ });
593
+ }
594
+ }
595
+
596
+ // Add large classes as split points
597
+ if (boundaries.classes) {
598
+ for (const cls of boundaries.classes.filter(c => c.lineCount > 100)) {
599
+ splitPoints.push({
600
+ type: 'class',
601
+ name: cls.name,
602
+ startLine: cls.startLine,
603
+ endLine: cls.endLine,
604
+ suggestedPath: this.suggestClassPath(fileAnalysis.filePath, cls.name)
605
+ });
606
+ }
607
+ }
608
+
609
+ // Add utility sections as split points
610
+ if (boundaries.utilities) {
611
+ for (const util of boundaries.utilities) {
612
+ splitPoints.push({
613
+ type: 'utility',
614
+ name: util.name,
615
+ startLine: util.startLine,
616
+ endLine: util.endLine,
617
+ suggestedPath: this.suggestUtilityPath(fileAnalysis.filePath, 'utils')
618
+ });
619
+ }
620
+ }
621
+
622
+ return splitPoints.sort((a, b) => a.startLine - b.startLine);
623
+ }
624
+
625
+ /**
626
+ * Suggest path for extracted function
627
+ */
628
+ suggestFunctionPath(originalPath, functionName) {
629
+ const dir = path.dirname(originalPath);
630
+ const name = functionName.toLowerCase();
631
+ return path.join(dir, `${name}.js`);
632
+ }
633
+
634
+ /**
635
+ * Suggest path for extracted class
636
+ */
637
+ suggestClassPath(originalPath, className) {
638
+ const dir = path.dirname(originalPath);
639
+ const name = className.toLowerCase();
640
+ return path.join(dir, `${name}.js`);
641
+ }
642
+
643
+ /**
644
+ * Suggest path for utilities
645
+ */
646
+ suggestUtilityPath(originalPath, utilityName) {
647
+ const dir = path.dirname(originalPath);
648
+ return path.join(dir, `${utilityName}.js`);
649
+ }
650
+
651
+ /**
652
+ * Suggest path for merged files
653
+ */
654
+ suggestMergedPath(files) {
655
+ const dir = path.dirname(files[0].path);
656
+ const name = 'merged-' + path.basename(files[0].path, '.js');
657
+ return path.join(dir, `${name}.js`);
658
+ }
659
+
660
+ /**
661
+ * Determine priority for file analysis
662
+ */
663
+ determinePriority(fileAnalysis) {
664
+ if (fileAnalysis.urgentRefactoring || fileAnalysis.lineCount > 800) {
665
+ return PRIORITY_LEVELS.CRITICAL;
666
+ }
667
+ if (fileAnalysis.needsRefactoring || fileAnalysis.lineCount > 555) {
668
+ return PRIORITY_LEVELS.HIGH;
669
+ }
670
+ if (fileAnalysis.lineCount > 300) {
671
+ return PRIORITY_LEVELS.MEDIUM;
672
+ }
673
+ return PRIORITY_LEVELS.LOW;
674
+ }
675
+
676
+ /**
677
+ * Estimate effort for file splitting
678
+ */
679
+ estimateSplitEffort(fileAnalysis, splitPoints) {
680
+ const baseEffort = 5; // Base effort for any split
681
+ const splitEffort = splitPoints.length * 2; // 2 effort per split point
682
+ const sizeEffort = Math.ceil(fileAnalysis.lineCount / 100); // 1 effort per 100 lines
683
+
684
+ return baseEffort + splitEffort + sizeEffort;
685
+ }
686
+
687
+ /**
688
+ * Assess risk of file splitting
689
+ */
690
+ assessSplitRisk(fileAnalysis) {
691
+ let risk = 'medium';
692
+
693
+ if (fileAnalysis.lineCount > 1000) {
694
+ risk = 'high';
695
+ } else if (fileAnalysis.lineCount < 300) {
696
+ risk = 'low';
697
+ }
698
+
699
+ // Consider complexity
700
+ if (fileAnalysis.categorization && fileAnalysis.categorization.complexity === 'VERY_COMPLEX') {
701
+ risk = 'high';
702
+ } else if (fileAnalysis.categorization && fileAnalysis.categorization.complexity === 'SIMPLE') {
703
+ risk = 'low';
704
+ }
705
+
706
+ return risk;
707
+ }
708
+
709
+ /**
710
+ * Find small files that could be merged
711
+ */
712
+ findSmallFiles() {
713
+ if (!this.analysisResults || !this.analysisResults.files) {
714
+ return [];
715
+ }
716
+
717
+ return this.analysisResults.files.filter(file =>
718
+ file.lineCount < 50 && file.lineCount > 5 // Not too small
719
+ );
720
+ }
721
+
722
+ /**
723
+ * Group small files for merging
724
+ */
725
+ groupSmallFiles(smallFiles) {
726
+ const groups = {};
727
+
728
+ for (const file of smallFiles) {
729
+ const pkg = this.extractPackage(file.path);
730
+ const type = this.extractFileType(file.path);
731
+ const key = `${pkg}/${type}`;
732
+
733
+ if (!groups[key]) {
734
+ groups[key] = [];
735
+ }
736
+ groups[key].push(file);
737
+ }
738
+
739
+ return groups;
740
+ }
741
+
742
+ /**
743
+ * Extract package from file path
744
+ */
745
+ extractPackage(filePath) {
746
+ const match = filePath.match(/packages\/([^\/]+)/);
747
+ return match ? match[1] : 'root';
748
+ }
749
+
750
+ /**
751
+ * Extract file type from path
752
+ */
753
+ extractFileType(filePath) {
754
+ const basename = path.basename(filePath, path.extname(filePath));
755
+ return basename.includes('test') ? 'test' :
756
+ basename.includes('util') ? 'utility' : 'main';
757
+ }
758
+
759
+ /**
760
+ * Prioritize strategies
761
+ */
762
+ prioritizeStrategies() {
763
+ const priorityOrder = {
764
+ [PRIORITY_LEVELS.CRITICAL]: 0,
765
+ [PRIORITY_LEVELS.HIGH]: 1,
766
+ [PRIORITY_LEVELS.MEDIUM]: 2,
767
+ [PRIORITY_LEVELS.LOW]: 3
768
+ };
769
+
770
+ this.strategies.sort((a, b) => {
771
+ return priorityOrder[a.priority] - priorityOrder[b.priority];
772
+ });
773
+ }
774
+
775
+ /**
776
+ * Get execution plan
777
+ */
778
+ getExecutionPlan() {
779
+ const plan = {
780
+ phases: [],
781
+ summary: {
782
+ totalStrategies: this.strategies.length,
783
+ criticalStrategies: this.strategies.filter(s => s.priority === PRIORITY_LEVELS.CRITICAL).length,
784
+ highStrategies: this.strategies.filter(s => s.priority === PRIORITY_LEVELS.HIGH).length,
785
+ totalEffort: this.strategies.reduce((sum, s) => sum + s.estimatedEffort, 0)
786
+ }
787
+ };
788
+
789
+ // Group strategies by priority into phases
790
+ const phases = [
791
+ { name: 'Critical Refactoring', priority: PRIORITY_LEVELS.CRITICAL, strategies: [] },
792
+ { name: 'High Priority Refactoring', priority: PRIORITY_LEVELS.HIGH, strategies: [] },
793
+ { name: 'Medium Priority Refactoring', priority: PRIORITY_LEVELS.MEDIUM, strategies: [] },
794
+ { name: 'Low Priority Optimizations', priority: PRIORITY_LEVELS.LOW, strategies: [] }
795
+ ];
796
+
797
+ for (const strategy of this.strategies) {
798
+ const phase = phases.find(p => p.priority === strategy.priority);
799
+ if (phase) {
800
+ phase.strategies.push(strategy);
801
+ }
802
+ }
803
+
804
+ plan.phases = phases.filter(phase => phase.strategies.length > 0);
805
+ return plan;
806
+ }
807
+ }
808
+
809
+ module.exports = {
810
+ StrategyGenerator,
811
+ RefactoringStrategy,
812
+ STRATEGY_TYPES,
813
+ PRIORITY_LEVELS
814
+ };