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.
- package/package.json +1 -1
- package/src/agents/AgentCheckDiscoveryService.js +180 -0
- package/src/agents/AgentCheckService.js +18 -261
- package/src/agents/AgentCheckStatisticsService.js +195 -0
- package/src/agents/EnvironmentConfigurationManager.js +31 -380
- package/src/agents/InstallationType.js +19 -6
- package/src/agents/SimpleAgentCheckService.js +472 -0
- package/src/agents/config-managers/ConfigUtils.js +72 -0
- package/src/agents/config-managers/DefaultConfig.js +58 -0
- package/src/agents/config-managers/EnvVarLoader.js +66 -0
- package/src/agents/config-managers/FileConfigLoader.js +124 -0
- package/src/agents/config-managers/TypeConverters.js +61 -0
- package/src/agents/config-managers/VariableMappings.js +92 -0
- package/src/agents/discovery/AgentDiscoveryService-refactored.js +272 -0
- package/src/agents/discovery/AgentDiscoveryService.js +29 -403
- package/src/agents/discovery/agent-validator.js +262 -0
- package/src/agents/discovery/discovery-results.js +176 -0
- package/src/agents/discovery/discovery-scanner.js +268 -0
- package/src/agents/discovery/discovery-utils.js +161 -0
- package/src/agents/discovery/executable-analyzer.js +290 -0
- package/src/agents/discovery/history-manager.js +310 -0
- package/src/agents/verification/ResultAnalyzer-refactored.js +341 -0
- package/src/agents/verification/ResultAnalyzer.js +30 -431
- package/src/agents/verification/analysis-utils.js +310 -0
- package/src/agents/verification/batch-analyzer.js +440 -0
- package/src/agents/verification/pattern-recognizer.js +369 -0
- package/src/agents/verification/report-generator.js +320 -0
- package/src/agents/verification/test-analyzer.js +290 -0
- package/src/agents/windows/InstallerFactory.js +4 -0
- package/src/agents/windows/VSCodeExtensionInstaller.js +404 -0
- package/src/analysis/analysis-engine.js +314 -0
- package/src/analysis/ast-analyzer.js +342 -0
- package/src/analysis/boundary-detector-refactored.js +378 -0
- package/src/analysis/boundary-detector.js +200 -603
- package/src/analysis/boundary-scanner.js +609 -0
- package/src/analysis/boundary-types.js +118 -0
- package/src/analysis/boundary-utils.js +293 -0
- package/src/analysis/deadline-priority-calculator.js +18 -0
- package/src/analysis/detection-methods.js +347 -0
- package/src/analysis/importance-priority-calculator.js +18 -0
- package/src/analysis/priority/factor-calculators.js +204 -0
- package/src/analysis/priority/factor-helpers.js +71 -0
- package/src/analysis/priority/priority-constants.js +73 -0
- package/src/analysis/priority/priority-factor-calculators.js +301 -0
- package/src/analysis/priority/reasons-generator.js +44 -0
- package/src/analysis/priority-calculator.js +15 -580
- package/src/analysis/strategy-generator.js +16 -66
- package/src/analysis/type-priority-calculator.js +18 -0
- package/src/analysis/urgency-priority-calculator.js +18 -0
- package/src/auto-mode/AutoModeBusinessLogic.js +2 -40
- package/src/commands/disable-requirement.js +60 -0
- package/src/commands/disable-spec.js +60 -0
- package/src/commands/enable-requirement.js +60 -0
- package/src/commands/enable-spec.js +60 -0
- package/src/commands/registry.js +1 -6
- package/src/commands/requirements.js +8 -2
- package/src/ide-integration/applescript-manager.cjs +9 -24
- package/src/ide-integration/cdp-handlers/chat-reader.js +44 -0
- package/src/ide-integration/cdp-handlers/connection-handler.js +88 -0
- package/src/ide-integration/cdp-handlers/continuation-handler.js +314 -0
- package/src/ide-integration/cdp-handlers/message-submitter.js +75 -0
- package/src/ide-integration/cdp-handlers/text-sender.js +138 -0
- package/src/ide-integration/cdp-manager.js +28 -573
- package/src/ide-integration/claude-code-cli-manager.cjs +48 -12
- package/src/ide-integration/ide-openers/claude-opener.js +171 -0
- package/src/ide-integration/ide-openers/cursor-opener.js +53 -0
- package/src/ide-integration/ide-openers/other-ides-opener.js +230 -0
- package/src/ide-integration/ide-openers/vscode-opener.js +147 -0
- package/src/ide-integration/macos-ide-manager.js +20 -582
- package/src/ide-integration/macos-quota-checker.js +164 -0
- package/src/ide-integration/macos-text-sender.js +19 -38
- package/src/ide-integration/provider-manager.cjs +52 -7
- package/src/index.cjs +6 -0
- package/src/index.js +10 -0
- package/src/llm/direct-llm-manager.cjs +501 -0
- package/src/localization/translations/en-part1.js +363 -0
- package/src/localization/translations/en-part2.js +320 -0
- package/src/localization/translations/en.js +4 -687
- package/src/localization/translations/es-part1.js +363 -0
- package/src/localization/translations/es-part2.js +320 -0
- package/src/localization/translations/es.js +4 -688
- package/src/models/file-analysis-collection.js +139 -0
- package/src/models/file-analysis-metrics.js +50 -0
- package/src/models/file-analysis.js +15 -262
- package/src/models/plan-manager.js +410 -0
- package/src/models/refactoring-models.js +380 -0
- package/src/models/refactoring-plan-refactored.js +81 -0
- package/src/models/refactoring-plan.js +2 -663
- package/src/monitoring/alert-system.js +4 -45
- package/src/monitoring/continuous-scan-notifications.js +37 -191
- package/src/monitoring/notification-handlers/base-handler.js +58 -0
- package/src/monitoring/notification-handlers/error-handler.js +36 -0
- package/src/monitoring/notification-handlers/index.js +21 -0
- package/src/monitoring/notification-handlers/new-violation-handler.js +91 -0
- package/src/monitoring/notification-handlers/progress-handler.js +48 -0
- package/src/monitoring/notification-handlers/resolved-violation-handler.js +54 -0
- package/src/monitoring/notification-handlers/threshold-handler.js +36 -0
- package/src/provider-registry.js +8 -0
- package/src/refactoring/boundary/boundary-detector-refactored.js +58 -0
- package/src/refactoring/boundary/boundary-detector.js +26 -596
- package/src/refactoring/boundary/detectors/boundary-analyzers.js +281 -0
- package/src/refactoring/boundary/detectors/boundary-core.js +167 -0
- package/src/refactoring/boundary/detectors/class-detector.js +247 -0
- package/src/refactoring/boundary/detectors/config-detector.js +270 -0
- package/src/refactoring/boundary/detectors/constant-detector.js +269 -0
- package/src/refactoring/boundary/detectors/function-detector.js +248 -0
- package/src/refactoring/boundary/detectors/module-detector.js +249 -0
- package/src/refactoring/boundary/detectors/object-detector.js +247 -0
- package/src/refactoring/boundary/detectors/type-detectors.js +338 -0
- package/src/refactoring/boundary/detectors/utility-detector.js +270 -0
- package/src/refactoring/circular-dependency-resolver-original.js +16 -76
- package/src/refactoring/code-mover-refactored.js +309 -0
- package/src/refactoring/code-mover.js +48 -355
- package/src/refactoring/execution-status.js +18 -0
- package/src/refactoring/execution-strategies.js +172 -0
- package/src/refactoring/file-splitter-core.js +568 -0
- package/src/refactoring/file-splitter-types.js +136 -0
- package/src/refactoring/file-splitter.js +2 -682
- package/src/refactoring/functionality-validator.js +11 -51
- package/src/refactoring/import-manager-refactored.js +385 -0
- package/src/refactoring/import-manager.js +112 -487
- package/src/refactoring/import-models.js +189 -0
- package/src/refactoring/import-parser.js +306 -0
- package/src/refactoring/move-executor.js +431 -0
- package/src/refactoring/move-utils.js +368 -0
- package/src/refactoring/operation-executor.js +76 -0
- package/src/refactoring/plan-creator.js +36 -0
- package/src/refactoring/plan-executor.js +143 -0
- package/src/refactoring/plan-validator.js +68 -0
- package/src/refactoring/refactoring-executor-result.js +70 -0
- package/src/refactoring/refactoring-executor.js +34 -569
- package/src/refactoring/refactoring-operation.js +94 -0
- package/src/refactoring/refactoring-plan.js +69 -0
- package/src/refactoring/refactoring-rollback.js +22 -527
- package/src/refactoring/rollback-handlers/RollbackExecutor.js +107 -0
- package/src/refactoring/rollback-handlers/RollbackManager.js +265 -0
- package/src/refactoring/rollback-handlers/RollbackOperation.js +105 -0
- package/src/refactoring/rollback-handlers/RollbackResult.js +109 -0
- package/src/refactoring/rollback-handlers/RollbackStatistics.js +77 -0
- package/src/refactoring/test-validator.js +32 -448
- package/src/refactoring/validation/baseline-runner.js +71 -0
- package/src/refactoring/validation/report-generator.js +136 -0
- package/src/refactoring/validation/result-comparator.js +92 -0
- package/src/refactoring/validation/test-suite.js +59 -0
- package/src/refactoring/validation/test-validation-result.js +83 -0
- package/src/refactoring/validation/validation-runner.js +95 -0
- package/src/refactoring/validation/validation-status.js +18 -0
- package/src/rui/commands/AgentCommandParser.js +60 -369
- package/src/rui/commands/AgentResponseFormatter.js +7 -47
- package/src/rui/commands/parsers/CommandMapper.js +148 -0
- package/src/rui/commands/parsers/CommandValidator.js +228 -0
- package/src/rui/commands/parsers/ComponentExtractor.js +100 -0
- package/src/rui/commands/parsers/TokenParser.js +69 -0
- package/src/rui/commands/parsers/tokenizer.js +153 -0
- package/src/utils/current-requirement-operations.js +50 -1
- package/src/utils/report-generator.js +18 -514
- package/src/utils/report-generators/analysis-generator.js +115 -0
- package/src/utils/report-generators/base-generator.js +141 -0
- package/src/utils/report-generators/compliance-generator.js +41 -0
- package/src/utils/report-generators/format-handlers.js +185 -0
- package/src/utils/report-generators/refactoring-generator.js +46 -0
- package/src/utils/report-generators/validation-generator.js +63 -0
- package/src/utils/requirement-enable-disable.js +265 -0
- package/src/utils/requirement-helpers/requirement-file-ops.js +69 -1
- package/src/utils/requirement-helpers/requirement-mover.js +88 -1
- package/src/utils/requirement-helpers.js +5 -2
- package/src/utils/smoke-test-cli.js +45 -8
- package/src/utils/specification-enable-disable.js +122 -0
- package/src/utils/specification-helpers.js +30 -4
- package/src/utils/specification-migration.js +5 -5
- package/src/utils/test-comparator.js +118 -0
- package/src/utils/test-config.js +54 -0
- package/src/utils/test-executor.js +133 -0
- package/src/utils/test-parser.js +215 -0
- package/src/utils/test-runner-baseline.js +63 -0
- package/src/utils/test-runner-core.js +98 -0
- package/src/utils/test-runner-report.js +39 -0
- package/src/utils/test-runner-validation.js +71 -0
- package/src/utils/test-runner.js +11 -535
- package/src/validation/comparison-analyzer.js +333 -0
- package/src/validation/compliance-reporter-new.js +282 -0
- package/src/validation/compliance-reporter-refactored.js +344 -0
- package/src/validation/compliance-reporter.js +278 -591
- package/src/validation/compliance-utils.js +278 -0
- package/src/validation/html-generator.js +446 -0
- package/src/validation/metrics/category-calculator.js +137 -0
- package/src/validation/metrics/metrics-helpers.js +155 -0
- package/src/validation/metrics/overview-calculator.js +85 -0
- package/src/validation/metrics/overview-metrics.js +41 -0
- package/src/validation/metrics/quality-calculator.js +166 -0
- package/src/validation/metrics/size-calculator.js +69 -0
- package/src/validation/metrics-calculator.js +27 -551
|
@@ -5,382 +5,75 @@
|
|
|
5
5
|
* Handles import updates and dependency management during moves.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
const fs = require('fs');
|
|
9
|
-
const path = require('path');
|
|
10
8
|
const { RollbackManager } = require('../utils/rollback-manager');
|
|
9
|
+
const MoveExecutor = require('./move-executor');
|
|
11
10
|
|
|
12
11
|
/**
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
|
-
const MOVE_TYPES = {
|
|
16
|
-
EXTRACT: 'extract',
|
|
17
|
-
RELOCATE: 'relocate',
|
|
18
|
-
CONSOLIDATE: 'consolidate',
|
|
19
|
-
REORGANIZE: 'reorganize'
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Move result class
|
|
24
|
-
*/
|
|
25
|
-
class MoveResult {
|
|
26
|
-
constructor(operation) {
|
|
27
|
-
this.operation = operation;
|
|
28
|
-
this.success = false;
|
|
29
|
-
this.sourceModified = false;
|
|
30
|
-
this.targetCreated = false;
|
|
31
|
-
this.importsUpdated = false;
|
|
32
|
-
this.errors = [];
|
|
33
|
-
this.warnings = [];
|
|
34
|
-
this.metadata = {
|
|
35
|
-
executedAt: new Date().toISOString(),
|
|
36
|
-
linesMoved: 0,
|
|
37
|
-
filesAffected: 0
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
addError(error) {
|
|
42
|
-
this.errors.push({
|
|
43
|
-
message: error.message,
|
|
44
|
-
timestamp: new Date().toISOString(),
|
|
45
|
-
stack: error.stack
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
addWarning(warning) {
|
|
50
|
-
this.warnings.push({
|
|
51
|
-
message: warning,
|
|
52
|
-
timestamp: new Date().toISOString()
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
setSuccess(success) {
|
|
57
|
-
this.success = success;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
setSourceModified(modified) {
|
|
61
|
-
this.sourceModified = modified;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
setTargetCreated(created) {
|
|
65
|
-
this.targetCreated = created;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
setImportsUpdated(updated) {
|
|
69
|
-
this.importsUpdated = updated;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
getSummary() {
|
|
73
|
-
return {
|
|
74
|
-
operation: this.operation,
|
|
75
|
-
success: this.success,
|
|
76
|
-
sourceModified: this.sourceModified,
|
|
77
|
-
targetCreated: this.targetCreated,
|
|
78
|
-
importsUpdated: this.importsUpdated,
|
|
79
|
-
linesMoved: this.metadata.linesMoved,
|
|
80
|
-
filesAffected: this.metadata.filesAffected,
|
|
81
|
-
errorCount: this.errors.length,
|
|
82
|
-
warningCount: this.warnings.length
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Move operation class
|
|
89
|
-
*/
|
|
90
|
-
class MoveOperation {
|
|
91
|
-
constructor(type, sourcePath, targetPath, options = {}) {
|
|
92
|
-
this.id = this.generateId();
|
|
93
|
-
this.type = type;
|
|
94
|
-
this.sourcePath = sourcePath;
|
|
95
|
-
this.targetPath = targetPath;
|
|
96
|
-
this.startLine = options.startLine;
|
|
97
|
-
this.endLine = options.endLine;
|
|
98
|
-
this.segmentName = options.segmentName;
|
|
99
|
-
this.updateImports = options.updateImports !== false;
|
|
100
|
-
this.preserveOriginal = options.preserveOriginal || false;
|
|
101
|
-
this.createBackup = options.createBackup !== false;
|
|
102
|
-
this.metadata = {
|
|
103
|
-
createdAt: new Date().toISOString(),
|
|
104
|
-
description: options.description || ''
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
generateId() {
|
|
109
|
-
return `move_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
validate() {
|
|
113
|
-
const errors = [];
|
|
114
|
-
|
|
115
|
-
if (!this.sourcePath) {
|
|
116
|
-
errors.push('Source path is required');
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (!this.targetPath) {
|
|
120
|
-
errors.push('Target path is required');
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
if (this.startLine && this.endLine && this.startLine > this.endLine) {
|
|
124
|
-
errors.push('Start line cannot be greater than end line');
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return {
|
|
128
|
-
isValid: errors.length === 0,
|
|
129
|
-
errors
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Code mover class
|
|
12
|
+
* Code Mover class
|
|
136
13
|
*/
|
|
137
14
|
class CodeMover {
|
|
138
15
|
constructor(options = {}) {
|
|
139
16
|
this.options = {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
preserveFormatting:
|
|
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,
|
|
144
22
|
...options
|
|
145
23
|
};
|
|
146
24
|
|
|
147
|
-
this.
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
if (this.options.backupBeforeMove) {
|
|
165
|
-
this.rollbackManager.backupFile(operation.sourcePath);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// Read source file
|
|
169
|
-
const sourceContent = fs.readFileSync(operation.sourcePath, 'utf8');
|
|
170
|
-
const sourceLines = sourceContent.split('\n');
|
|
171
|
-
|
|
172
|
-
// Extract code segment
|
|
173
|
-
const segment = this.extractSegment(sourceLines, operation);
|
|
174
|
-
result.metadata.linesMoved = segment.lines.length;
|
|
175
|
-
|
|
176
|
-
// Analyze dependencies
|
|
177
|
-
const dependencies = this.analyzeDependencies(segment.content);
|
|
178
|
-
|
|
179
|
-
// Write to target file
|
|
180
|
-
await this.writeTargetFile(operation, segment, dependencies);
|
|
181
|
-
result.setTargetCreated(true);
|
|
182
|
-
|
|
183
|
-
// Update source file
|
|
184
|
-
if (!operation.preserveOriginal) {
|
|
185
|
-
await this.updateSourceFile(operation.sourcePath, sourceLines, operation);
|
|
186
|
-
result.setSourceModified(true);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// Update imports
|
|
190
|
-
if (operation.updateImports && this.options.updateImportsAutomatically) {
|
|
191
|
-
await this.updateImports(operation, dependencies);
|
|
192
|
-
result.setImportsUpdated(true);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// Validate result
|
|
196
|
-
if (this.options.validateAfterMove) {
|
|
197
|
-
await this.validateMove(operation, result);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
result.metadata.filesAffected = 1 + (result.importsUpdated ? this.countAffectedFiles(dependencies) : 0);
|
|
201
|
-
result.setSuccess(true);
|
|
202
|
-
|
|
203
|
-
} catch (error) {
|
|
204
|
-
result.addError(error);
|
|
205
|
-
result.setSuccess(false);
|
|
206
|
-
|
|
207
|
-
// Rollback on error
|
|
208
|
-
await this.rollbackManager.rollback();
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
return result;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Extract code segment from source
|
|
216
|
-
*/
|
|
217
|
-
extractSegment(sourceLines, operation) {
|
|
218
|
-
let startIdx = 0;
|
|
219
|
-
let endIdx = sourceLines.length;
|
|
220
|
-
|
|
221
|
-
if (operation.startLine && operation.endLine) {
|
|
222
|
-
// Extract specific line range
|
|
223
|
-
startIdx = Math.max(0, operation.startLine - 1);
|
|
224
|
-
endIdx = Math.min(sourceLines.length, operation.endLine);
|
|
225
|
-
} else if (operation.segmentName) {
|
|
226
|
-
// Find segment by name (function, class, etc.)
|
|
227
|
-
const segmentRange = this.findSegmentRange(sourceLines, operation.segmentName);
|
|
228
|
-
if (segmentRange) {
|
|
229
|
-
startIdx = segmentRange.start;
|
|
230
|
-
endIdx = segmentRange.end;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
const lines = sourceLines.slice(startIdx, endIdx);
|
|
235
|
-
const content = lines.join('\n');
|
|
236
|
-
|
|
237
|
-
return {
|
|
238
|
-
lines,
|
|
239
|
-
content,
|
|
240
|
-
startLine: startIdx + 1,
|
|
241
|
-
endLine: endIdx
|
|
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
|
|
242
42
|
};
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* Find segment range by name
|
|
247
|
-
*/
|
|
248
|
-
findSegmentRange(lines, name) {
|
|
249
|
-
for (let i = 0; i < lines.length; i++) {
|
|
250
|
-
const line = lines[i].trim();
|
|
251
|
-
|
|
252
|
-
// Function declaration
|
|
253
|
-
const funcMatch = line.match(new RegExp(`^function\\s+${name}\\s*\\(`));
|
|
254
|
-
if (funcMatch) {
|
|
255
|
-
return this.findBlockRange(lines, i);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
// Function expression
|
|
259
|
-
const exprMatch = line.match(new RegExp(`^(?:const|let|var)\\s+${name}\\s*=\\s*function`));
|
|
260
|
-
if (exprMatch) {
|
|
261
|
-
return this.findBlockRange(lines, i);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
// Arrow function
|
|
265
|
-
const arrowMatch = line.match(new RegExp(`^(?:const|let|var)\\s+${name}\\s*=\\s*\\(`));
|
|
266
|
-
if (arrowMatch) {
|
|
267
|
-
return this.findBlockRange(lines, i);
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
// Class
|
|
271
|
-
const classMatch = line.match(new RegExp(`^class\\s+${name}\\b`));
|
|
272
|
-
if (classMatch) {
|
|
273
|
-
return this.findBlockRange(lines, i);
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
// Object assignment
|
|
277
|
-
const objMatch = line.match(new RegExp(`^(?:const|let|var)\\s+${name}\\s*=\\s*\\{`));
|
|
278
|
-
if (objMatch) {
|
|
279
|
-
return this.findBlockRange(lines, i);
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
43
|
|
|
283
|
-
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* Find block range (between braces)
|
|
288
|
-
*/
|
|
289
|
-
findBlockRange(lines, startLine) {
|
|
290
|
-
let braceCount = 0;
|
|
291
|
-
let foundBrace = false;
|
|
44
|
+
const result = await this.executor.executeMove(operation);
|
|
292
45
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
braceCount++;
|
|
299
|
-
foundBrace = true;
|
|
300
|
-
} else if (line[j] === '}') {
|
|
301
|
-
braceCount--;
|
|
302
|
-
if (foundBrace && braceCount === 0) {
|
|
303
|
-
return {
|
|
304
|
-
start: startLine,
|
|
305
|
-
end: i + 1
|
|
306
|
-
};
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
}
|
|
46
|
+
this.moveHistory.push({
|
|
47
|
+
operation,
|
|
48
|
+
result: result.getSummary(),
|
|
49
|
+
timestamp: new Date().toISOString()
|
|
50
|
+
});
|
|
311
51
|
|
|
312
|
-
return
|
|
313
|
-
start: startLine,
|
|
314
|
-
end: lines.length
|
|
315
|
-
};
|
|
52
|
+
return result;
|
|
316
53
|
}
|
|
317
54
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
analyzeDependencies(content) {
|
|
322
|
-
const dependencies = {
|
|
323
|
-
imports: [],
|
|
324
|
-
requires: [],
|
|
325
|
-
internalRefs: [],
|
|
326
|
-
externalRefs: []
|
|
327
|
-
};
|
|
328
|
-
|
|
329
|
-
const lines = content.split('\n');
|
|
55
|
+
async extractFunction(functionName, sourceFile, targetFile) {
|
|
56
|
+
const sourceContent = await fs.promises.readFile(sourceFile, 'utf8');
|
|
57
|
+
const functionMatch = this.findFunctionDefinition(sourceContent, functionName);
|
|
330
58
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
// Import statements
|
|
335
|
-
if (trimmed.startsWith('import ')) {
|
|
336
|
-
const match = trimmed.match(/import\s+(?:.*?\s+from\s+)?['"]([^'"]+)['"]/);
|
|
337
|
-
if (match) {
|
|
338
|
-
dependencies.imports.push({
|
|
339
|
-
statement: trimmed,
|
|
340
|
-
module: match[1],
|
|
341
|
-
isRelative: match[1].startsWith('./') || match[1].startsWith('../')
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
// Require statements
|
|
347
|
-
if (trimmed.includes('require(')) {
|
|
348
|
-
const match = trimmed.match(/require\s*\(\s*['"]([^'"]+)['"]\s*\)/);
|
|
349
|
-
if (match) {
|
|
350
|
-
dependencies.requires.push({
|
|
351
|
-
statement: trimmed,
|
|
352
|
-
module: match[1],
|
|
353
|
-
isRelative: match[1].startsWith('./') || match[1].startsWith('../')
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
// Variable references (simplified)
|
|
359
|
-
const varMatches = trimmed.match(/\b[a-zA-Z_]\w*\b/g);
|
|
360
|
-
if (varMatches) {
|
|
361
|
-
for (const varName of varMatches) {
|
|
362
|
-
if (!this.isKeyword(varName)) {
|
|
363
|
-
dependencies.internalRefs.push(varName);
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
}
|
|
59
|
+
if (!functionMatch) {
|
|
60
|
+
throw new Error(`Function '${functionName}' not found in ${sourceFile}`);
|
|
367
61
|
}
|
|
368
62
|
|
|
369
|
-
|
|
63
|
+
const moveRequest = {
|
|
64
|
+
sourceFile,
|
|
65
|
+
targetFile,
|
|
66
|
+
startLine: functionMatch.startLine,
|
|
67
|
+
endLine: functionMatch.endLine,
|
|
68
|
+
insertPosition: 'end'
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
return await this.moveCodeSegment(moveRequest);
|
|
370
72
|
}
|
|
371
73
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
isKeyword(word) {
|
|
376
|
-
const keywords = [
|
|
377
|
-
'break', 'case', 'catch', 'class', 'const', 'continue', 'debugger', 'default',
|
|
378
|
-
'delete', 'do', 'else', 'export', 'extends', 'finally', 'for', 'function',
|
|
379
|
-
'if', 'import', 'in', 'instanceof', 'let', 'new', 'return', 'super', 'switch',
|
|
380
|
-
'this', 'throw', 'try', 'typeof', 'var', 'void', 'while', 'with', 'yield'
|
|
381
|
-
];
|
|
382
|
-
return keywords.includes(word);
|
|
383
|
-
}
|
|
74
|
+
async extractClass(className, sourceFile, targetFile) {
|
|
75
|
+
const sourceContent = await fs.promises.readFile(sourceFile, 'utf8');
|
|
76
|
+
const classMatch = this.findClassDefinition(sourceContent, className);
|
|
384
77
|
|
|
385
78
|
/**
|
|
386
79
|
* Write target file
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Execution Status Constants
|
|
3
|
+
*
|
|
4
|
+
* Defines the possible execution states for refactoring operations and plans.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const EXECUTION_STATUS = {
|
|
8
|
+
PENDING: 'pending',
|
|
9
|
+
RUNNING: 'running',
|
|
10
|
+
COMPLETED: 'completed',
|
|
11
|
+
FAILED: 'failed',
|
|
12
|
+
PAUSED: 'paused',
|
|
13
|
+
CANCELLED: 'cancelled'
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
module.exports = {
|
|
17
|
+
EXECUTION_STATUS
|
|
18
|
+
};
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Execution Strategies
|
|
3
|
+
*
|
|
4
|
+
* Handles the execution of different types of refactoring operations.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const { EXECUTION_STATUS } = require('./execution-status');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Operation execution strategies
|
|
11
|
+
*/
|
|
12
|
+
class ExecutionStrategies {
|
|
13
|
+
constructor(components) {
|
|
14
|
+
this.fileSplitter = components.fileSplitter;
|
|
15
|
+
this.boundaryExtractor = components.boundaryExtractor;
|
|
16
|
+
this.codeMover = components.codeMover;
|
|
17
|
+
this.importManager = components.importManager;
|
|
18
|
+
this.circularDependencyResolver = components.circularDependencyResolver;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Execute file split operation
|
|
23
|
+
*/
|
|
24
|
+
async executeSplitFile(operation) {
|
|
25
|
+
const { targetPath, splitPoints } = operation.options;
|
|
26
|
+
|
|
27
|
+
// Read file analysis (would come from operation context)
|
|
28
|
+
const fileAnalysis = await this.analyzeFile(targetPath);
|
|
29
|
+
|
|
30
|
+
const splitResult = await this.fileSplitter.splitFile(fileAnalysis, splitPoints);
|
|
31
|
+
|
|
32
|
+
if (!splitResult.success) {
|
|
33
|
+
throw new Error(`File split failed: ${splitResult.errors.map(e => e.message).join(', ')}`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return splitResult;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Execute boundary extraction operation
|
|
41
|
+
*/
|
|
42
|
+
async executeExtractBoundaries(operation) {
|
|
43
|
+
const { targetPath, boundaries } = operation.options;
|
|
44
|
+
|
|
45
|
+
const extractionResult = await this.boundaryExtractor.extractBoundaries(targetPath);
|
|
46
|
+
|
|
47
|
+
if (extractionResult.errors.length > 0) {
|
|
48
|
+
throw new Error(`Boundary extraction failed: ${extractionResult.errors.map(e => e.message).join(', ')}`);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return extractionResult;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Execute code move operation
|
|
56
|
+
*/
|
|
57
|
+
async executeMoveCode(operation) {
|
|
58
|
+
const { sourcePath, targetPath, segment } = operation.options;
|
|
59
|
+
|
|
60
|
+
const moveOperation = {
|
|
61
|
+
type: 'extract',
|
|
62
|
+
sourcePath,
|
|
63
|
+
targetPath,
|
|
64
|
+
segmentName: segment.name,
|
|
65
|
+
startLine: segment.startLine,
|
|
66
|
+
endLine: segment.endLine
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const moveResult = await this.codeMover.executeMove(moveOperation);
|
|
70
|
+
|
|
71
|
+
if (!moveResult.success) {
|
|
72
|
+
throw new Error(`Code move failed: ${moveResult.errors.map(e => e.message).join(', ')}`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return moveResult;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Execute import update operation
|
|
80
|
+
*/
|
|
81
|
+
async executeUpdateImports(operation) {
|
|
82
|
+
const { targetPath, changes } = operation.options;
|
|
83
|
+
|
|
84
|
+
const updateResult = await this.importManager.updateImports(targetPath, changes);
|
|
85
|
+
|
|
86
|
+
if (!updateResult.success) {
|
|
87
|
+
throw new Error(`Import update failed: ${updateResult.errors.map(e => e.message).join(', ')}`);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return updateResult;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Execute circular dependency resolution
|
|
95
|
+
*/
|
|
96
|
+
async executeResolveCircularDeps(operation) {
|
|
97
|
+
const { rootPath, strategies } = operation.options;
|
|
98
|
+
|
|
99
|
+
const analysisResult = await this.circularDependencyResolver.analyze(rootPath);
|
|
100
|
+
|
|
101
|
+
if (analysisResult.errors.length > 0) {
|
|
102
|
+
throw new Error(`Circular dependency analysis failed: ${analysisResult.errors.map(e => e.message).join(', ')}`);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return analysisResult;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Execute a single operation
|
|
110
|
+
*/
|
|
111
|
+
async executeOperation(operation, result) {
|
|
112
|
+
console.log(`Executing operation: ${operation.type} on ${operation.targetPath}`);
|
|
113
|
+
operation.setStatus(EXECUTION_STATUS.RUNNING);
|
|
114
|
+
operation.setProgress(0);
|
|
115
|
+
|
|
116
|
+
try {
|
|
117
|
+
let operationResult = null;
|
|
118
|
+
|
|
119
|
+
switch (operation.type) {
|
|
120
|
+
case 'split_file':
|
|
121
|
+
operationResult = await this.executeSplitFile(operation);
|
|
122
|
+
break;
|
|
123
|
+
|
|
124
|
+
case 'extract_boundaries':
|
|
125
|
+
operationResult = await this.executeExtractBoundaries(operation);
|
|
126
|
+
break;
|
|
127
|
+
|
|
128
|
+
case 'move_code':
|
|
129
|
+
operationResult = await this.executeMoveCode(operation);
|
|
130
|
+
break;
|
|
131
|
+
|
|
132
|
+
case 'update_imports':
|
|
133
|
+
operationResult = await this.executeUpdateImports(operation);
|
|
134
|
+
break;
|
|
135
|
+
|
|
136
|
+
case 'resolve_circular_deps':
|
|
137
|
+
operationResult = await this.executeResolveCircularDeps(operation);
|
|
138
|
+
break;
|
|
139
|
+
|
|
140
|
+
default:
|
|
141
|
+
throw new Error(`Unknown operation type: ${operation.type}`);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
operation.setResult(operationResult);
|
|
145
|
+
operation.setStatus(EXECUTION_STATUS.COMPLETED);
|
|
146
|
+
operation.setProgress(100);
|
|
147
|
+
|
|
148
|
+
console.log(`Operation completed: ${operation.id}`);
|
|
149
|
+
|
|
150
|
+
} catch (error) {
|
|
151
|
+
operation.setError(error);
|
|
152
|
+
operation.setStatus(EXECUTION_STATUS.FAILED);
|
|
153
|
+
throw error;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Analyze file for refactoring
|
|
159
|
+
*/
|
|
160
|
+
async analyzeFile(filePath) {
|
|
161
|
+
// This would create a FileAnalysis object
|
|
162
|
+
// For now, return a placeholder
|
|
163
|
+
return {
|
|
164
|
+
filePath,
|
|
165
|
+
lineCount: 100,
|
|
166
|
+
needsRefactoring: true,
|
|
167
|
+
boundaries: null
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
module.exports = { ExecutionStrategies };
|