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
|
@@ -1,51 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Boundary Detection Algorithms
|
|
2
|
+
* Refactored Boundary Detection Algorithms - Main Orchestrator
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const FunctionDetector = require('./detectors/function-detector');
|
|
6
|
+
const ClassDetector = require('./detectors/class-detector');
|
|
7
|
+
const ObjectDetector = require('./detectors/object-detector');
|
|
8
|
+
const ModuleDetector = require('./detectors/module-detector');
|
|
9
|
+
const UtilityDetector = require('./detectors/utility-detector');
|
|
10
|
+
const ConfigDetector = require('./detectors/config-detector');
|
|
11
|
+
const ConstantDetector = require('./detectors/constant-detector');
|
|
12
|
+
const { COHESION_LEVELS } = require('./boundary-types');
|
|
6
13
|
|
|
7
14
|
/**
|
|
8
|
-
* Boundary detector class
|
|
15
|
+
* Boundary detector class - orchestrates all specialized detectors
|
|
9
16
|
*/
|
|
10
17
|
class BoundaryDetector {
|
|
11
18
|
constructor() {
|
|
12
|
-
this.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
initializePatterns() {
|
|
20
|
-
return {
|
|
21
|
-
// Function patterns
|
|
22
|
-
function: {
|
|
23
|
-
declaration: /(?:function\s+(\w+)\s*\(|const\s+(\w+)\s*=\s*(?:async\s+)?(?:function|\([^)]*\)\s*=>)/g,
|
|
24
|
-
export: /(?:export\s+(?:default\s+)?(?:function|const|let|var)\s+(\w+))/g,
|
|
25
|
-
method: /(?:async\s+)?(\w+)\s*\([^)]*\)\s*{/g,
|
|
26
|
-
arrow: /(?:const|let|var)\s+(\w+)\s*=\s*(?:async\s+)?\([^)]*\)\s*=>/g
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
// Class patterns
|
|
30
|
-
class: {
|
|
31
|
-
declaration: /(?:class\s+(\w+)|export\s+(?:default\s+)?class\s+(\w+))/g,
|
|
32
|
-
method: /(?:async\s+)?(\w+)\s*\([^)]*\)\s*{/g,
|
|
33
|
-
property: /(\w+)\s*[=:]/g
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
// Object patterns
|
|
37
|
-
object: {
|
|
38
|
-
declaration: /(?:const|let|var)\s+(\w+)\s*=\s*{/g,
|
|
39
|
-
property: /(\w+)\s*:/g,
|
|
40
|
-
method: /(\w+)\s*\([^)]*\)\s*{/g
|
|
41
|
-
},
|
|
42
|
-
|
|
43
|
-
// Module patterns
|
|
44
|
-
module: {
|
|
45
|
-
export: /export\s+(?:\{([^}]+)\}|(?:default\s+)?(?:const|let|var|function|class)\s+(\w+))/g,
|
|
46
|
-
import: /import\s+(?:\{([^}]+)\}|(?:\*\s+as)?(\w+))/g
|
|
47
|
-
}
|
|
48
|
-
};
|
|
19
|
+
this.functionDetector = new FunctionDetector();
|
|
20
|
+
this.classDetector = new ClassDetector();
|
|
21
|
+
this.objectDetector = new ObjectDetector();
|
|
22
|
+
this.moduleDetector = new ModuleDetector();
|
|
23
|
+
this.utilityDetector = new UtilityDetector();
|
|
24
|
+
this.configDetector = new ConfigDetector();
|
|
25
|
+
this.constantDetector = new ConstantDetector();
|
|
49
26
|
}
|
|
50
27
|
|
|
51
28
|
/**
|
|
@@ -59,502 +36,29 @@ class BoundaryDetector {
|
|
|
59
36
|
const boundaries = [];
|
|
60
37
|
|
|
61
38
|
// Detect function boundaries
|
|
62
|
-
boundaries.push(...this.detectFunctionBoundaries(lines, filePath));
|
|
39
|
+
boundaries.push(...this.functionDetector.detectFunctionBoundaries(lines, filePath));
|
|
63
40
|
|
|
64
41
|
// Detect class boundaries
|
|
65
|
-
boundaries.push(...this.detectClassBoundaries(lines, filePath));
|
|
42
|
+
boundaries.push(...this.classDetector.detectClassBoundaries(lines, filePath));
|
|
66
43
|
|
|
67
44
|
// Detect object boundaries
|
|
68
|
-
boundaries.push(...this.detectObjectBoundaries(lines, filePath));
|
|
45
|
+
boundaries.push(...this.objectDetector.detectObjectBoundaries(lines, filePath));
|
|
69
46
|
|
|
70
47
|
// Detect module boundaries
|
|
71
|
-
boundaries.push(...this.detectModuleBoundaries(lines, filePath));
|
|
48
|
+
boundaries.push(...this.moduleDetector.detectModuleBoundaries(lines, filePath));
|
|
72
49
|
|
|
73
50
|
// Detect utility boundaries
|
|
74
|
-
boundaries.push(...this.detectUtilityBoundaries(lines, filePath));
|
|
51
|
+
boundaries.push(...this.utilityDetector.detectUtilityBoundaries(lines, filePath));
|
|
75
52
|
|
|
76
53
|
// Detect config boundaries
|
|
77
|
-
boundaries.push(...this.detectConfigBoundaries(lines, filePath));
|
|
54
|
+
boundaries.push(...this.configDetector.detectConfigBoundaries(lines, filePath));
|
|
78
55
|
|
|
79
56
|
// Detect constant boundaries
|
|
80
|
-
boundaries.push(...this.detectConstantBoundaries(lines, filePath));
|
|
81
|
-
|
|
82
|
-
return boundaries;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Detect function boundaries
|
|
87
|
-
* @param {Array} lines - Source code lines
|
|
88
|
-
* @param {string} filePath - File path
|
|
89
|
-
* @returns {Array} Array of function boundaries
|
|
90
|
-
*/
|
|
91
|
-
detectFunctionBoundaries(lines, filePath) {
|
|
92
|
-
const boundaries = [];
|
|
93
|
-
const sourceCode = lines.join('\n');
|
|
94
|
-
|
|
95
|
-
// Find function declarations
|
|
96
|
-
const matches = [...sourceCode.matchAll(this.patterns.function.declaration)];
|
|
97
|
-
|
|
98
|
-
for (const match of matches) {
|
|
99
|
-
const functionName = match[1] || match[2];
|
|
100
|
-
if (functionName) {
|
|
101
|
-
const boundary = this.createBoundary(
|
|
102
|
-
BOUNDARY_TYPES.FUNCTION,
|
|
103
|
-
functionName,
|
|
104
|
-
lines,
|
|
105
|
-
filePath,
|
|
106
|
-
match.index
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
if (boundary) {
|
|
110
|
-
boundaries.push(boundary);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
57
|
+
boundaries.push(...this.constantDetector.detectConstantBoundaries(lines, filePath));
|
|
114
58
|
|
|
115
59
|
return boundaries;
|
|
116
60
|
}
|
|
117
61
|
|
|
118
|
-
/**
|
|
119
|
-
* Detect class boundaries
|
|
120
|
-
* @param {Array} lines - Source code lines
|
|
121
|
-
* @param {string} filePath - File path
|
|
122
|
-
* @returns {Array} Array of class boundaries
|
|
123
|
-
*/
|
|
124
|
-
detectClassBoundaries(lines, filePath) {
|
|
125
|
-
const boundaries = [];
|
|
126
|
-
const sourceCode = lines.join('\n');
|
|
127
|
-
|
|
128
|
-
// Find class declarations
|
|
129
|
-
const matches = [...sourceCode.matchAll(this.patterns.class.declaration)];
|
|
130
|
-
|
|
131
|
-
for (const match of matches) {
|
|
132
|
-
const className = match[1] || match[2];
|
|
133
|
-
if (className) {
|
|
134
|
-
const boundary = this.createBoundary(
|
|
135
|
-
BOUNDARY_TYPES.CLASS,
|
|
136
|
-
className,
|
|
137
|
-
lines,
|
|
138
|
-
filePath,
|
|
139
|
-
match.index
|
|
140
|
-
);
|
|
141
|
-
|
|
142
|
-
if (boundary) {
|
|
143
|
-
boundaries.push(boundary);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return boundaries;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Detect object boundaries
|
|
153
|
-
* @param {Array} lines - Source code lines
|
|
154
|
-
* @param {string} filePath - File path
|
|
155
|
-
* @returns {Array} Array of object boundaries
|
|
156
|
-
*/
|
|
157
|
-
detectObjectBoundaries(lines, filePath) {
|
|
158
|
-
const boundaries = [];
|
|
159
|
-
const sourceCode = lines.join('\n');
|
|
160
|
-
|
|
161
|
-
// Find object declarations
|
|
162
|
-
const matches = [...sourceCode.matchAll(this.patterns.object.declaration)];
|
|
163
|
-
|
|
164
|
-
for (const match of matches) {
|
|
165
|
-
const objectName = match[1];
|
|
166
|
-
if (objectName) {
|
|
167
|
-
const boundary = this.createBoundary(
|
|
168
|
-
BOUNDARY_TYPES.OBJECT,
|
|
169
|
-
objectName,
|
|
170
|
-
lines,
|
|
171
|
-
filePath,
|
|
172
|
-
match.index
|
|
173
|
-
);
|
|
174
|
-
|
|
175
|
-
if (boundary) {
|
|
176
|
-
boundaries.push(boundary);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
return boundaries;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Detect module boundaries
|
|
186
|
-
* @param {Array} lines - Source code lines
|
|
187
|
-
* @param {string} filePath - File path
|
|
188
|
-
* @returns {Array} Array of module boundaries
|
|
189
|
-
*/
|
|
190
|
-
detectModuleBoundaries(lines, filePath) {
|
|
191
|
-
const boundaries = [];
|
|
192
|
-
const sourceCode = lines.join('\n');
|
|
193
|
-
|
|
194
|
-
// Find export statements
|
|
195
|
-
const matches = [...sourceCode.matchAll(this.patterns.module.export)];
|
|
196
|
-
|
|
197
|
-
for (const match of matches) {
|
|
198
|
-
const exportNames = match[1] ? match[1].split(',').map(s => s.trim()) : [match[2]];
|
|
199
|
-
|
|
200
|
-
for (const exportName of exportNames) {
|
|
201
|
-
if (exportName && exportName !== 'default') {
|
|
202
|
-
const boundary = this.createBoundary(
|
|
203
|
-
BOUNDARY_TYPES.MODULE,
|
|
204
|
-
exportName,
|
|
205
|
-
lines,
|
|
206
|
-
filePath,
|
|
207
|
-
match.index
|
|
208
|
-
);
|
|
209
|
-
|
|
210
|
-
if (boundary) {
|
|
211
|
-
boundaries.push(boundary);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
return boundaries;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* Detect utility boundaries
|
|
222
|
-
* @param {Array} lines - Source code lines
|
|
223
|
-
* @param {string} filePath - File path
|
|
224
|
-
* @returns {Array} Array of utility boundaries
|
|
225
|
-
*/
|
|
226
|
-
detectUtilityBoundaries(lines, filePath) {
|
|
227
|
-
const boundaries = [];
|
|
228
|
-
|
|
229
|
-
// Look for utility function patterns
|
|
230
|
-
for (let i = 0; i < lines.length; i++) {
|
|
231
|
-
const line = lines[i].trim();
|
|
232
|
-
|
|
233
|
-
// Helper function patterns
|
|
234
|
-
if (this.isUtilityFunction(line)) {
|
|
235
|
-
const functionName = this.extractUtilityFunctionName(line);
|
|
236
|
-
if (functionName) {
|
|
237
|
-
const boundary = this.createBoundary(
|
|
238
|
-
BOUNDARY_TYPES.UTILITY,
|
|
239
|
-
functionName,
|
|
240
|
-
lines,
|
|
241
|
-
filePath,
|
|
242
|
-
i
|
|
243
|
-
);
|
|
244
|
-
|
|
245
|
-
if (boundary) {
|
|
246
|
-
boundaries.push(boundary);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
return boundaries;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Detect config boundaries
|
|
257
|
-
* @param {Array} lines - Source code lines
|
|
258
|
-
* @param {string} filePath - File path
|
|
259
|
-
* @returns {Array} Array of config boundaries
|
|
260
|
-
*/
|
|
261
|
-
detectConfigBoundaries(lines, filePath) {
|
|
262
|
-
const boundaries = [];
|
|
263
|
-
|
|
264
|
-
// Look for config object patterns
|
|
265
|
-
for (let i = 0; i < lines.length; i++) {
|
|
266
|
-
const line = lines[i].trim();
|
|
267
|
-
|
|
268
|
-
// Config object patterns
|
|
269
|
-
if (this.isConfigObject(line)) {
|
|
270
|
-
const configName = this.extractConfigObjectName(line);
|
|
271
|
-
if (configName) {
|
|
272
|
-
const boundary = this.createBoundary(
|
|
273
|
-
BOUNDARY_TYPES.CONFIG,
|
|
274
|
-
configName,
|
|
275
|
-
lines,
|
|
276
|
-
filePath,
|
|
277
|
-
i
|
|
278
|
-
);
|
|
279
|
-
|
|
280
|
-
if (boundary) {
|
|
281
|
-
boundaries.push(boundary);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
return boundaries;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* Detect constant boundaries
|
|
292
|
-
* @param {Array} lines - Source code lines
|
|
293
|
-
* @param {string} filePath - File path
|
|
294
|
-
* @returns {Array} Array of constant boundaries
|
|
295
|
-
*/
|
|
296
|
-
detectConstantBoundaries(lines, filePath) {
|
|
297
|
-
const boundaries = [];
|
|
298
|
-
|
|
299
|
-
// Look for constant patterns
|
|
300
|
-
for (let i = 0; i < lines.length; i++) {
|
|
301
|
-
const line = lines[i].trim();
|
|
302
|
-
|
|
303
|
-
// Constant patterns
|
|
304
|
-
if (this.isConstantDeclaration(line)) {
|
|
305
|
-
const constantName = this.extractConstantName(line);
|
|
306
|
-
if (constantName) {
|
|
307
|
-
const boundary = this.createBoundary(
|
|
308
|
-
BOUNDARY_TYPES.CONSTANT,
|
|
309
|
-
constantName,
|
|
310
|
-
lines,
|
|
311
|
-
filePath,
|
|
312
|
-
i
|
|
313
|
-
);
|
|
314
|
-
|
|
315
|
-
if (boundary) {
|
|
316
|
-
boundaries.push(boundary);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
return boundaries;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
/**
|
|
326
|
-
* Create boundary from detection
|
|
327
|
-
* @param {string} type - Boundary type
|
|
328
|
-
* @param {string} name - Boundary name
|
|
329
|
-
* @param {Array} lines - Source code lines
|
|
330
|
-
* @param {string} filePath - File path
|
|
331
|
-
* @param {number} startIndex - Start index in source
|
|
332
|
-
* @returns {Object|null} Boundary object or null
|
|
333
|
-
*/
|
|
334
|
-
createBoundary(type, name, lines, filePath, startIndex) {
|
|
335
|
-
const { startLine, endLine } = this.findBoundaryExtent(lines, startIndex, type);
|
|
336
|
-
|
|
337
|
-
if (startLine === -1 || endLine === -1) {
|
|
338
|
-
return null;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
const { ModuleBoundary } = require('./boundary-types');
|
|
342
|
-
const boundary = new ModuleBoundary(type, name, startLine + 1, endLine + 1, filePath);
|
|
343
|
-
|
|
344
|
-
// Analyze boundary properties
|
|
345
|
-
this.analyzeBoundary(boundary, lines, startLine, endLine);
|
|
346
|
-
|
|
347
|
-
return boundary;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
/**
|
|
351
|
-
* Find the extent of a boundary
|
|
352
|
-
* @param {Array} lines - Source code lines
|
|
353
|
-
* @param {number} startIndex - Start index
|
|
354
|
-
* @param {string} type - Boundary type
|
|
355
|
-
* @returns {Object} Start and end line numbers
|
|
356
|
-
*/
|
|
357
|
-
findBoundaryExtent(lines, startIndex, type) {
|
|
358
|
-
let startLine = -1;
|
|
359
|
-
let endLine = -1;
|
|
360
|
-
let braceCount = 0;
|
|
361
|
-
let inString = false;
|
|
362
|
-
let stringChar = null;
|
|
363
|
-
|
|
364
|
-
for (let i = startIndex; i < lines.length; i++) {
|
|
365
|
-
const line = lines[i];
|
|
366
|
-
|
|
367
|
-
// Track string literals
|
|
368
|
-
for (let j = 0; j < line.length; j++) {
|
|
369
|
-
const char = line[j];
|
|
370
|
-
|
|
371
|
-
if (!inString && (char === '"' || char === "'" || char === '`')) {
|
|
372
|
-
inString = true;
|
|
373
|
-
stringChar = char;
|
|
374
|
-
} else if (inString && char === stringChar) {
|
|
375
|
-
inString = false;
|
|
376
|
-
stringChar = null;
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
// Skip lines inside strings
|
|
381
|
-
if (inString) continue;
|
|
382
|
-
|
|
383
|
-
// Count braces for block detection
|
|
384
|
-
const openBraces = (line.match(/\{/g) || []).length;
|
|
385
|
-
const closeBraces = (line.match(/\}/g) || []).length;
|
|
386
|
-
|
|
387
|
-
braceCount += openBraces - closeBraces;
|
|
388
|
-
|
|
389
|
-
// Set start line on first detection
|
|
390
|
-
if (startLine === -1) {
|
|
391
|
-
startLine = i;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
// End when braces are balanced and we're past the start
|
|
395
|
-
if (braceCount <= 0 && i > startIndex) {
|
|
396
|
-
endLine = i;
|
|
397
|
-
break;
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
return { startLine, endLine };
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
/**
|
|
405
|
-
* Analyze boundary properties
|
|
406
|
-
* @param {Object} boundary - Boundary object
|
|
407
|
-
* @param {Array} lines - Source code lines
|
|
408
|
-
* @param {number} startLine - Start line number
|
|
409
|
-
* @param {number} endLine - End line number
|
|
410
|
-
*/
|
|
411
|
-
analyzeBoundary(boundary, lines, startLine, endLine) {
|
|
412
|
-
const boundaryLines = lines.slice(startLine, endLine + 1);
|
|
413
|
-
const sourceCode = boundaryLines.join('\n');
|
|
414
|
-
|
|
415
|
-
// Calculate complexity
|
|
416
|
-
const complexity = this.calculateComplexity(sourceCode);
|
|
417
|
-
boundary.setComplexity(complexity);
|
|
418
|
-
|
|
419
|
-
// Find dependencies
|
|
420
|
-
const dependencies = this.findDependencies(sourceCode);
|
|
421
|
-
for (const dep of dependencies) {
|
|
422
|
-
boundary.addDependency(dep);
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
// Find exports
|
|
426
|
-
const exports = this.findExports(sourceCode, boundary.type);
|
|
427
|
-
for (const exp of exports) {
|
|
428
|
-
boundary.addExport(exp);
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
// Calculate cohesion
|
|
432
|
-
const cohesion = this.calculateCohesion(boundary, boundaryLines);
|
|
433
|
-
boundary.setCohesion(cohesion);
|
|
434
|
-
|
|
435
|
-
// Determine extractability
|
|
436
|
-
const extractable = this.isExtractable(boundary, boundaryLines);
|
|
437
|
-
boundary.setExtractable(extractable);
|
|
438
|
-
|
|
439
|
-
// Set confidence based on analysis
|
|
440
|
-
const confidence = this.calculateConfidence(boundary);
|
|
441
|
-
boundary.setConfidence(confidence);
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
/**
|
|
445
|
-
* Calculate complexity score
|
|
446
|
-
* @param {string} sourceCode - Source code
|
|
447
|
-
* @returns {number} Complexity score
|
|
448
|
-
*/
|
|
449
|
-
calculateComplexity(sourceCode) {
|
|
450
|
-
let complexity = 0;
|
|
451
|
-
|
|
452
|
-
// Cyclomatic complexity indicators
|
|
453
|
-
complexity += (sourceCode.match(/if\s*\(/g) || []).length * 1;
|
|
454
|
-
complexity += (sourceCode.match(/else\s+if/g) || []).length * 1;
|
|
455
|
-
complexity += (sourceCode.match(/while\s*\(/g) || []).length * 2;
|
|
456
|
-
complexity += (sourceCode.match(/for\s*\(/g) || []).length * 2;
|
|
457
|
-
complexity += (sourceCode.match(/switch\s*\(/g) || []).length * 2;
|
|
458
|
-
complexity += (sourceCode.match(/catch\s*\(/g) || []).length * 2;
|
|
459
|
-
complexity += (sourceCode.match(/&&/g) || []).length * 1;
|
|
460
|
-
complexity += (sourceCode.match(/\|\|/g) || []).length * 1;
|
|
461
|
-
|
|
462
|
-
// Nesting complexity
|
|
463
|
-
const maxNesting = this.calculateMaxNesting(sourceCode);
|
|
464
|
-
complexity += maxNesting * 2;
|
|
465
|
-
|
|
466
|
-
// Length complexity
|
|
467
|
-
const lineCount = sourceCode.split('\n').length;
|
|
468
|
-
if (lineCount > 50) complexity += 5;
|
|
469
|
-
if (lineCount > 100) complexity += 10;
|
|
470
|
-
if (lineCount > 200) complexity += 20;
|
|
471
|
-
|
|
472
|
-
return Math.min(100, complexity);
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
/**
|
|
476
|
-
* Calculate maximum nesting level
|
|
477
|
-
* @param {string} sourceCode - Source code
|
|
478
|
-
* @returns {number} Maximum nesting level
|
|
479
|
-
*/
|
|
480
|
-
calculateMaxNesting(sourceCode) {
|
|
481
|
-
let maxNesting = 0;
|
|
482
|
-
let currentNesting = 0;
|
|
483
|
-
let inString = false;
|
|
484
|
-
let stringChar = null;
|
|
485
|
-
|
|
486
|
-
for (const char of sourceCode) {
|
|
487
|
-
if (!inString && (char === '"' || char === "'" || char === '`')) {
|
|
488
|
-
inString = true;
|
|
489
|
-
stringChar = char;
|
|
490
|
-
} else if (inString && char === stringChar) {
|
|
491
|
-
inString = false;
|
|
492
|
-
stringChar = null;
|
|
493
|
-
} else if (!inString) {
|
|
494
|
-
if (char === '{') {
|
|
495
|
-
currentNesting++;
|
|
496
|
-
maxNesting = Math.max(maxNesting, currentNesting);
|
|
497
|
-
} else if (char === '}') {
|
|
498
|
-
currentNesting--;
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
return maxNesting;
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
/**
|
|
507
|
-
* Find dependencies in boundary
|
|
508
|
-
* @param {string} sourceCode - Source code
|
|
509
|
-
* @returns {Array} Array of dependencies
|
|
510
|
-
*/
|
|
511
|
-
findDependencies(sourceCode) {
|
|
512
|
-
const dependencies = [];
|
|
513
|
-
|
|
514
|
-
// Import statements
|
|
515
|
-
const importMatches = sourceCode.match(/import\s+.+from\s+['"]([^'"]+)['"]/g);
|
|
516
|
-
if (importMatches) {
|
|
517
|
-
for (const match of importMatches) {
|
|
518
|
-
dependencies.push(match[1]);
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
// Require statements
|
|
523
|
-
const requireMatches = sourceCode.match(/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g);
|
|
524
|
-
if (requireMatches) {
|
|
525
|
-
for (const match of requireMatches) {
|
|
526
|
-
dependencies.push(match[1]);
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
return [...new Set(dependencies)];
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
/**
|
|
534
|
-
* Find exports in boundary
|
|
535
|
-
* @param {string} sourceCode - Source code
|
|
536
|
-
* @param {string} type - Boundary type
|
|
537
|
-
* @returns {Array} Array of exports
|
|
538
|
-
*/
|
|
539
|
-
findExports(sourceCode, type) {
|
|
540
|
-
const exports = [];
|
|
541
|
-
|
|
542
|
-
if (type === BOUNDARY_TYPES.FUNCTION || type === BOUNDARY_TYPES.CLASS) {
|
|
543
|
-
// Look for explicit exports
|
|
544
|
-
const exportMatches = sourceCode.match(/export\s+(?:default\s+)?(?:\w+|\{[^}]+\})/g);
|
|
545
|
-
if (exportMatches) {
|
|
546
|
-
for (const match of exportMatches) {
|
|
547
|
-
const exportName = match.replace(/export\s+(?:default\s+)?/, '').trim();
|
|
548
|
-
if (exportName && exportName !== '{' && exportName !== '}') {
|
|
549
|
-
exports.push(exportName);
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
return exports;
|
|
556
|
-
}
|
|
557
|
-
|
|
558
62
|
/**
|
|
559
63
|
* Calculate cohesion level
|
|
560
64
|
* @param {Object} boundary - Boundary object
|
|
@@ -565,7 +69,7 @@ class BoundaryDetector {
|
|
|
565
69
|
let cohesionScore = 0;
|
|
566
70
|
|
|
567
71
|
// Single responsibility (high cohesion)
|
|
568
|
-
if (boundary.type ===
|
|
72
|
+
if (boundary.type === 'FUNCTION' || boundary.type === 'CLASS') {
|
|
569
73
|
cohesionScore += 40;
|
|
570
74
|
}
|
|
571
75
|
|
|
@@ -656,86 +160,12 @@ class BoundaryDetector {
|
|
|
656
160
|
}
|
|
657
161
|
|
|
658
162
|
// Increase confidence for extractable boundaries
|
|
659
|
-
if (
|
|
163
|
+
if (this.isExtractable(boundary, boundary.lines)) {
|
|
660
164
|
confidence += 0.1;
|
|
661
165
|
}
|
|
662
166
|
|
|
663
167
|
return Math.min(1.0, confidence);
|
|
664
168
|
}
|
|
665
|
-
|
|
666
|
-
/**
|
|
667
|
-
* Check if line is a utility function
|
|
668
|
-
* @param {string} line - Code line
|
|
669
|
-
* @returns {boolean} Whether line is utility function
|
|
670
|
-
*/
|
|
671
|
-
isUtilityFunction(line) {
|
|
672
|
-
const utilityPatterns = [
|
|
673
|
-
/(?:const|let|var)\s+\w+\s*=\s*\([^)]*\)\s*=>/,
|
|
674
|
-
/function\s+(?:is|has|get|set|calculate|compute|parse|format|validate|check)/,
|
|
675
|
-
/(?:is|has|get|set|calculate|compute|parse|format|validate|check)\w+\s*\(/
|
|
676
|
-
];
|
|
677
|
-
|
|
678
|
-
return utilityPatterns.some(pattern => pattern.test(line));
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
/**
|
|
682
|
-
* Extract utility function name
|
|
683
|
-
* @param {string} line - Code line
|
|
684
|
-
* @returns {string|null} Function name
|
|
685
|
-
*/
|
|
686
|
-
extractUtilityFunctionName(line) {
|
|
687
|
-
const match = line.match(/(?:const|let|var)\s+(\w+)\s*=|function\s+(\w+)/);
|
|
688
|
-
return match ? match[1] || match[2] : null;
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
/**
|
|
692
|
-
* Check if line is config object
|
|
693
|
-
* @param {string} line - Code line
|
|
694
|
-
* @returns {boolean} Whether line is config object
|
|
695
|
-
*/
|
|
696
|
-
isConfigObject(line) {
|
|
697
|
-
const configPatterns = [
|
|
698
|
-
/(?:const|let|var)\s+\w*config\w*\s*=/,
|
|
699
|
-
/(?:const|let|var)\s+\w*Config\w*\s*=/,
|
|
700
|
-
/(?:const|let|var)\s+\w*Settings\w*\s*=/
|
|
701
|
-
];
|
|
702
|
-
|
|
703
|
-
return configPatterns.some(pattern => pattern.test(line));
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
/**
|
|
707
|
-
* Extract config object name
|
|
708
|
-
* @param {string} line - Code line
|
|
709
|
-
* @returns {string|null} Config name
|
|
710
|
-
*/
|
|
711
|
-
extractConfigObjectName(line) {
|
|
712
|
-
const match = line.match(/(?:const|let|var)\s+(\w*config\w*|\w*Config\w*|\w*Settings\w*)\s*=/);
|
|
713
|
-
return match ? match[1] : null;
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
/**
|
|
717
|
-
* Check if line is constant declaration
|
|
718
|
-
* @param {string} line - Code line
|
|
719
|
-
* @returns {boolean} Whether line is constant declaration
|
|
720
|
-
*/
|
|
721
|
-
isConstantDeclaration(line) {
|
|
722
|
-
const constantPatterns = [
|
|
723
|
-
/const\s+[A-Z_][A-Z0-9_]*\s*=/,
|
|
724
|
-
/(?:const|let|var)\s+[A-Z_][A-Z0-9_]*\s*=/
|
|
725
|
-
];
|
|
726
|
-
|
|
727
|
-
return constantPatterns.some(pattern => pattern.test(line));
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
/**
|
|
731
|
-
* Extract constant name
|
|
732
|
-
* @param {string} line - Code line
|
|
733
|
-
* @returns {string|null} Constant name
|
|
734
|
-
*/
|
|
735
|
-
extractConstantName(line) {
|
|
736
|
-
const match = line.match(/(?:const|let|var)\s+([A-Z_][A-Z0-9_]*)\s*=/);
|
|
737
|
-
return match ? match[1] : null;
|
|
738
|
-
}
|
|
739
169
|
}
|
|
740
170
|
|
|
741
171
|
module.exports = BoundaryDetector;
|