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
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logical Boundary Detector
|
|
3
|
+
*
|
|
4
|
+
* Uses AST analysis to detect logical boundaries in files for refactoring.
|
|
5
|
+
* Identifies functions, classes, modules, and other logical segments.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
const BoundaryScanner = require('./boundary-scanner');
|
|
11
|
+
const {
|
|
12
|
+
BOUNDARY_TYPES,
|
|
13
|
+
groupBoundariesByType,
|
|
14
|
+
findBoundaryRelationships,
|
|
15
|
+
generateBoundaryRecommendations
|
|
16
|
+
} = require('./boundary-utils');
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Boundary Detection Result class
|
|
20
|
+
*/
|
|
21
|
+
class BoundaryDetectionResult {
|
|
22
|
+
constructor(filePath) {
|
|
23
|
+
this.filePath = filePath;
|
|
24
|
+
this.boundaries = [];
|
|
25
|
+
this.metadata = {
|
|
26
|
+
totalBoundaries: 0,
|
|
27
|
+
byType: {},
|
|
28
|
+
complexity: 'unknown',
|
|
29
|
+
cohesion: 'unknown',
|
|
30
|
+
coupling: 'unknown'
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
addBoundary(boundary) {
|
|
35
|
+
this.boundaries.push(boundary);
|
|
36
|
+
this.metadata.totalBoundaries++;
|
|
37
|
+
|
|
38
|
+
if (!this.metadata.byType[boundary.type]) {
|
|
39
|
+
this.metadata.byType[boundary.type] = 0;
|
|
40
|
+
}
|
|
41
|
+
this.metadata.byType[boundary.type]++;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
getSummary() {
|
|
45
|
+
return {
|
|
46
|
+
filePath: this.filePath,
|
|
47
|
+
totalBoundaries: this.metadata.totalBoundaries,
|
|
48
|
+
byType: this.metadata.byType,
|
|
49
|
+
averageSize: this.boundaries.length > 0 ?
|
|
50
|
+
this.boundaries.reduce((sum, b) => sum + b.size, 0) / this.boundaries.length : 0,
|
|
51
|
+
complexity: this.metadata.complexity,
|
|
52
|
+
cohesion: this.metadata.cohesion,
|
|
53
|
+
coupling: this.metadata.coupling
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Boundary Detector class
|
|
60
|
+
*/
|
|
61
|
+
class BoundaryDetector {
|
|
62
|
+
constructor(options = {}) {
|
|
63
|
+
this.options = {
|
|
64
|
+
includeComments: options.includeComments !== false,
|
|
65
|
+
includeImports: options.includeImports !== false,
|
|
66
|
+
includeExports: options.includeExports !== false,
|
|
67
|
+
minBoundarySize: options.minBoundarySize || 5,
|
|
68
|
+
analysisDepth: options.analysisDepth || 'standard',
|
|
69
|
+
...options
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
this.scanner = new BoundaryScanner(this.options);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Detect boundaries in file
|
|
77
|
+
* @param {string} filePath - Path to file
|
|
78
|
+
* @returns {Promise<BoundaryDetectionResult>} - Detection result
|
|
79
|
+
*/
|
|
80
|
+
async detectBoundaries(filePath) {
|
|
81
|
+
try {
|
|
82
|
+
const content = await fs.promises.readFile(filePath, 'utf8');
|
|
83
|
+
const scanResult = this.scanner.scanFile(content, filePath);
|
|
84
|
+
|
|
85
|
+
const result = new BoundaryDetectionResult(filePath);
|
|
86
|
+
|
|
87
|
+
// Add all detected boundaries
|
|
88
|
+
scanResult.boundaries.forEach(boundary => {
|
|
89
|
+
result.addBoundary(boundary);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// Analyze relationships
|
|
93
|
+
const relationships = findBoundaryRelationships(result.boundaries);
|
|
94
|
+
|
|
95
|
+
// Calculate overall metrics
|
|
96
|
+
result.metadata.complexity = this.calculateOverallComplexity(result.boundaries);
|
|
97
|
+
result.metadata.cohesion = this.calculateOverallCohesion(result.boundaries);
|
|
98
|
+
result.metadata.coupling = this.calculateOverallCoupling(result.boundaries, relationships);
|
|
99
|
+
|
|
100
|
+
// Add scan metadata
|
|
101
|
+
result.metadata.scanMetadata = scanResult.metadata;
|
|
102
|
+
result.metadata.relationships = relationships;
|
|
103
|
+
|
|
104
|
+
return result;
|
|
105
|
+
|
|
106
|
+
} catch (error) {
|
|
107
|
+
const result = new BoundaryDetectionResult(filePath);
|
|
108
|
+
result.metadata.error = error.message;
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Detect boundaries in multiple files
|
|
115
|
+
* @param {Array} filePaths - Array of file paths
|
|
116
|
+
* @returns {Promise<Array>} - Array of detection results
|
|
117
|
+
*/
|
|
118
|
+
async detectBoundariesInFiles(filePaths) {
|
|
119
|
+
const results = [];
|
|
120
|
+
|
|
121
|
+
for (const filePath of filePaths) {
|
|
122
|
+
const result = await this.detectBoundaries(filePath);
|
|
123
|
+
results.push(result);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return results;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Detect boundaries in directory
|
|
131
|
+
* @param {string} dirPath - Directory path
|
|
132
|
+
* @param {Object} options - Scan options
|
|
133
|
+
* @returns {Promise<Array>} - Array of detection results
|
|
134
|
+
*/
|
|
135
|
+
async detectBoundariesInDirectory(dirPath, options = {}) {
|
|
136
|
+
const scanOptions = {
|
|
137
|
+
recursive: options.recursive !== false,
|
|
138
|
+
extensions: options.extensions || ['.js', '.ts', '.jsx', '.tsx'],
|
|
139
|
+
exclude: options.exclude || ['node_modules', '.git', 'dist'],
|
|
140
|
+
...options
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const filePaths = await this.getFilePaths(dirPath, scanOptions);
|
|
144
|
+
return this.detectBoundariesInFiles(filePaths);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Get file paths from directory
|
|
149
|
+
* @param {string} dirPath - Directory path
|
|
150
|
+
* @param {Object} options - Scan options
|
|
151
|
+
* @returns {Promise<Array>} - Array of file paths
|
|
152
|
+
*/
|
|
153
|
+
async getFilePaths(dirPath, options) {
|
|
154
|
+
const filePaths = [];
|
|
155
|
+
|
|
156
|
+
const scanDirectory = async (currentPath, depth = 0) => {
|
|
157
|
+
if (depth > (options.maxDepth || 10)) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const entries = await fs.promises.readdir(currentPath, { withFileTypes: true });
|
|
162
|
+
|
|
163
|
+
for (const entry of entries) {
|
|
164
|
+
const fullPath = path.join(currentPath, entry.name);
|
|
165
|
+
|
|
166
|
+
if (entry.isDirectory()) {
|
|
167
|
+
if (options.exclude && !options.exclude.some(exclude => entry.name.includes(exclude))) {
|
|
168
|
+
if (options.recursive) {
|
|
169
|
+
await scanDirectory(fullPath, depth + 1);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
} else if (entry.isFile()) {
|
|
173
|
+
const ext = path.extname(entry.name);
|
|
174
|
+
if (options.extensions.includes(ext)) {
|
|
175
|
+
filePaths.push(fullPath);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
await scanDirectory(dirPath);
|
|
182
|
+
return filePaths;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Calculate overall complexity
|
|
187
|
+
* @param {Array} boundaries - Array of boundaries
|
|
188
|
+
* @returns {string} - Complexity level
|
|
189
|
+
*/
|
|
190
|
+
calculateOverallComplexity(boundaries) {
|
|
191
|
+
if (boundaries.length === 0) return 'unknown';
|
|
192
|
+
|
|
193
|
+
const complexities = boundaries.map(b => b.complexity || 1);
|
|
194
|
+
const avgComplexity = complexities.reduce((sum, c) => sum + c, 0) / complexities.length;
|
|
195
|
+
|
|
196
|
+
if (avgComplexity > 7) return 'very_high';
|
|
197
|
+
if (avgComplexity > 5) return 'high';
|
|
198
|
+
if (avgComplexity > 3) return 'medium';
|
|
199
|
+
if (avgComplexity > 2) return 'low';
|
|
200
|
+
return 'very_low';
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Calculate overall cohesion
|
|
205
|
+
* @param {Array} boundaries - Array of boundaries
|
|
206
|
+
* @returns {string} - Cohesion level
|
|
207
|
+
*/
|
|
208
|
+
calculateOverallCohesion(boundaries) {
|
|
209
|
+
if (boundaries.length === 0) return 'unknown';
|
|
210
|
+
|
|
211
|
+
const cohesions = boundaries.map(b => b.cohesion || 'medium');
|
|
212
|
+
const cohesionScores = cohesions.map(c => {
|
|
213
|
+
switch (c) {
|
|
214
|
+
case 'very_low': return 1;
|
|
215
|
+
case 'low': return 2;
|
|
216
|
+
case 'medium': return 3;
|
|
217
|
+
case 'high': return 4;
|
|
218
|
+
case 'very_high': return 5;
|
|
219
|
+
default: return 3;
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
const avgCohesion = cohesionScores.reduce((sum, c) => sum + c, 0) / cohesionScores.length;
|
|
224
|
+
|
|
225
|
+
if (avgCohesion > 4.5) return 'very_high';
|
|
226
|
+
if (avgCohesion > 3.5) return 'high';
|
|
227
|
+
if (avgCohesion > 2.5) return 'medium';
|
|
228
|
+
if (avgCohesion > 1.5) return 'low';
|
|
229
|
+
return 'very_low';
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Calculate overall coupling
|
|
234
|
+
* @param {Array} boundaries - Array of boundaries
|
|
235
|
+
* @param {Array} relationships - Array of relationships
|
|
236
|
+
* @returns {string} - Coupling level
|
|
237
|
+
*/
|
|
238
|
+
calculateOverallCoupling(boundaries, relationships) {
|
|
239
|
+
if (boundaries.length === 0) return 'unknown';
|
|
240
|
+
|
|
241
|
+
const couplingScores = boundaries.map(b => {
|
|
242
|
+
const boundaryRelationships = relationships.filter(r => r.source === b.name);
|
|
243
|
+
if (boundaryRelationships.length === 0) return 5; // Very low coupling
|
|
244
|
+
|
|
245
|
+
const avgStrength = boundaryRelationships.reduce((sum, r) => sum + r.strength, 0) / boundaryRelationships.length;
|
|
246
|
+
|
|
247
|
+
if (avgStrength > 4) return 1; // Very high coupling
|
|
248
|
+
if (avgStrength > 3) return 2; // High coupling
|
|
249
|
+
if (avgStrength > 2) return 3; // Medium coupling
|
|
250
|
+
if (avgStrength > 1) return 4; // Low coupling
|
|
251
|
+
return 5; // Very low coupling
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
const avgCoupling = couplingScores.reduce((sum, c) => sum + c, 0) / couplingScores.length;
|
|
255
|
+
|
|
256
|
+
if (avgCoupling > 4.5) return 'very_low';
|
|
257
|
+
if (avgCoupling > 3.5) return 'low';
|
|
258
|
+
if (avgCoupling > 2.5) return 'medium';
|
|
259
|
+
if (avgCoupling > 1.5) return 'high';
|
|
260
|
+
return 'very_high';
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Generate refactoring recommendations
|
|
265
|
+
* @param {BoundaryDetectionResult} result - Detection result
|
|
266
|
+
* @returns {Array} - Array of recommendations
|
|
267
|
+
*/
|
|
268
|
+
generateRefactoringRecommendations(result) {
|
|
269
|
+
const recommendations = [];
|
|
270
|
+
|
|
271
|
+
// Add boundary-specific recommendations
|
|
272
|
+
const boundaryRecommendations = generateBoundaryRecommendations(result.boundaries);
|
|
273
|
+
recommendations.push(...boundaryRecommendations);
|
|
274
|
+
|
|
275
|
+
// Add file-level recommendations
|
|
276
|
+
if (result.metadata.totalBoundaries > 20) {
|
|
277
|
+
recommendations.push({
|
|
278
|
+
type: 'file_structure',
|
|
279
|
+
priority: 'high',
|
|
280
|
+
message: 'File has too many boundaries (>20)',
|
|
281
|
+
action: 'split_into_modules'
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (result.metadata.complexity === 'very_high') {
|
|
286
|
+
recommendations.push({
|
|
287
|
+
type: 'complexity',
|
|
288
|
+
priority: 'high',
|
|
289
|
+
message: 'File has very high complexity',
|
|
290
|
+
action: 'reduce_complexity'
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (result.metadata.cohesion === 'very_low') {
|
|
295
|
+
recommendations.push({
|
|
296
|
+
type: 'cohesion',
|
|
297
|
+
priority: 'medium',
|
|
298
|
+
message: 'File has very low cohesion',
|
|
299
|
+
action: 'improve_cohesion'
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
return recommendations;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Export results to file
|
|
308
|
+
* @param {BoundaryDetectionResult} result - Detection result
|
|
309
|
+
* @param {string} outputPath - Output file path
|
|
310
|
+
* @returns {Promise<void>}
|
|
311
|
+
*/
|
|
312
|
+
async exportResults(result, outputPath) {
|
|
313
|
+
const exportData = {
|
|
314
|
+
filePath: result.filePath,
|
|
315
|
+
timestamp: new Date().toISOString(),
|
|
316
|
+
summary: result.getSummary(),
|
|
317
|
+
boundaries: result.boundaries,
|
|
318
|
+
metadata: result.metadata,
|
|
319
|
+
recommendations: this.generateRefactoringRecommendations(result)
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
await fs.promises.writeFile(outputPath, JSON.stringify(exportData, null, 2), 'utf8');
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Get detector information
|
|
327
|
+
* @returns {Object} - Detector info
|
|
328
|
+
*/
|
|
329
|
+
getDetectorInfo() {
|
|
330
|
+
return {
|
|
331
|
+
supportedTypes: Object.values(BOUNDARY_TYPES),
|
|
332
|
+
defaultOptions: this.options,
|
|
333
|
+
features: [
|
|
334
|
+
'boundary detection',
|
|
335
|
+
'complexity analysis',
|
|
336
|
+
'cohesion calculation',
|
|
337
|
+
'coupling analysis',
|
|
338
|
+
'refactoring recommendations',
|
|
339
|
+
'batch processing'
|
|
340
|
+
],
|
|
341
|
+
version: '1.0.0'
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Create detector with default configuration
|
|
347
|
+
* @param {Object} config - Configuration overrides
|
|
348
|
+
* @returns {BoundaryDetector} - Detector instance
|
|
349
|
+
*/
|
|
350
|
+
static createDefault(config = {}) {
|
|
351
|
+
return new BoundaryDetector({
|
|
352
|
+
includeComments: true,
|
|
353
|
+
includeImports: true,
|
|
354
|
+
includeExports: true,
|
|
355
|
+
minBoundarySize: 5,
|
|
356
|
+
analysisDepth: 'standard',
|
|
357
|
+
...config
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Create detector for refactoring
|
|
363
|
+
* @param {Object} config - Configuration overrides
|
|
364
|
+
* @returns {BoundaryDetector} - Refactoring detector instance
|
|
365
|
+
*/
|
|
366
|
+
static createForRefactoring(config = {}) {
|
|
367
|
+
return new BoundaryDetector({
|
|
368
|
+
includeComments: false,
|
|
369
|
+
includeImports: true,
|
|
370
|
+
includeExports: true,
|
|
371
|
+
minBoundarySize: 10,
|
|
372
|
+
analysisDepth: 'deep',
|
|
373
|
+
...config
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
module.exports = BoundaryDetector;
|