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,770 @@
1
+ /**
2
+ * Refactoring Plan Data Model
3
+ *
4
+ * Comprehensive data model for refactoring plans and strategies.
5
+ * Provides structure for storing and managing refactoring operations.
6
+ */
7
+
8
+ const path = require('path');
9
+
10
+ /**
11
+ * Refactoring operation class
12
+ */
13
+ class RefactoringOperation {
14
+ constructor(type, targetPath, options = {}) {
15
+ this.id = this.generateId();
16
+ this.type = type;
17
+ this.targetPath = targetPath;
18
+ this.options = options;
19
+ this.status = 'pending';
20
+ this.priority = 'medium';
21
+ this.estimatedEffort = 0;
22
+ this.riskLevel = 'medium';
23
+ this.dependencies = [];
24
+ this.outputs = [];
25
+ this.steps = [];
26
+ this.metadata = {
27
+ createdAt: new Date().toISOString(),
28
+ updatedAt: new Date().toISOString(),
29
+ version: '1.0.0'
30
+ };
31
+ this.results = null;
32
+ this.errors = [];
33
+ this.warnings = [];
34
+ }
35
+
36
+ generateId() {
37
+ return `op_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
38
+ }
39
+
40
+ /**
41
+ * Add step to operation
42
+ */
43
+ addStep(step) {
44
+ this.steps.push({
45
+ ...step,
46
+ id: this.generateStepId(),
47
+ status: 'pending',
48
+ createdAt: new Date().toISOString()
49
+ });
50
+ this.metadata.updatedAt = new Date().toISOString();
51
+ }
52
+
53
+ generateStepId() {
54
+ return `step_${Date.now()}_${Math.random().toString(36).substr(2, 5)}`;
55
+ }
56
+
57
+ /**
58
+ * Add dependency
59
+ */
60
+ addDependency(operationId) {
61
+ if (!this.dependencies.includes(operationId)) {
62
+ this.dependencies.push(operationId);
63
+ }
64
+ }
65
+
66
+ /**
67
+ * Add output
68
+ */
69
+ addOutput(outputPath) {
70
+ if (!this.outputs.includes(outputPath)) {
71
+ this.outputs.push(outputPath);
72
+ }
73
+ }
74
+
75
+ /**
76
+ * Set status
77
+ */
78
+ setStatus(status) {
79
+ this.status = status;
80
+ this.metadata.updatedAt = new Date().toISOString();
81
+ }
82
+
83
+ /**
84
+ * Set results
85
+ */
86
+ setResults(results) {
87
+ this.results = results;
88
+ this.metadata.updatedAt = new Date().toISOString();
89
+ }
90
+
91
+ /**
92
+ * Add error
93
+ */
94
+ addError(message, details = null) {
95
+ this.errors.push({
96
+ message,
97
+ details,
98
+ timestamp: new Date().toISOString()
99
+ });
100
+ }
101
+
102
+ /**
103
+ * Add warning
104
+ */
105
+ addWarning(message, details = null) {
106
+ this.warnings.push({
107
+ message,
108
+ details,
109
+ timestamp: new Date().toISOString()
110
+ });
111
+ }
112
+
113
+ /**
114
+ * Check if operation is ready to execute
115
+ */
116
+ isReady(dependencies) {
117
+ if (this.status !== 'pending') return false;
118
+
119
+ for (const depId of this.dependencies) {
120
+ const dep = dependencies.get(depId);
121
+ if (!dep || dep.status !== 'completed') {
122
+ return false;
123
+ }
124
+ }
125
+
126
+ return true;
127
+ }
128
+
129
+ /**
130
+ * Get execution summary
131
+ */
132
+ getSummary() {
133
+ return {
134
+ id: this.id,
135
+ type: this.type,
136
+ targetPath: this.targetPath,
137
+ status: this.status,
138
+ priority: this.priority,
139
+ estimatedEffort: this.estimatedEffort,
140
+ riskLevel: this.riskLevel,
141
+ stepCount: this.steps.length,
142
+ dependencyCount: this.dependencies.length,
143
+ outputCount: this.outputs.length,
144
+ errorCount: this.errors.length,
145
+ warningCount: this.warnings.length
146
+ };
147
+ }
148
+ }
149
+
150
+ /**
151
+ * Refactoring phase class
152
+ */
153
+ class RefactoringPhase {
154
+ constructor(name, priority = 'medium') {
155
+ this.id = this.generateId();
156
+ this.name = name;
157
+ this.priority = priority;
158
+ this.operations = [];
159
+ this.status = 'pending';
160
+ this.metadata = {
161
+ createdAt: new Date().toISOString(),
162
+ startedAt: null,
163
+ completedAt: null,
164
+ version: '1.0.0'
165
+ };
166
+ this.results = null;
167
+ }
168
+
169
+ generateId() {
170
+ return `phase_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
171
+ }
172
+
173
+ /**
174
+ * Add operation to phase
175
+ */
176
+ addOperation(operation) {
177
+ if (!(operation instanceof RefactoringOperation)) {
178
+ throw new Error('Operation must be a RefactoringOperation instance');
179
+ }
180
+
181
+ this.operations.push(operation);
182
+ }
183
+
184
+ /**
185
+ * Get operations by status
186
+ */
187
+ getOperationsByStatus(status) {
188
+ return this.operations.filter(op => op.status === status);
189
+ }
190
+
191
+ /**
192
+ * Get completed operations
193
+ */
194
+ getCompletedOperations() {
195
+ return this.getOperationsByStatus('completed');
196
+ }
197
+
198
+ /**
199
+ * Get failed operations
200
+ */
201
+ getFailedOperations() {
202
+ return this.getOperationsByStatus('failed');
203
+ }
204
+
205
+ /**
206
+ * Get pending operations
207
+ */
208
+ getPendingOperations() {
209
+ return this.getOperationsByStatus('pending');
210
+ }
211
+
212
+ /**
213
+ * Start phase
214
+ */
215
+ start() {
216
+ this.status = 'in_progress';
217
+ this.metadata.startedAt = new Date().toISOString();
218
+ }
219
+
220
+ /**
221
+ * Complete phase
222
+ */
223
+ complete(results = null) {
224
+ this.status = 'completed';
225
+ this.metadata.completedAt = new Date().toISOString();
226
+ this.results = results;
227
+ }
228
+
229
+ /**
230
+ * Fail phase
231
+ */
232
+ fail(error) {
233
+ this.status = 'failed';
234
+ this.metadata.completedAt = new Date().toISOString();
235
+ this.results = { error };
236
+ }
237
+
238
+ /**
239
+ * Get progress percentage
240
+ */
241
+ getProgress() {
242
+ if (this.operations.length === 0) return 0;
243
+
244
+ const completed = this.getCompletedOperations().length;
245
+ return Math.round((completed / this.operations.length) * 100);
246
+ }
247
+
248
+ /**
249
+ * Get summary
250
+ */
251
+ getSummary() {
252
+ const completed = this.getCompletedOperations().length;
253
+ const failed = this.getFailedOperations().length;
254
+ const pending = this.getPendingOperations().length;
255
+
256
+ return {
257
+ id: this.id,
258
+ name: this.name,
259
+ priority: this.priority,
260
+ status: this.status,
261
+ operationCount: this.operations.length,
262
+ completedOperations: completed,
263
+ failedOperations: failed,
264
+ pendingOperations: pending,
265
+ progress: this.getProgress(),
266
+ estimatedEffort: this.operations.reduce((sum, op) => sum + op.estimatedEffort, 0)
267
+ };
268
+ }
269
+ }
270
+
271
+ /**
272
+ * Refactoring plan class
273
+ */
274
+ class RefactoringPlan {
275
+ constructor(name, description = '') {
276
+ this.id = this.generateId();
277
+ this.name = name;
278
+ this.description = description;
279
+ this.phases = [];
280
+ this.status = 'draft';
281
+ this.metadata = {
282
+ createdAt: new Date().toISOString(),
283
+ updatedAt: new Date().toISOString(),
284
+ version: '1.0.0',
285
+ createdBy: 'system',
286
+ targetFiles: [],
287
+ analysisResults: null
288
+ };
289
+ this.results = null;
290
+ this.rollbackPlan = null;
291
+ }
292
+
293
+ generateId() {
294
+ return `plan_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
295
+ }
296
+
297
+ /**
298
+ * Add phase to plan
299
+ */
300
+ addPhase(phase) {
301
+ if (!(phase instanceof RefactoringPhase)) {
302
+ throw new Error('Phase must be a RefactoringPhase instance');
303
+ }
304
+
305
+ this.phases.push(phase);
306
+ this.metadata.updatedAt = new Date().toISOString();
307
+ }
308
+
309
+ /**
310
+ * Get phase by ID
311
+ */
312
+ getPhase(phaseId) {
313
+ return this.phases.find(phase => phase.id === phaseId);
314
+ }
315
+
316
+ /**
317
+ * Get phases by status
318
+ */
319
+ getPhasesByStatus(status) {
320
+ return this.phases.filter(phase => phase.status === status);
321
+ }
322
+
323
+ /**
324
+ * Get current phase
325
+ */
326
+ getCurrentPhase() {
327
+ return this.phases.find(phase => phase.status === 'in_progress');
328
+ }
329
+
330
+ /**
331
+ * Get next phase
332
+ */
333
+ getNextPhase() {
334
+ const currentIndex = this.phases.findIndex(phase => phase.status === 'in_progress');
335
+ if (currentIndex >= 0 && currentIndex < this.phases.length - 1) {
336
+ return this.phases[currentIndex + 1];
337
+ }
338
+
339
+ // If no current phase, return first pending phase
340
+ return this.phases.find(phase => phase.status === 'pending');
341
+ }
342
+
343
+ /**
344
+ * Start plan execution
345
+ */
346
+ start() {
347
+ if (this.phases.length === 0) {
348
+ throw new Error('Cannot start plan with no phases');
349
+ }
350
+
351
+ this.status = 'in_progress';
352
+ this.metadata.updatedAt = new Date().toISOString();
353
+
354
+ // Start first phase
355
+ const firstPhase = this.phases[0];
356
+ firstPhase.start();
357
+ }
358
+
359
+ /**
360
+ * Complete plan
361
+ */
362
+ complete(results = null) {
363
+ this.status = 'completed';
364
+ this.metadata.updatedAt = new Date().toISOString();
365
+ this.results = results;
366
+ }
367
+
368
+ /**
369
+ * Fail plan
370
+ */
371
+ fail(error) {
372
+ this.status = 'failed';
373
+ this.metadata.updatedAt = new Date().toISOString();
374
+ this.results = { error };
375
+ }
376
+
377
+ /**
378
+ * Pause plan
379
+ */
380
+ pause() {
381
+ this.status = 'paused';
382
+ this.metadata.updatedAt = new Date().toISOString();
383
+ }
384
+
385
+ /**
386
+ * Resume plan
387
+ */
388
+ resume() {
389
+ this.status = 'in_progress';
390
+ this.metadata.updatedAt = new Date().toISOString();
391
+ }
392
+
393
+ /**
394
+ * Get overall progress
395
+ */
396
+ getProgress() {
397
+ if (this.phases.length === 0) return 0;
398
+
399
+ const totalOperations = this.phases.reduce((sum, phase) => sum + phase.operations.length, 0);
400
+ if (totalOperations === 0) return 0;
401
+
402
+ const completedOperations = this.phases.reduce(
403
+ (sum, phase) => sum + phase.getCompletedOperations().length,
404
+ 0
405
+ );
406
+
407
+ return Math.round((completedOperations / totalOperations) * 100);
408
+ }
409
+
410
+ /**
411
+ * Get total estimated effort
412
+ */
413
+ getTotalEffort() {
414
+ return this.phases.reduce((sum, phase) =>
415
+ sum + phase.operations.reduce((phaseSum, op) => phaseSum + op.estimatedEffort, 0),
416
+ 0
417
+ );
418
+ }
419
+
420
+ /**
421
+ * Get all operations
422
+ */
423
+ getAllOperations() {
424
+ return this.phases.flatMap(phase => phase.operations);
425
+ }
426
+
427
+ /**
428
+ * Get operations by status
429
+ */
430
+ getOperationsByStatus(status) {
431
+ return this.getAllOperations().filter(op => op.status === status);
432
+ }
433
+
434
+ /**
435
+ * Get operations by type
436
+ */
437
+ getOperationsByType(type) {
438
+ return this.getAllOperations().filter(op => op.type === type);
439
+ }
440
+
441
+ /**
442
+ * Get operations by priority
443
+ */
444
+ getOperationsByPriority(priority) {
445
+ return this.getAllOperations().filter(op => op.priority === priority);
446
+ }
447
+
448
+ /**
449
+ * Get high risk operations
450
+ */
451
+ getHighRiskOperations() {
452
+ return this.getAllOperations().filter(op => op.riskLevel === 'high' || op.riskLevel === 'critical');
453
+ }
454
+
455
+ /**
456
+ * Validate plan
457
+ */
458
+ validate() {
459
+ const issues = [];
460
+
461
+ // Check if plan has phases
462
+ if (this.phases.length === 0) {
463
+ issues.push('Plan must have at least one phase');
464
+ }
465
+
466
+ // Check if phases have operations
467
+ for (const phase of this.phases) {
468
+ if (phase.operations.length === 0) {
469
+ issues.push(`Phase "${phase.name}" has no operations`);
470
+ }
471
+ }
472
+
473
+ // Check operation dependencies
474
+ const allOperations = this.getAllOperations();
475
+ for (const operation of allOperations) {
476
+ for (const depId of operation.dependencies) {
477
+ const dep = allOperations.find(op => op.id === depId);
478
+ if (!dep) {
479
+ issues.push(`Operation "${operation.id}" has invalid dependency: ${depId}`);
480
+ }
481
+ }
482
+ }
483
+
484
+ // Check for circular dependencies
485
+ const circularDeps = this.detectCircularDependencies();
486
+ if (circularDeps.length > 0) {
487
+ issues.push(`Circular dependencies detected: ${circularDeps.join(', ')}`);
488
+ }
489
+
490
+ return {
491
+ isValid: issues.length === 0,
492
+ issues
493
+ };
494
+ }
495
+
496
+ /**
497
+ * Detect circular dependencies
498
+ */
499
+ detectCircularDependencies() {
500
+ const operations = this.getAllOperations();
501
+ const visited = new Set();
502
+ const recursionStack = new Set();
503
+ const cycles = [];
504
+
505
+ function dfs(operationId, path) {
506
+ if (recursionStack.has(operationId)) {
507
+ const cycleStart = path.indexOf(operationId);
508
+ cycles.push(path.slice(cycleStart).concat(operationId).join(' -> '));
509
+ return;
510
+ }
511
+
512
+ if (visited.has(operationId)) return;
513
+
514
+ visited.add(operationId);
515
+ recursionStack.add(operationId);
516
+
517
+ const operation = operations.find(op => op.id === operationId);
518
+ if (operation) {
519
+ for (const depId of operation.dependencies) {
520
+ dfs(depId, path.concat(operationId));
521
+ }
522
+ }
523
+
524
+ recursionStack.delete(operationId);
525
+ }
526
+
527
+ for (const operation of operations) {
528
+ if (!visited.has(operation.id)) {
529
+ dfs(operation.id, []);
530
+ }
531
+ }
532
+
533
+ return cycles;
534
+ }
535
+
536
+ /**
537
+ * Get execution order
538
+ */
539
+ getExecutionOrder() {
540
+ const operations = this.getAllOperations();
541
+ const visited = new Set();
542
+ const order = [];
543
+
544
+ function visit(operation) {
545
+ if (visited.has(operation.id)) return;
546
+
547
+ // Visit dependencies first
548
+ for (const depId of operation.dependencies) {
549
+ const dep = operations.find(op => op.id === depId);
550
+ if (dep) {
551
+ visit(dep);
552
+ }
553
+ }
554
+
555
+ visited.add(operation.id);
556
+ order.push(operation);
557
+ }
558
+
559
+ for (const operation of operations) {
560
+ if (!visited.has(operation.id)) {
561
+ visit(operation);
562
+ }
563
+ }
564
+
565
+ return order;
566
+ }
567
+
568
+ /**
569
+ * Get summary
570
+ */
571
+ getSummary() {
572
+ const allOperations = this.getAllOperations();
573
+ const completed = this.getOperationsByStatus('completed').length;
574
+ const failed = this.getOperationsByStatus('failed').length;
575
+ const pending = this.getOperationsByStatus('pending').length;
576
+ const inProgress = this.getOperationsByStatus('in_progress').length;
577
+
578
+ return {
579
+ id: this.id,
580
+ name: this.name,
581
+ description: this.description,
582
+ status: this.status,
583
+ phaseCount: this.phases.length,
584
+ operationCount: allOperations.length,
585
+ completedOperations: completed,
586
+ failedOperations: failed,
587
+ pendingOperations: pending,
588
+ inProgressOperations: inProgress,
589
+ progress: this.getProgress(),
590
+ totalEffort: this.getTotalEffort(),
591
+ highRiskOperations: this.getHighRiskOperations().length,
592
+ targetFiles: this.metadata.targetFiles.length,
593
+ createdAt: this.metadata.createdAt,
594
+ updatedAt: this.metadata.updatedAt
595
+ };
596
+ }
597
+
598
+ /**
599
+ * Convert to JSON
600
+ */
601
+ toJSON() {
602
+ return {
603
+ id: this.id,
604
+ name: this.name,
605
+ description: this.description,
606
+ status: this.status,
607
+ phases: this.phases.map(phase => ({
608
+ ...phase,
609
+ operations: phase.operations.map(op => op.getSummary())
610
+ })),
611
+ metadata: this.metadata,
612
+ results: this.results,
613
+ rollbackPlan: this.rollbackPlan
614
+ };
615
+ }
616
+
617
+ /**
618
+ * Create from JSON
619
+ */
620
+ static fromJSON(data) {
621
+ const plan = new RefactoringPlan(data.name, data.description);
622
+
623
+ plan.id = data.id;
624
+ plan.status = data.status;
625
+ plan.metadata = { ...plan.metadata, ...data.metadata };
626
+ plan.results = data.results;
627
+ plan.rollbackPlan = data.rollbackPlan;
628
+
629
+ // Recreate phases and operations
630
+ for (const phaseData of data.phases) {
631
+ const phase = new RefactoringPhase(phaseData.name, phaseData.priority);
632
+ phase.id = phaseData.id;
633
+ phase.status = phaseData.status;
634
+ phase.metadata = { ...phase.metadata, ...phaseData.metadata };
635
+ phase.results = phaseData.results;
636
+
637
+ for (const opData of phaseData.operations) {
638
+ const operation = new RefactoringOperation(opData.type, opData.targetPath, opData.options);
639
+ operation.id = opData.id;
640
+ operation.status = opData.status;
641
+ operation.priority = opData.priority;
642
+ operation.estimatedEffort = opData.estimatedEffort;
643
+ operation.riskLevel = opData.riskLevel;
644
+ operation.dependencies = opData.dependencies;
645
+ operation.outputs = opData.outputs;
646
+ operation.results = opData.results;
647
+ operation.errors = opData.errors;
648
+ operation.warnings = opData.warnings;
649
+ operation.metadata = { ...operation.metadata, ...opData.metadata };
650
+
651
+ phase.addOperation(operation);
652
+ }
653
+
654
+ plan.addPhase(phase);
655
+ }
656
+
657
+ return plan;
658
+ }
659
+ }
660
+
661
+ /**
662
+ * Refactoring plan collection class
663
+ */
664
+ class RefactoringPlanCollection {
665
+ constructor() {
666
+ this.plans = new Map();
667
+ this.metadata = {
668
+ createdAt: new Date().toISOString(),
669
+ version: '1.0.0',
670
+ totalPlans: 0
671
+ };
672
+ }
673
+
674
+ /**
675
+ * Add plan
676
+ */
677
+ add(plan) {
678
+ if (!(plan instanceof RefactoringPlan)) {
679
+ throw new Error('Plan must be a RefactoringPlan instance');
680
+ }
681
+
682
+ this.plans.set(plan.id, plan);
683
+ this.updateMetadata();
684
+ }
685
+
686
+ /**
687
+ * Get plan by ID
688
+ */
689
+ get(planId) {
690
+ return this.plans.get(planId);
691
+ }
692
+
693
+ /**
694
+ * Remove plan
695
+ */
696
+ remove(planId) {
697
+ const removed = this.plans.delete(planId);
698
+ if (removed) {
699
+ this.updateMetadata();
700
+ }
701
+ return removed;
702
+ }
703
+
704
+ /**
705
+ * Get all plans
706
+ */
707
+ getAll() {
708
+ return Array.from(this.plans.values());
709
+ }
710
+
711
+ /**
712
+ * Get plans by status
713
+ */
714
+ getByStatus(status) {
715
+ return this.getAll().filter(plan => plan.status === status);
716
+ }
717
+
718
+ /**
719
+ * Get active plans
720
+ */
721
+ getActive() {
722
+ return this.getAll().filter(plan =>
723
+ plan.status === 'in_progress' || plan.status === 'paused'
724
+ );
725
+ }
726
+
727
+ /**
728
+ * Get completed plans
729
+ */
730
+ getCompleted() {
731
+ return this.getByStatus('completed');
732
+ }
733
+
734
+ /**
735
+ * Get failed plans
736
+ */
737
+ getFailed() {
738
+ return this.getByStatus('failed');
739
+ }
740
+
741
+ /**
742
+ * Update metadata
743
+ */
744
+ updateMetadata() {
745
+ this.metadata.totalPlans = this.plans.size;
746
+ }
747
+
748
+ /**
749
+ * Get summary statistics
750
+ */
751
+ getSummary() {
752
+ const plans = this.getAll();
753
+
754
+ return {
755
+ totalPlans: plans.length,
756
+ activePlans: this.getActive().length,
757
+ completedPlans: this.getCompleted().length,
758
+ failedPlans: this.getFailed().length,
759
+ totalOperations: plans.reduce((sum, plan) => sum + plan.getAllOperations().length, 0),
760
+ totalEffort: plans.reduce((sum, plan) => sum + plan.getTotalEffort(), 0)
761
+ };
762
+ }
763
+ }
764
+
765
+ module.exports = {
766
+ RefactoringPlan,
767
+ RefactoringPhase,
768
+ RefactoringOperation,
769
+ RefactoringPlanCollection
770
+ };