vibecodingmachine-core 2026.2.26-1739 → 2026.3.9-850

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 (192) hide show
  1. package/package.json +1 -1
  2. package/src/agents/AgentCheckDiscoveryService.js +180 -0
  3. package/src/agents/AgentCheckService.js +18 -261
  4. package/src/agents/AgentCheckStatisticsService.js +195 -0
  5. package/src/agents/EnvironmentConfigurationManager.js +31 -380
  6. package/src/agents/InstallationType.js +19 -6
  7. package/src/agents/SimpleAgentCheckService.js +472 -0
  8. package/src/agents/config-managers/ConfigUtils.js +72 -0
  9. package/src/agents/config-managers/DefaultConfig.js +58 -0
  10. package/src/agents/config-managers/EnvVarLoader.js +66 -0
  11. package/src/agents/config-managers/FileConfigLoader.js +124 -0
  12. package/src/agents/config-managers/TypeConverters.js +61 -0
  13. package/src/agents/config-managers/VariableMappings.js +92 -0
  14. package/src/agents/discovery/AgentDiscoveryService-refactored.js +272 -0
  15. package/src/agents/discovery/AgentDiscoveryService.js +29 -403
  16. package/src/agents/discovery/agent-validator.js +262 -0
  17. package/src/agents/discovery/discovery-results.js +176 -0
  18. package/src/agents/discovery/discovery-scanner.js +268 -0
  19. package/src/agents/discovery/discovery-utils.js +161 -0
  20. package/src/agents/discovery/executable-analyzer.js +290 -0
  21. package/src/agents/discovery/history-manager.js +310 -0
  22. package/src/agents/verification/ResultAnalyzer-refactored.js +341 -0
  23. package/src/agents/verification/ResultAnalyzer.js +30 -431
  24. package/src/agents/verification/analysis-utils.js +310 -0
  25. package/src/agents/verification/batch-analyzer.js +440 -0
  26. package/src/agents/verification/pattern-recognizer.js +369 -0
  27. package/src/agents/verification/report-generator.js +320 -0
  28. package/src/agents/verification/test-analyzer.js +290 -0
  29. package/src/agents/windows/InstallerFactory.js +4 -0
  30. package/src/agents/windows/VSCodeExtensionInstaller.js +404 -0
  31. package/src/analysis/analysis-engine.js +314 -0
  32. package/src/analysis/ast-analyzer.js +342 -0
  33. package/src/analysis/boundary-detector-refactored.js +378 -0
  34. package/src/analysis/boundary-detector.js +200 -603
  35. package/src/analysis/boundary-scanner.js +609 -0
  36. package/src/analysis/boundary-types.js +118 -0
  37. package/src/analysis/boundary-utils.js +293 -0
  38. package/src/analysis/deadline-priority-calculator.js +18 -0
  39. package/src/analysis/detection-methods.js +347 -0
  40. package/src/analysis/importance-priority-calculator.js +18 -0
  41. package/src/analysis/priority/factor-calculators.js +204 -0
  42. package/src/analysis/priority/factor-helpers.js +71 -0
  43. package/src/analysis/priority/priority-constants.js +73 -0
  44. package/src/analysis/priority/priority-factor-calculators.js +301 -0
  45. package/src/analysis/priority/reasons-generator.js +44 -0
  46. package/src/analysis/priority-calculator.js +15 -580
  47. package/src/analysis/strategy-generator.js +16 -66
  48. package/src/analysis/type-priority-calculator.js +18 -0
  49. package/src/analysis/urgency-priority-calculator.js +18 -0
  50. package/src/auto-mode/AutoModeBusinessLogic.js +2 -40
  51. package/src/commands/disable-requirement.js +60 -0
  52. package/src/commands/disable-spec.js +60 -0
  53. package/src/commands/enable-requirement.js +60 -0
  54. package/src/commands/enable-spec.js +60 -0
  55. package/src/commands/registry.js +1 -6
  56. package/src/commands/requirements.js +8 -2
  57. package/src/ide-integration/applescript-manager.cjs +9 -24
  58. package/src/ide-integration/cdp-handlers/chat-reader.js +44 -0
  59. package/src/ide-integration/cdp-handlers/connection-handler.js +88 -0
  60. package/src/ide-integration/cdp-handlers/continuation-handler.js +314 -0
  61. package/src/ide-integration/cdp-handlers/message-submitter.js +75 -0
  62. package/src/ide-integration/cdp-handlers/text-sender.js +138 -0
  63. package/src/ide-integration/cdp-manager.js +28 -573
  64. package/src/ide-integration/claude-code-cli-manager.cjs +48 -12
  65. package/src/ide-integration/ide-openers/claude-opener.js +171 -0
  66. package/src/ide-integration/ide-openers/cursor-opener.js +53 -0
  67. package/src/ide-integration/ide-openers/other-ides-opener.js +230 -0
  68. package/src/ide-integration/ide-openers/vscode-opener.js +147 -0
  69. package/src/ide-integration/macos-ide-manager.js +20 -582
  70. package/src/ide-integration/macos-quota-checker.js +164 -0
  71. package/src/ide-integration/macos-text-sender.js +19 -38
  72. package/src/ide-integration/provider-manager.cjs +52 -7
  73. package/src/index.cjs +6 -0
  74. package/src/index.js +10 -0
  75. package/src/llm/direct-llm-manager.cjs +501 -0
  76. package/src/localization/translations/en-part1.js +363 -0
  77. package/src/localization/translations/en-part2.js +320 -0
  78. package/src/localization/translations/en.js +4 -687
  79. package/src/localization/translations/es-part1.js +363 -0
  80. package/src/localization/translations/es-part2.js +320 -0
  81. package/src/localization/translations/es.js +4 -688
  82. package/src/models/file-analysis-collection.js +139 -0
  83. package/src/models/file-analysis-metrics.js +50 -0
  84. package/src/models/file-analysis.js +15 -262
  85. package/src/models/plan-manager.js +410 -0
  86. package/src/models/refactoring-models.js +380 -0
  87. package/src/models/refactoring-plan-refactored.js +81 -0
  88. package/src/models/refactoring-plan.js +2 -663
  89. package/src/monitoring/alert-system.js +4 -45
  90. package/src/monitoring/continuous-scan-notifications.js +37 -191
  91. package/src/monitoring/notification-handlers/base-handler.js +58 -0
  92. package/src/monitoring/notification-handlers/error-handler.js +36 -0
  93. package/src/monitoring/notification-handlers/index.js +21 -0
  94. package/src/monitoring/notification-handlers/new-violation-handler.js +91 -0
  95. package/src/monitoring/notification-handlers/progress-handler.js +48 -0
  96. package/src/monitoring/notification-handlers/resolved-violation-handler.js +54 -0
  97. package/src/monitoring/notification-handlers/threshold-handler.js +36 -0
  98. package/src/provider-registry.js +8 -0
  99. package/src/refactoring/boundary/boundary-detector-refactored.js +58 -0
  100. package/src/refactoring/boundary/boundary-detector.js +26 -596
  101. package/src/refactoring/boundary/detectors/boundary-analyzers.js +281 -0
  102. package/src/refactoring/boundary/detectors/boundary-core.js +167 -0
  103. package/src/refactoring/boundary/detectors/class-detector.js +247 -0
  104. package/src/refactoring/boundary/detectors/config-detector.js +270 -0
  105. package/src/refactoring/boundary/detectors/constant-detector.js +269 -0
  106. package/src/refactoring/boundary/detectors/function-detector.js +248 -0
  107. package/src/refactoring/boundary/detectors/module-detector.js +249 -0
  108. package/src/refactoring/boundary/detectors/object-detector.js +247 -0
  109. package/src/refactoring/boundary/detectors/type-detectors.js +338 -0
  110. package/src/refactoring/boundary/detectors/utility-detector.js +270 -0
  111. package/src/refactoring/circular-dependency-resolver-original.js +16 -76
  112. package/src/refactoring/code-mover-refactored.js +309 -0
  113. package/src/refactoring/code-mover.js +48 -355
  114. package/src/refactoring/execution-status.js +18 -0
  115. package/src/refactoring/execution-strategies.js +172 -0
  116. package/src/refactoring/file-splitter-core.js +568 -0
  117. package/src/refactoring/file-splitter-types.js +136 -0
  118. package/src/refactoring/file-splitter.js +2 -682
  119. package/src/refactoring/functionality-validator.js +11 -51
  120. package/src/refactoring/import-manager-refactored.js +385 -0
  121. package/src/refactoring/import-manager.js +112 -487
  122. package/src/refactoring/import-models.js +189 -0
  123. package/src/refactoring/import-parser.js +306 -0
  124. package/src/refactoring/move-executor.js +431 -0
  125. package/src/refactoring/move-utils.js +368 -0
  126. package/src/refactoring/operation-executor.js +76 -0
  127. package/src/refactoring/plan-creator.js +36 -0
  128. package/src/refactoring/plan-executor.js +143 -0
  129. package/src/refactoring/plan-validator.js +68 -0
  130. package/src/refactoring/refactoring-executor-result.js +70 -0
  131. package/src/refactoring/refactoring-executor.js +34 -569
  132. package/src/refactoring/refactoring-operation.js +94 -0
  133. package/src/refactoring/refactoring-plan.js +69 -0
  134. package/src/refactoring/refactoring-rollback.js +22 -527
  135. package/src/refactoring/rollback-handlers/RollbackExecutor.js +107 -0
  136. package/src/refactoring/rollback-handlers/RollbackManager.js +265 -0
  137. package/src/refactoring/rollback-handlers/RollbackOperation.js +105 -0
  138. package/src/refactoring/rollback-handlers/RollbackResult.js +109 -0
  139. package/src/refactoring/rollback-handlers/RollbackStatistics.js +77 -0
  140. package/src/refactoring/test-validator.js +32 -448
  141. package/src/refactoring/validation/baseline-runner.js +71 -0
  142. package/src/refactoring/validation/report-generator.js +136 -0
  143. package/src/refactoring/validation/result-comparator.js +92 -0
  144. package/src/refactoring/validation/test-suite.js +59 -0
  145. package/src/refactoring/validation/test-validation-result.js +83 -0
  146. package/src/refactoring/validation/validation-runner.js +95 -0
  147. package/src/refactoring/validation/validation-status.js +18 -0
  148. package/src/rui/commands/AgentCommandParser.js +60 -369
  149. package/src/rui/commands/AgentResponseFormatter.js +7 -47
  150. package/src/rui/commands/parsers/CommandMapper.js +148 -0
  151. package/src/rui/commands/parsers/CommandValidator.js +228 -0
  152. package/src/rui/commands/parsers/ComponentExtractor.js +100 -0
  153. package/src/rui/commands/parsers/TokenParser.js +69 -0
  154. package/src/rui/commands/parsers/tokenizer.js +153 -0
  155. package/src/utils/current-requirement-operations.js +50 -1
  156. package/src/utils/report-generator.js +18 -514
  157. package/src/utils/report-generators/analysis-generator.js +115 -0
  158. package/src/utils/report-generators/base-generator.js +141 -0
  159. package/src/utils/report-generators/compliance-generator.js +41 -0
  160. package/src/utils/report-generators/format-handlers.js +185 -0
  161. package/src/utils/report-generators/refactoring-generator.js +46 -0
  162. package/src/utils/report-generators/validation-generator.js +63 -0
  163. package/src/utils/requirement-enable-disable.js +265 -0
  164. package/src/utils/requirement-helpers/requirement-file-ops.js +69 -1
  165. package/src/utils/requirement-helpers/requirement-mover.js +88 -1
  166. package/src/utils/requirement-helpers.js +5 -2
  167. package/src/utils/smoke-test-cli.js +45 -8
  168. package/src/utils/specification-enable-disable.js +122 -0
  169. package/src/utils/specification-helpers.js +30 -4
  170. package/src/utils/specification-migration.js +5 -5
  171. package/src/utils/test-comparator.js +118 -0
  172. package/src/utils/test-config.js +54 -0
  173. package/src/utils/test-executor.js +133 -0
  174. package/src/utils/test-parser.js +215 -0
  175. package/src/utils/test-runner-baseline.js +63 -0
  176. package/src/utils/test-runner-core.js +98 -0
  177. package/src/utils/test-runner-report.js +39 -0
  178. package/src/utils/test-runner-validation.js +71 -0
  179. package/src/utils/test-runner.js +11 -535
  180. package/src/validation/comparison-analyzer.js +333 -0
  181. package/src/validation/compliance-reporter-new.js +282 -0
  182. package/src/validation/compliance-reporter-refactored.js +344 -0
  183. package/src/validation/compliance-reporter.js +278 -591
  184. package/src/validation/compliance-utils.js +278 -0
  185. package/src/validation/html-generator.js +446 -0
  186. package/src/validation/metrics/category-calculator.js +137 -0
  187. package/src/validation/metrics/metrics-helpers.js +155 -0
  188. package/src/validation/metrics/overview-calculator.js +85 -0
  189. package/src/validation/metrics/overview-metrics.js +41 -0
  190. package/src/validation/metrics/quality-calculator.js +166 -0
  191. package/src/validation/metrics/size-calculator.js +69 -0
  192. package/src/validation/metrics-calculator.js +27 -551
@@ -0,0 +1,270 @@
1
+ /**
2
+ * Utility Boundary Detection
3
+ */
4
+
5
+ const { BOUNDARY_TYPES } = require('../boundary-types');
6
+
7
+ /**
8
+ * Utility boundary detector
9
+ */
10
+ class UtilityDetector {
11
+ constructor() {
12
+ this.patterns = this.initializePatterns();
13
+ }
14
+
15
+ /**
16
+ * Initialize detection patterns
17
+ * @returns {Object} Detection patterns
18
+ */
19
+ initializePatterns() {
20
+ return {
21
+ utility: [
22
+ /(?:const|let|var)\s+\w+\s*=\s*\([^)]*\)\s*=>/,
23
+ /function\s+(?:is|has|get|set|calculate|compute|parse|format|validate|check)/,
24
+ /(?:is|has|get|set|calculate|compute|parse|format|validate|check)\w+\s*\(/
25
+ ]
26
+ };
27
+ }
28
+
29
+ /**
30
+ * Detect utility boundaries
31
+ * @param {Array} lines - Source code lines
32
+ * @param {string} filePath - File path
33
+ * @returns {Array} Array of utility boundaries
34
+ */
35
+ detectUtilityBoundaries(lines, filePath) {
36
+ const boundaries = [];
37
+
38
+ // Look for utility function patterns
39
+ for (let i = 0; i < lines.length; i++) {
40
+ const line = lines[i].trim();
41
+
42
+ // Helper function patterns
43
+ if (this.isUtilityFunction(line)) {
44
+ const functionName = this.extractUtilityFunctionName(line);
45
+ if (functionName) {
46
+ const boundary = this.createBoundary(
47
+ BOUNDARY_TYPES.UTILITY,
48
+ functionName,
49
+ lines,
50
+ filePath,
51
+ i
52
+ );
53
+
54
+ if (boundary) {
55
+ boundaries.push(boundary);
56
+ }
57
+ }
58
+ }
59
+ }
60
+
61
+ return boundaries;
62
+ }
63
+
64
+ /**
65
+ * Check if line is a utility function
66
+ * @param {string} line - Code line
67
+ * @returns {boolean} Whether line is utility function
68
+ */
69
+ isUtilityFunction(line) {
70
+ return this.patterns.utility.some(pattern => pattern.test(line));
71
+ }
72
+
73
+ /**
74
+ * Extract utility function name
75
+ * @param {string} line - Code line
76
+ * @returns {string|null} Function name
77
+ */
78
+ extractUtilityFunctionName(line) {
79
+ const match = line.match(/(?:const|let|var)\s+(\w+)\s*=|function\s+(\w+)/);
80
+ return match ? match[1] || match[2] : null;
81
+ }
82
+
83
+ /**
84
+ * Create boundary from detection
85
+ * @param {string} type - Boundary type
86
+ * @param {string} name - Boundary name
87
+ * @param {Array} lines - Source code lines
88
+ * @param {string} filePath - File path
89
+ * @param {number} startIndex - Start index in source
90
+ * @returns {Object|null} Boundary object or null
91
+ */
92
+ createBoundary(type, name, lines, filePath, startIndex) {
93
+ const { startLine, endLine } = this.findBoundaryExtent(lines, startIndex, type);
94
+
95
+ if (startLine === -1 || endLine === -1) {
96
+ return null;
97
+ }
98
+
99
+ const { ModuleBoundary } = require('../boundary-types');
100
+ const boundary = new ModuleBoundary(type, name, startLine + 1, endLine + 1, filePath);
101
+
102
+ // Basic analysis
103
+ this.analyzeBoundary(boundary, lines, startLine, endLine);
104
+
105
+ return boundary;
106
+ }
107
+
108
+ /**
109
+ * Find extent of a boundary
110
+ * @param {Array} lines - Source code lines
111
+ * @param {number} startIndex - Start index
112
+ * @param {string} type - Boundary type
113
+ * @returns {Object} Start and end line numbers
114
+ */
115
+ findBoundaryExtent(lines, startIndex, type) {
116
+ let startLine = -1;
117
+ let endLine = -1;
118
+ let braceCount = 0;
119
+ let inString = false;
120
+ let stringChar = null;
121
+
122
+ for (let i = startIndex; i < lines.length; i++) {
123
+ const line = lines[i];
124
+
125
+ // Track string literals
126
+ for (let j = 0; j < line.length; j++) {
127
+ const char = line[j];
128
+
129
+ if (!inString && (char === '"' || char === "'" || char === '`')) {
130
+ inString = true;
131
+ stringChar = char;
132
+ } else if (inString && char === stringChar) {
133
+ inString = false;
134
+ stringChar = null;
135
+ }
136
+ }
137
+
138
+ // Skip lines inside strings
139
+ if (inString) continue;
140
+
141
+ // Count braces for block detection
142
+ const openBraces = (line.match(/\{/g) || []).length;
143
+ const closeBraces = (line.match(/\}/g) || []).length;
144
+
145
+ braceCount += openBraces - closeBraces;
146
+
147
+ // Set start line on first detection
148
+ if (startLine === -1) {
149
+ startLine = i;
150
+ }
151
+
152
+ // End when braces are balanced and we're past start
153
+ if (braceCount <= 0 && i > startIndex) {
154
+ endLine = i;
155
+ break;
156
+ }
157
+ }
158
+
159
+ return { startLine, endLine };
160
+ }
161
+
162
+ /**
163
+ * Analyze boundary properties
164
+ * @param {Object} boundary - Boundary object
165
+ * @param {Array} lines - Source code lines
166
+ * @param {number} startLine - Start line number
167
+ * @param {number} endLine - End line number
168
+ */
169
+ analyzeBoundary(boundary, lines, startLine, endLine) {
170
+ const boundaryLines = lines.slice(startLine, endLine + 1);
171
+ const sourceCode = boundaryLines.join('\n');
172
+
173
+ // Calculate complexity
174
+ const complexity = this.calculateComplexity(sourceCode);
175
+ boundary.setComplexity(complexity);
176
+
177
+ // Find dependencies
178
+ const dependencies = this.findDependencies(sourceCode);
179
+ for (const dep of dependencies) {
180
+ boundary.addDependency(dep);
181
+ }
182
+
183
+ // Find exports
184
+ const exports = this.findExports(sourceCode, boundary.type);
185
+ for (const exp of exports) {
186
+ boundary.addExport(exp);
187
+ }
188
+ }
189
+
190
+ /**
191
+ * Calculate complexity score
192
+ * @param {string} sourceCode - Source code
193
+ * @returns {number} Complexity score
194
+ */
195
+ calculateComplexity(sourceCode) {
196
+ let complexity = 0;
197
+
198
+ // Cyclomatic complexity indicators
199
+ complexity += (sourceCode.match(/if\s*\(/g) || []).length * 1;
200
+ complexity += (sourceCode.match(/else\s+if/g) || []).length * 1;
201
+ complexity += (sourceCode.match(/while\s*\(/g) || []).length * 2;
202
+ complexity += (sourceCode.match(/for\s*\(/g) || []).length * 2;
203
+ complexity += (sourceCode.match(/switch\s*\(/g) || []).length * 2;
204
+ complexity += (sourceCode.match(/catch\s*\(/g) || []).length * 2;
205
+ complexity += (sourceCode.match(/&&/g) || []).length * 1;
206
+ complexity += (sourceCode.match(/\|\|/g) || []).length * 1;
207
+
208
+ // Length complexity
209
+ const lineCount = sourceCode.split('\n').length;
210
+ if (lineCount > 50) complexity += 5;
211
+ if (lineCount > 100) complexity += 10;
212
+ if (lineCount > 200) complexity += 20;
213
+
214
+ return Math.min(100, complexity);
215
+ }
216
+
217
+ /**
218
+ * Find dependencies in boundary
219
+ * @param {string} sourceCode - Source code
220
+ * @returns {Array} Array of dependencies
221
+ */
222
+ findDependencies(sourceCode) {
223
+ const dependencies = [];
224
+
225
+ // Import statements
226
+ const importMatches = sourceCode.match(/import\s+.+from\s+['"]([^'"]+)['"]/g);
227
+ if (importMatches) {
228
+ for (const match of importMatches) {
229
+ dependencies.push(match[1]);
230
+ }
231
+ }
232
+
233
+ // Require statements
234
+ const requireMatches = sourceCode.match(/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g);
235
+ if (requireMatches) {
236
+ for (const match of requireMatches) {
237
+ dependencies.push(match[1]);
238
+ }
239
+ }
240
+
241
+ return [...new Set(dependencies)];
242
+ }
243
+
244
+ /**
245
+ * Find exports in boundary
246
+ * @param {string} sourceCode - Source code
247
+ * @param {string} type - Boundary type
248
+ * @returns {Array} Array of exports
249
+ */
250
+ findExports(sourceCode, type) {
251
+ const exports = [];
252
+
253
+ if (type === BOUNDARY_TYPES.UTILITY) {
254
+ // Look for explicit exports
255
+ const exportMatches = sourceCode.match(/export\s+(?:default\s+)?(?:\w+|\{[^}]+\})/g);
256
+ if (exportMatches) {
257
+ for (const match of exportMatches) {
258
+ const exportName = match.replace(/export\s+(?:default\s+)?/, '').trim();
259
+ if (exportName && exportName !== '{' && exportName !== '}') {
260
+ exports.push(exportName);
261
+ }
262
+ }
263
+ }
264
+ }
265
+
266
+ return exports;
267
+ }
268
+ }
269
+
270
+ module.exports = UtilityDetector;
@@ -8,25 +8,8 @@
8
8
  const fs = require('fs');
9
9
  const path = require('path');
10
10
 
11
- /**
12
- * Dependency types
13
- */
14
- const DEPENDENCY_TYPES = {
15
- IMPORT: 'import',
16
- REQUIRE: 'require',
17
- DYNAMIC: 'dynamic',
18
- INDIRECT: 'indirect'
19
- };
20
-
21
- /**
22
- * Cycle severity levels
23
- */
24
- const CYCLE_SEVERITY = {
25
- LOW: 'low',
26
- MEDIUM: 'medium',
27
- HIGH: 'high',
28
- CRITICAL: 'critical'
29
- };
11
+ const DEPENDENCY_TYPES = { IMPORT: 'import', REQUIRE: 'require', DYNAMIC: 'dynamic', INDIRECT: 'indirect' };
12
+ const CYCLE_SEVERITY = { LOW: 'low', MEDIUM: 'medium', HIGH: 'high', CRITICAL: 'critical' };
30
13
 
31
14
  /**
32
15
  * Dependency node class
@@ -57,25 +40,11 @@ class DependencyNode {
57
40
  return match ? match[1] : 'root';
58
41
  }
59
42
 
60
- addDependency(filePath, type = DEPENDENCY_TYPES.IMPORT) {
61
- this.dependencies.add({ path: filePath, type });
62
- }
63
-
64
- addDependent(filePath) {
65
- this.dependents.add(filePath);
66
- }
67
-
68
- hasDependency(filePath) {
69
- return this.dependencies.has(filePath);
70
- }
71
-
72
- getDependencyCount() {
73
- return this.dependencies.size;
74
- }
75
-
76
- getDependentCount() {
77
- return this.dependents.size;
78
- }
43
+ addDependency(filePath, type = DEPENDENCY_TYPES.IMPORT) { this.dependencies.add({ path: filePath, type }); }
44
+ addDependent(filePath) { this.dependents.add(filePath); }
45
+ hasDependency(filePath) { return this.dependencies.has(filePath); }
46
+ getDependencyCount() { return this.dependencies.size; }
47
+ getDependentCount() { return this.dependents.size; }
79
48
  }
80
49
 
81
50
  /**
@@ -103,23 +72,16 @@ class CircularDependency {
103
72
 
104
73
  calculateImpact() {
105
74
  let impact = 0;
106
-
107
- // Impact based on cycle length
108
75
  impact += (6 - Math.min(this.length, 6)) * 10;
109
-
110
- // Impact based on file types
111
76
  for (const filePath of this.cycle) {
112
77
  if (filePath.includes('packages/core')) impact += 15;
113
78
  if (filePath.includes('packages/cli')) impact += 10;
114
79
  if (filePath.includes('packages/electron-app')) impact += 8;
115
80
  }
116
-
117
81
  return Math.min(100, impact);
118
82
  }
119
83
 
120
- setResolution(resolution) {
121
- this.resolution = resolution;
122
- }
84
+ setResolution(resolution) { this.resolution = resolution; }
123
85
 
124
86
  getSummary() {
125
87
  return {
@@ -146,13 +108,8 @@ class ResolutionStrategy {
146
108
  this.applicable = true;
147
109
  }
148
110
 
149
- addStep(step) {
150
- this.steps.push(step);
151
- }
152
-
153
- setApplicable(applicable) {
154
- this.applicable = applicable;
155
- }
111
+ addStep(step) { this.steps.push(step); }
112
+ setApplicable(applicable) { this.applicable = applicable; }
156
113
 
157
114
  getSummary() {
158
115
  return {
@@ -184,34 +141,17 @@ class CircularDependencyResult {
184
141
  this.warnings = [];
185
142
  }
186
143
 
187
- addCycle(cycle) {
188
- this.cycles.push(cycle);
189
- }
190
-
191
- addStrategy(strategy) {
192
- this.strategies.push(strategy);
193
- }
194
-
195
- addResolved(resolution) {
196
- this.resolved.push(resolution);
197
- }
198
-
199
- addFailed(failure) {
200
- this.failed.push(failure);
201
- }
144
+ addCycle(cycle) { this.cycles.push(cycle); }
145
+ addStrategy(strategy) { this.strategies.push(strategy); }
146
+ addResolved(resolution) { this.resolved.push(resolution); }
147
+ addFailed(failure) { this.failed.push(failure); }
202
148
 
203
149
  addError(error) {
204
- this.errors.push({
205
- message: error.message,
206
- timestamp: new Date().toISOString()
207
- });
150
+ this.errors.push({ message: error.message, timestamp: new Date().toISOString() });
208
151
  }
209
152
 
210
153
  addWarning(warning) {
211
- this.warnings.push({
212
- message: warning,
213
- timestamp: new Date().toISOString()
214
- });
154
+ this.warnings.push({ message: warning, timestamp: new Date().toISOString() });
215
155
  }
216
156
 
217
157
  getSummary() {
@@ -0,0 +1,309 @@
1
+ /**
2
+ * Code Segment Mover
3
+ *
4
+ * Moves code segments between files while preserving functionality.
5
+ * Handles import updates and dependency management during moves.
6
+ */
7
+
8
+ const { RollbackManager } = require('../utils/rollback-manager');
9
+ const MoveExecutor = require('./move-executor');
10
+
11
+ /**
12
+ * Code Mover class
13
+ */
14
+ class CodeMover {
15
+ constructor(options = {}) {
16
+ this.options = {
17
+ autoBackup: options.autoBackup !== false,
18
+ validateSyntax: options.validateSyntax !== false,
19
+ updateImports: options.updateImports !== false,
20
+ preserveFormatting: options.preserveFormatting !== false,
21
+ continueOnError: options.continueOnError || false,
22
+ ...options
23
+ };
24
+
25
+ this.executor = new MoveExecutor(this.options);
26
+ this.moveHistory = [];
27
+ }
28
+
29
+ async moveCodeSegment(moveRequest) {
30
+ const operation = {
31
+ type: 'extract',
32
+ source: {
33
+ filePath: moveRequest.sourceFile,
34
+ startLine: moveRequest.startLine,
35
+ endLine: moveRequest.endLine
36
+ },
37
+ target: {
38
+ filePath: moveRequest.targetFile,
39
+ insertPosition: moveRequest.insertPosition || 'end'
40
+ },
41
+ options: this.options
42
+ };
43
+
44
+ const result = await this.executor.executeMove(operation);
45
+
46
+ // Record in history
47
+ this.moveHistory.push({
48
+ operation,
49
+ result: result.getSummary(),
50
+ timestamp: new Date().toISOString()
51
+ });
52
+
53
+ return result;
54
+ }
55
+
56
+ async extractFunction(functionName, sourceFile, targetFile) {
57
+ // Find function in source file
58
+ const sourceContent = await fs.promises.readFile(sourceFile, 'utf8');
59
+ const functionMatch = this.findFunctionDefinition(sourceContent, functionName);
60
+
61
+ if (!functionMatch) {
62
+ throw new Error(`Function '${functionName}' not found in ${sourceFile}`);
63
+ }
64
+
65
+ const moveRequest = {
66
+ sourceFile,
67
+ targetFile,
68
+ startLine: functionMatch.startLine,
69
+ endLine: functionMatch.endLine,
70
+ insertPosition: 'end'
71
+ };
72
+
73
+ return await this.moveCodeSegment(moveRequest);
74
+ }
75
+
76
+ async extractClass(className, sourceFile, targetFile) {
77
+ // Find class in source file
78
+ const sourceContent = await fs.promises.readFile(sourceFile, 'utf8');
79
+ const classMatch = this.findClassDefinition(sourceContent, className);
80
+
81
+ if (!classMatch) {
82
+ throw new Error(`Class '${className}' not found in ${sourceFile}`);
83
+ }
84
+
85
+ const moveRequest = {
86
+ sourceFile,
87
+ targetFile,
88
+ startLine: classMatch.startLine,
89
+ endLine: classMatch.endLine,
90
+ insertPosition: 'end'
91
+ };
92
+
93
+ return await this.moveCodeSegment(moveRequest);
94
+ }
95
+
96
+ async consolidateRelatedFunctions(functionNames, sourceFile, targetFile) {
97
+ const results = [];
98
+
99
+ for (const functionName of functionNames) {
100
+ try {
101
+ const result = await this.extractFunction(functionName, sourceFile, targetFile);
102
+ results.push(result);
103
+ } catch (error) {
104
+ results.push({
105
+ success: false,
106
+ error: error.message,
107
+ functionName
108
+ });
109
+ }
110
+ }
111
+
112
+ return {
113
+ results,
114
+ summary: {
115
+ total: functionNames.length,
116
+ successful: results.filter(r => r.success).length,
117
+ failed: results.filter(r => !r.success).length
118
+ }
119
+ };
120
+ }
121
+
122
+ findFunctionDefinition(content, functionName) {
123
+ const lines = content.split('\n');
124
+ const functionPattern = new RegExp(`(?:function\\s+${functionName}\\s*\\(|${functionName}\\s*:\\s*function|const\\s+${functionName}\\s*=\\s*function)`, 'g');
125
+
126
+ for (let i = 0; i < lines.length; i++) {
127
+ if (functionPattern.test(lines[i])) {
128
+ return {
129
+ startLine: i + 1,
130
+ endLine: this.findFunctionEnd(lines, i),
131
+ content: lines[i]
132
+ };
133
+ }
134
+ }
135
+
136
+ return null;
137
+ }
138
+
139
+ findClassDefinition(content, className) {
140
+ const lines = content.split('\n');
141
+ const classPattern = new RegExp(`class\\s+${className}\\s*(?:extends\\s+\\w+)?`, 'g');
142
+
143
+ for (let i = 0; i < lines.length; i++) {
144
+ if (classPattern.test(lines[i])) {
145
+ return {
146
+ startLine: i + 1,
147
+ endLine: this.findClassEnd(lines, i),
148
+ content: lines[i]
149
+ };
150
+ }
151
+ }
152
+
153
+ return null;
154
+ }
155
+
156
+ findFunctionEnd(lines, startIndex) {
157
+ let braceCount = 0;
158
+ let inFunction = false;
159
+
160
+ for (let i = startIndex; i < lines.length; i++) {
161
+ const line = lines[i];
162
+
163
+ if (line.includes('{')) {
164
+ braceCount += (line.match(/{/g) || []).length;
165
+ inFunction = true;
166
+ }
167
+
168
+ if (line.includes('}')) {
169
+ braceCount -= (line.match(/}/g) || []).length;
170
+ }
171
+
172
+ if (inFunction && braceCount === 0) {
173
+ return i + 1;
174
+ }
175
+ }
176
+
177
+ return lines.length;
178
+ }
179
+
180
+ findClassEnd(lines, startIndex) {
181
+ let braceCount = 0;
182
+ let inClass = false;
183
+
184
+ for (let i = startIndex; i < lines.length; i++) {
185
+ const line = lines[i];
186
+
187
+ if (line.includes('{')) {
188
+ braceCount += (line.match(/{/g) || []).length;
189
+ inClass = true;
190
+ }
191
+
192
+ if (line.includes('}')) {
193
+ braceCount -= (line.match(/}/g) || []).length;
194
+ }
195
+
196
+ if (inClass && braceCount === 0) {
197
+ return i + 1;
198
+ }
199
+ }
200
+
201
+ return lines.length;
202
+ }
203
+
204
+ async batchMove(moveRequests) {
205
+ const operations = moveRequests.map(request => ({
206
+ type: 'extract',
207
+ source: {
208
+ filePath: request.sourceFile,
209
+ startLine: request.startLine,
210
+ endLine: request.endLine
211
+ },
212
+ target: {
213
+ filePath: request.targetFile,
214
+ insertPosition: request.insertPosition || 'end'
215
+ },
216
+ options: this.options
217
+ }));
218
+
219
+ return await this.executor.executeBatchMove(operations);
220
+ }
221
+
222
+ getMoveHistory() {
223
+ return this.moveHistory;
224
+ }
225
+
226
+ async rollbackLastMove() {
227
+ return await this.executor.rollbackLastMove();
228
+ }
229
+
230
+ analyzeMoveImpact(moveRequest) {
231
+ const operation = {
232
+ type: 'extract',
233
+ source: {
234
+ filePath: moveRequest.sourceFile,
235
+ startLine: moveRequest.startLine,
236
+ endLine: moveRequest.endLine
237
+ },
238
+ target: {
239
+ filePath: moveRequest.targetFile
240
+ }
241
+ };
242
+
243
+ const impact = {
244
+ linesMoved: moveRequest.endLine - moveRequest.startLine + 1,
245
+ filesAffected: 2,
246
+ riskLevel: 'low',
247
+ dependencies: []
248
+ };
249
+
250
+ // Risk assessment
251
+ if (impact.linesMoved > 50) {
252
+ impact.riskLevel = 'high';
253
+ } else if (impact.linesMoved > 20) {
254
+ impact.riskLevel = 'medium';
255
+ }
256
+
257
+ return impact;
258
+ }
259
+
260
+ generateMoveReport(result) {
261
+ return this.executor.generateReport(result.operation, result);
262
+ }
263
+
264
+ getMoverInfo() {
265
+ return {
266
+ supportedOperations: [
267
+ 'extract_function',
268
+ 'extract_class',
269
+ 'move_segment',
270
+ 'batch_move',
271
+ 'consolidate_functions'
272
+ ],
273
+ defaultOptions: this.options,
274
+ features: [
275
+ 'function extraction',
276
+ 'class extraction',
277
+ 'import management',
278
+ 'backup creation',
279
+ 'rollback support',
280
+ 'batch operations',
281
+ 'impact analysis'
282
+ ],
283
+ version: '1.0.0'
284
+ };
285
+ }
286
+
287
+ static createDefault(config = {}) {
288
+ return new CodeMover({
289
+ autoBackup: true,
290
+ validateSyntax: true,
291
+ updateImports: true,
292
+ preserveFormatting: true,
293
+ ...config
294
+ });
295
+ }
296
+
297
+ static createForRefactoring(config = {}) {
298
+ return new CodeMover({
299
+ autoBackup: true,
300
+ validateSyntax: true,
301
+ updateImports: true,
302
+ preserveFormatting: false,
303
+ continueOnError: false,
304
+ ...config
305
+ });
306
+ }
307
+ }
308
+
309
+ module.exports = CodeMover;