vibecodingmachine-core 2026.2.20-438 → 2026.2.26-1642
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/README.md +240 -0
- package/package.json +10 -2
- package/src/agents/Agent.js +300 -0
- package/src/agents/AgentAdditionService.js +311 -0
- package/src/agents/AgentCheckService.js +690 -0
- package/src/agents/AgentInstallationService.js +140 -0
- package/src/agents/AgentSetupService.js +467 -0
- package/src/agents/AgentStatus.js +183 -0
- package/src/agents/AgentVerificationService.js +634 -0
- package/src/agents/ConfigurationSchemaValidator.js +543 -0
- package/src/agents/EnvironmentConfigurationManager.js +602 -0
- package/src/agents/InstallationErrorHandler.js +372 -0
- package/src/agents/InstallationLog.js +363 -0
- package/src/agents/InstallationMethod.js +510 -0
- package/src/agents/InstallationOrchestrator.js +352 -0
- package/src/agents/InstallationProgressReporter.js +372 -0
- package/src/agents/InstallationRetryManager.js +322 -0
- package/src/agents/InstallationType.js +254 -0
- package/src/agents/OperationTypes.js +310 -0
- package/src/agents/PerformanceMetricsCollector.js +493 -0
- package/src/agents/SecurityValidationService.js +534 -0
- package/src/agents/VerificationTest.js +354 -0
- package/src/agents/VerificationType.js +226 -0
- package/src/agents/WindowsPermissionHandler.js +518 -0
- package/src/agents/config/AgentConfigManager.js +393 -0
- package/src/agents/config/AgentDefaultsRegistry.js +373 -0
- package/src/agents/config/ConfigValidator.js +281 -0
- package/src/agents/discovery/AgentDiscoveryService.js +707 -0
- package/src/agents/logging/AgentLogger.js +511 -0
- package/src/agents/status/AgentStatusManager.js +481 -0
- package/src/agents/storage/FileManager.js +454 -0
- package/src/agents/verification/AgentCommunicationTester.js +474 -0
- package/src/agents/verification/BaseVerifier.js +430 -0
- package/src/agents/verification/CommandVerifier.js +480 -0
- package/src/agents/verification/FileOperationVerifier.js +453 -0
- package/src/agents/verification/ResultAnalyzer.js +707 -0
- package/src/agents/verification/TestRequirementManager.js +495 -0
- package/src/agents/verification/VerificationRunner.js +433 -0
- package/src/agents/windows/BaseWindowsInstaller.js +441 -0
- package/src/agents/windows/ChocolateyInstaller.js +509 -0
- package/src/agents/windows/DirectInstaller.js +443 -0
- package/src/agents/windows/InstallerFactory.js +391 -0
- package/src/agents/windows/NpmInstaller.js +505 -0
- package/src/agents/windows/PowerShellInstaller.js +458 -0
- package/src/agents/windows/WinGetInstaller.js +390 -0
- package/src/analysis/analysis-reporter.js +132 -0
- package/src/analysis/boundary-detector.js +712 -0
- package/src/analysis/categorizer.js +340 -0
- package/src/analysis/codebase-scanner.js +384 -0
- package/src/analysis/line-counter.js +513 -0
- package/src/analysis/priority-calculator.js +679 -0
- package/src/analysis/report/analysis-report.js +250 -0
- package/src/analysis/report/package-analyzer.js +278 -0
- package/src/analysis/report/recommendation-generator.js +382 -0
- package/src/analysis/report/statistics-generator.js +515 -0
- package/src/analysis/reports/analysis-report-model.js +101 -0
- package/src/analysis/reports/recommendation-generator.js +283 -0
- package/src/analysis/reports/report-generators.js +191 -0
- package/src/analysis/reports/statistics-calculator.js +231 -0
- package/src/analysis/reports/trend-analyzer.js +219 -0
- package/src/analysis/strategy-generator.js +814 -0
- package/src/auto-mode/AutoModeBusinessLogic.js +836 -0
- package/src/config/refactoring-config.js +307 -0
- package/src/health-tracking/json-storage.js +38 -2
- package/src/ide-integration/applescript-manager-core.js +233 -0
- package/src/ide-integration/applescript-manager.cjs +357 -28
- package/src/ide-integration/applescript-manager.js +89 -3599
- package/src/ide-integration/cdp-manager.js +306 -0
- package/src/ide-integration/claude-code-cli-manager.cjs +1 -1
- package/src/ide-integration/continuation-handler.js +337 -0
- package/src/ide-integration/ide-status-checker.js +292 -0
- package/src/ide-integration/macos-ide-manager.js +627 -0
- package/src/ide-integration/macos-text-sender.js +528 -0
- package/src/ide-integration/response-reader.js +548 -0
- package/src/ide-integration/windows-automation-manager.js +121 -0
- package/src/ide-integration/windows-ide-manager.js +373 -0
- package/src/index.cjs +25 -3
- package/src/index.js +15 -1
- package/src/llm/direct-llm-manager.cjs +90 -2
- package/src/models/compliance-report.js +538 -0
- package/src/models/file-analysis.js +681 -0
- package/src/models/refactoring-plan.js +770 -0
- package/src/monitoring/alert-system.js +834 -0
- package/src/monitoring/compliance-progress-tracker.js +437 -0
- package/src/monitoring/continuous-scan-notifications.js +661 -0
- package/src/monitoring/continuous-scanner.js +279 -0
- package/src/monitoring/file-monitor/file-analyzer.js +262 -0
- package/src/monitoring/file-monitor/file-monitor.js +237 -0
- package/src/monitoring/file-monitor/watcher.js +194 -0
- package/src/monitoring/file-monitor.js +17 -0
- package/src/monitoring/notification-manager.js +437 -0
- package/src/monitoring/scanner-core.js +368 -0
- package/src/monitoring/scanner-events.js +214 -0
- package/src/monitoring/violation-notification-system.js +515 -0
- package/src/refactoring/boundaries/cohesion-analyzer.js +316 -0
- package/src/refactoring/boundaries/extraction-result.js +285 -0
- package/src/refactoring/boundaries/extraction-strategies.js +392 -0
- package/src/refactoring/boundaries/module-boundary.js +209 -0
- package/src/refactoring/boundary/boundary-detector.js +741 -0
- package/src/refactoring/boundary/boundary-types.js +405 -0
- package/src/refactoring/boundary/extraction-strategies.js +554 -0
- package/src/refactoring/boundary-extraction-result.js +77 -0
- package/src/refactoring/boundary-extraction-strategies.js +330 -0
- package/src/refactoring/boundary-extractor.js +384 -0
- package/src/refactoring/boundary-types.js +46 -0
- package/src/refactoring/circular/circular-dependency.js +88 -0
- package/src/refactoring/circular/cycle-detection.js +147 -0
- package/src/refactoring/circular/dependency-node.js +82 -0
- package/src/refactoring/circular/dependency-result.js +107 -0
- package/src/refactoring/circular/dependency-types.js +58 -0
- package/src/refactoring/circular/graph-builder.js +213 -0
- package/src/refactoring/circular/resolution-strategy.js +72 -0
- package/src/refactoring/circular/strategy-generator.js +229 -0
- package/src/refactoring/circular-dependency-resolver-original.js +809 -0
- package/src/refactoring/circular-dependency-resolver.js +200 -0
- package/src/refactoring/code-mover.js +761 -0
- package/src/refactoring/file-splitter.js +696 -0
- package/src/refactoring/functionality-validator.js +816 -0
- package/src/refactoring/import-manager.js +774 -0
- package/src/refactoring/module-boundary.js +107 -0
- package/src/refactoring/refactoring-executor.js +672 -0
- package/src/refactoring/refactoring-rollback.js +614 -0
- package/src/refactoring/test-validator.js +631 -0
- package/src/requirement-management/default-requirement-manager.js +321 -0
- package/src/requirement-management/requirement-file-parser.js +159 -0
- package/src/requirement-management/requirement-sequencer.js +221 -0
- package/src/rui/commands/AgentCommandParser.js +600 -0
- package/src/rui/commands/AgentCommands.js +487 -0
- package/src/rui/commands/AgentResponseFormatter.js +832 -0
- package/src/scripts/verify-full-compliance.js +269 -0
- package/src/sync/sync-engine-core.js +1 -0
- package/src/sync/sync-engine-remote-handlers.js +135 -0
- package/src/task-generation/automated-task-generator.js +351 -0
- package/src/task-generation/prioritizer.js +287 -0
- package/src/task-generation/task-list-updater.js +215 -0
- package/src/task-generation/task-management-integration.js +480 -0
- package/src/task-generation/task-manager-integration.js +270 -0
- package/src/task-generation/violation-task-generator.js +474 -0
- package/src/task-management/continuous-scan-integration.js +342 -0
- package/src/timeout-management/index.js +12 -3
- package/src/timeout-management/response-time-tracker.js +167 -0
- package/src/timeout-management/timeout-calculator.js +159 -0
- package/src/timeout-management/timeout-config-manager.js +172 -0
- package/src/utils/ast-analyzer.js +417 -0
- package/src/utils/current-requirement-manager.js +276 -0
- package/src/utils/current-requirement-operations.js +472 -0
- package/src/utils/dependency-mapper.js +456 -0
- package/src/utils/download-with-progress.js +4 -2
- package/src/utils/electron-update-checker.js +4 -1
- package/src/utils/file-size-analyzer.js +272 -0
- package/src/utils/import-updater.js +280 -0
- package/src/utils/refactoring-tools.js +512 -0
- package/src/utils/report-generator.js +569 -0
- package/src/utils/reports/report-analysis.js +218 -0
- package/src/utils/reports/report-types.js +55 -0
- package/src/utils/reports/summary-generators.js +102 -0
- package/src/utils/requirement-file-management.js +157 -0
- package/src/utils/requirement-helpers/requirement-file-ops.js +392 -0
- package/src/utils/requirement-helpers/requirement-mover.js +414 -0
- package/src/utils/requirement-helpers/requirement-parser.js +326 -0
- package/src/utils/requirement-helpers/requirement-status.js +320 -0
- package/src/utils/requirement-helpers-new.js +55 -0
- package/src/utils/requirement-helpers-refactored.js +367 -0
- package/src/utils/requirement-helpers.js +291 -1191
- package/src/utils/requirement-movement-operations.js +450 -0
- package/src/utils/requirement-movement.js +312 -0
- package/src/utils/requirement-parsing-helpers.js +56 -0
- package/src/utils/requirement-statistics.js +200 -0
- package/src/utils/requirement-text-utils.js +58 -0
- package/src/utils/rollback/rollback-handlers.js +125 -0
- package/src/utils/rollback/rollback-operation.js +63 -0
- package/src/utils/rollback/rollback-recorder.js +166 -0
- package/src/utils/rollback/rollback-state-manager.js +175 -0
- package/src/utils/rollback/rollback-types.js +33 -0
- package/src/utils/rollback/rollback-utils.js +110 -0
- package/src/utils/rollback-manager-original.js +569 -0
- package/src/utils/rollback-manager.js +202 -0
- package/src/utils/smoke-test-cli.js +362 -0
- package/src/utils/smoke-test-gui.js +351 -0
- package/src/utils/smoke-test-orchestrator.js +321 -0
- package/src/utils/smoke-test-runner.js +60 -0
- package/src/utils/smoke-test-web.js +347 -0
- package/src/utils/specification-helpers.js +39 -13
- package/src/utils/specification-migration.js +97 -0
- package/src/utils/test-runner.js +579 -0
- package/src/utils/validation-framework.js +518 -0
- package/src/validation/compliance-analyzer.js +197 -0
- package/src/validation/compliance-report-generator.js +343 -0
- package/src/validation/compliance-reporter.js +711 -0
- package/src/validation/compliance-rules.js +127 -0
- package/src/validation/constitution-validator-new.js +196 -0
- package/src/validation/constitution-validator.js +17 -0
- package/src/validation/file-validators.js +170 -0
- package/src/validation/line-limit/file-analyzer.js +201 -0
- package/src/validation/line-limit/line-limit-validator.js +208 -0
- package/src/validation/line-limit/validation-result.js +144 -0
- package/src/validation/line-limit-core.js +225 -0
- package/src/validation/line-limit-reporter.js +134 -0
- package/src/validation/line-limit-result.js +125 -0
- package/src/validation/line-limit-validator.js +41 -0
- package/src/validation/metrics-calculator.js +660 -0
- package/src/sync/sync-engine-backup.js +0 -559
|
@@ -0,0 +1,600 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RUI Agent Command Parser
|
|
3
|
+
*
|
|
4
|
+
* Parses and validates REST-based agent commands.
|
|
5
|
+
* Follows constitutional requirements: <555 lines, test-first approach.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* RUI Agent Command Parser class
|
|
10
|
+
*/
|
|
11
|
+
class AgentCommandParser {
|
|
12
|
+
/**
|
|
13
|
+
* Create command parser instance
|
|
14
|
+
* @param {Object} options - Parser options
|
|
15
|
+
*/
|
|
16
|
+
constructor(options = {}) {
|
|
17
|
+
this.caseSensitive = options.caseSensitive || false;
|
|
18
|
+
this.allowShortcuts = options.allowShortcuts !== false;
|
|
19
|
+
this.strictMode = options.strictMode || false;
|
|
20
|
+
|
|
21
|
+
// Define command mappings
|
|
22
|
+
this.commandMap = this.initializeCommandMap();
|
|
23
|
+
this.shortcutMap = this.initializeShortcutMap();
|
|
24
|
+
this.parameterDefinitions = this.initializeParameterDefinitions();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Parse command string into components
|
|
29
|
+
* @param {string} commandString - Raw command string
|
|
30
|
+
* @returns {Object} - Parsed command object
|
|
31
|
+
*/
|
|
32
|
+
parse(commandString) {
|
|
33
|
+
if (!commandString || typeof commandString !== 'string') {
|
|
34
|
+
throw new Error('Command string is required and must be a string');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
const tokens = this.tokenize(commandString);
|
|
39
|
+
const { verb, resource, params } = this.extractComponents(tokens);
|
|
40
|
+
|
|
41
|
+
const normalizedVerb = this.normalizeVerb(verb);
|
|
42
|
+
const validatedCommand = this.validateCommand(normalizedVerb, resource, params);
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
...validatedCommand,
|
|
46
|
+
original: commandString,
|
|
47
|
+
tokens,
|
|
48
|
+
parsed: true
|
|
49
|
+
};
|
|
50
|
+
} catch (error) {
|
|
51
|
+
return {
|
|
52
|
+
success: false,
|
|
53
|
+
error: error.message,
|
|
54
|
+
original: commandString,
|
|
55
|
+
parsed: false
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Tokenize command string
|
|
62
|
+
* @param {string} commandString - Command string to tokenize
|
|
63
|
+
* @returns {Array} - Array of tokens
|
|
64
|
+
*/
|
|
65
|
+
tokenize(commandString) {
|
|
66
|
+
// Handle quoted strings and parameters
|
|
67
|
+
const tokens = [];
|
|
68
|
+
let current = '';
|
|
69
|
+
let inQuotes = false;
|
|
70
|
+
let quoteChar = '';
|
|
71
|
+
|
|
72
|
+
for (let i = 0; i < commandString.length; i++) {
|
|
73
|
+
const char = commandString[i];
|
|
74
|
+
|
|
75
|
+
if ((char === '"' || char === "'") && !inQuotes) {
|
|
76
|
+
inQuotes = true;
|
|
77
|
+
quoteChar = char;
|
|
78
|
+
} else if (char === quoteChar && inQuotes) {
|
|
79
|
+
inQuotes = false;
|
|
80
|
+
quoteChar = '';
|
|
81
|
+
} else if (char === ' ' && !inQuotes) {
|
|
82
|
+
if (current.trim()) {
|
|
83
|
+
tokens.push(current.trim());
|
|
84
|
+
current = '';
|
|
85
|
+
}
|
|
86
|
+
} else {
|
|
87
|
+
current += char;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (current.trim()) {
|
|
92
|
+
tokens.push(current.trim());
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return tokens;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Extract verb, resource, and parameters from tokens
|
|
100
|
+
* @param {Array} tokens - Command tokens
|
|
101
|
+
* @returns {Object} - Extracted components
|
|
102
|
+
*/
|
|
103
|
+
extractComponents(tokens) {
|
|
104
|
+
if (tokens.length === 0) {
|
|
105
|
+
throw new Error('Empty command');
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
let verb = tokens[0];
|
|
109
|
+
let resource = '';
|
|
110
|
+
let params = {};
|
|
111
|
+
|
|
112
|
+
// Handle shortcuts (2-character commands)
|
|
113
|
+
if (this.allowShortcuts && tokens.length >= 2 && tokens[0].length <= 3) {
|
|
114
|
+
verb = tokens[0];
|
|
115
|
+
resource = tokens[1];
|
|
116
|
+
|
|
117
|
+
// Extract parameters from remaining tokens
|
|
118
|
+
for (let i = 2; i < tokens.length; i++) {
|
|
119
|
+
this.parseParameter(tokens[i], params);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// Handle full commands
|
|
123
|
+
else if (tokens.length >= 2) {
|
|
124
|
+
verb = tokens[0];
|
|
125
|
+
resource = tokens[1];
|
|
126
|
+
|
|
127
|
+
// Extract parameters from remaining tokens
|
|
128
|
+
for (let i = 2; i < tokens.length; i++) {
|
|
129
|
+
this.parseParameter(tokens[i], params);
|
|
130
|
+
}
|
|
131
|
+
} else {
|
|
132
|
+
// Single token - might be verb only or verb+resource
|
|
133
|
+
const parts = tokens[0].split(/\s+/);
|
|
134
|
+
if (parts.length >= 2) {
|
|
135
|
+
verb = parts[0];
|
|
136
|
+
resource = parts[1];
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return { verb, resource, params };
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Parse parameter token
|
|
145
|
+
* @param {string} token - Parameter token
|
|
146
|
+
* @param {Object} params - Parameters object to update
|
|
147
|
+
*/
|
|
148
|
+
parseParameter(token, params) {
|
|
149
|
+
// Handle flag parameters (--flag)
|
|
150
|
+
if (token.startsWith('--')) {
|
|
151
|
+
const flag = token.substring(2);
|
|
152
|
+
params[flag] = true;
|
|
153
|
+
}
|
|
154
|
+
// Handle short flags (-f)
|
|
155
|
+
else if (token.startsWith('-') && !token.startsWith('--')) {
|
|
156
|
+
const flag = token.substring(1);
|
|
157
|
+
params[flag] = true;
|
|
158
|
+
}
|
|
159
|
+
// Handle key=value parameters (--key=value)
|
|
160
|
+
else if (token.includes('=')) {
|
|
161
|
+
const [key, value] = token.split('=', 2);
|
|
162
|
+
const cleanKey = key.startsWith('--') ? key.substring(2) : key.startsWith('-') ? key.substring(1) : key;
|
|
163
|
+
params[cleanKey] = this.parseValue(value);
|
|
164
|
+
}
|
|
165
|
+
// Handle key value parameters (--key value)
|
|
166
|
+
else if (token.startsWith('--')) {
|
|
167
|
+
const key = token.substring(2);
|
|
168
|
+
params[key] = true; // Will be updated with next token if it's a value
|
|
169
|
+
}
|
|
170
|
+
// Positional parameter
|
|
171
|
+
else {
|
|
172
|
+
if (!params.positional) {
|
|
173
|
+
params.positional = [];
|
|
174
|
+
}
|
|
175
|
+
params.positional.push(this.parseValue(token));
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Parse parameter value
|
|
181
|
+
* @param {string} value - Raw value
|
|
182
|
+
* @returns {*} - Parsed value
|
|
183
|
+
*/
|
|
184
|
+
parseValue(value) {
|
|
185
|
+
// Remove quotes if present
|
|
186
|
+
if ((value.startsWith('"') && value.endsWith('"')) ||
|
|
187
|
+
(value.startsWith("'") && value.endsWith("'"))) {
|
|
188
|
+
value = value.slice(1, -1);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Parse as JSON if possible
|
|
192
|
+
try {
|
|
193
|
+
return JSON.parse(value);
|
|
194
|
+
} catch {
|
|
195
|
+
// Return as string if not valid JSON
|
|
196
|
+
return value;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Normalize verb using command map
|
|
202
|
+
* @param {string} verb - Raw verb
|
|
203
|
+
* @returns {string} - Normalized verb
|
|
204
|
+
*/
|
|
205
|
+
normalizeVerb(verb) {
|
|
206
|
+
if (!verb) return verb;
|
|
207
|
+
|
|
208
|
+
const normalized = this.caseSensitive ? verb : verb.toUpperCase();
|
|
209
|
+
|
|
210
|
+
// Check shortcuts first
|
|
211
|
+
if (this.allowShortcuts && this.shortcutMap[normalized]) {
|
|
212
|
+
return this.shortcutMap[normalized];
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// Check full commands
|
|
216
|
+
if (this.commandMap[normalized]) {
|
|
217
|
+
return this.commandMap[normalized];
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return normalized;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Validate command components
|
|
225
|
+
* @param {string} verb - Command verb
|
|
226
|
+
* @param {string} resource - Command resource
|
|
227
|
+
* @param {Object} params - Command parameters
|
|
228
|
+
* @returns {Object} - Validation result
|
|
229
|
+
*/
|
|
230
|
+
validateCommand(verb, resource, params) {
|
|
231
|
+
const validation = {
|
|
232
|
+
success: true,
|
|
233
|
+
verb,
|
|
234
|
+
resource,
|
|
235
|
+
params,
|
|
236
|
+
errors: [],
|
|
237
|
+
warnings: []
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
// Validate verb
|
|
241
|
+
if (!this.isValidVerb(verb)) {
|
|
242
|
+
validation.success = false;
|
|
243
|
+
validation.errors.push(`Unknown command: ${verb}`);
|
|
244
|
+
return validation;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// Validate resource based on verb
|
|
248
|
+
const resourceValidation = this.validateResource(verb, resource);
|
|
249
|
+
if (!resourceValidation.valid) {
|
|
250
|
+
validation.success = false;
|
|
251
|
+
validation.errors.push(...resourceValidation.errors);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// Validate parameters
|
|
255
|
+
const paramValidation = this.validateParameters(verb, resource, params);
|
|
256
|
+
if (!paramValidation.valid) {
|
|
257
|
+
validation.success = false;
|
|
258
|
+
validation.errors.push(...paramValidation.errors);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
validation.warnings.push(...paramValidation.warnings);
|
|
262
|
+
|
|
263
|
+
return validation;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Check if verb is valid
|
|
268
|
+
* @param {string} verb - Verb to check
|
|
269
|
+
* @returns {boolean} - Whether verb is valid
|
|
270
|
+
*/
|
|
271
|
+
isValidVerb(verb) {
|
|
272
|
+
const validVerbs = new Set([
|
|
273
|
+
'GET', 'LIST', 'POST', 'CHECK', 'PUT', 'UPDATE', 'DELETE', 'REMOVE',
|
|
274
|
+
'ENABLE', 'DISABLE', 'STATUS', 'HELP'
|
|
275
|
+
]);
|
|
276
|
+
|
|
277
|
+
return validVerbs.has(verb);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Validate resource for given verb
|
|
282
|
+
* @param {string} verb - Command verb
|
|
283
|
+
* @param {string} resource - Resource to validate
|
|
284
|
+
* @returns {Object} - Validation result
|
|
285
|
+
*/
|
|
286
|
+
validateResource(verb, resource) {
|
|
287
|
+
const validation = { valid: true, errors: [] };
|
|
288
|
+
|
|
289
|
+
// Verbs that require resource
|
|
290
|
+
const resourceRequiredVerbs = new Set(['GET', 'PUT', 'UPDATE', 'DELETE', 'REMOVE', 'ENABLE', 'DISABLE']);
|
|
291
|
+
|
|
292
|
+
if (resourceRequiredVerbs.has(verb) && !resource) {
|
|
293
|
+
validation.valid = false;
|
|
294
|
+
validation.errors.push('Resource is required for this command');
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// Validate resource format
|
|
298
|
+
if (resource && !this.isValidResource(resource)) {
|
|
299
|
+
validation.valid = false;
|
|
300
|
+
validation.errors.push(`Invalid resource: ${resource}`);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
return validation;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Check if resource is valid
|
|
308
|
+
* @param {string} resource - Resource to check
|
|
309
|
+
* @returns {boolean} - Whether resource is valid
|
|
310
|
+
*/
|
|
311
|
+
isValidResource(resource) {
|
|
312
|
+
const validResources = ['agents', 'agent'];
|
|
313
|
+
return validResources.includes(resource.toLowerCase()) ||
|
|
314
|
+
resource.toLowerCase().startsWith('agent-');
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Validate command parameters
|
|
319
|
+
* @param {string} verb - Command verb
|
|
320
|
+
* @param {string} resource - Command resource
|
|
321
|
+
* @param {Object} params - Parameters to validate
|
|
322
|
+
* @returns {Object} - Validation result
|
|
323
|
+
*/
|
|
324
|
+
validateParameters(verb, resource, params) {
|
|
325
|
+
const validation = { valid: true, errors: [], warnings: [] };
|
|
326
|
+
|
|
327
|
+
// Get parameter definitions for this verb
|
|
328
|
+
const paramDefs = this.parameterDefinitions[verb] || {};
|
|
329
|
+
|
|
330
|
+
// Validate each parameter
|
|
331
|
+
for (const [paramName, paramValue] of Object.entries(params)) {
|
|
332
|
+
if (paramName === 'positional') continue;
|
|
333
|
+
|
|
334
|
+
const paramDef = paramDefs[paramName];
|
|
335
|
+
if (!paramDef) {
|
|
336
|
+
if (this.strictMode) {
|
|
337
|
+
validation.valid = false;
|
|
338
|
+
validation.errors.push(`Unknown parameter: ${paramName}`);
|
|
339
|
+
}
|
|
340
|
+
continue;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// Type validation
|
|
344
|
+
if (paramDef.type && !this.validateParameterType(paramValue, paramDef.type)) {
|
|
345
|
+
validation.valid = false;
|
|
346
|
+
validation.errors.push(`Invalid type for parameter ${paramName}: expected ${paramDef.type}`);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// Value validation
|
|
350
|
+
if (paramDef.validValues && !paramDef.validValues.includes(paramValue)) {
|
|
351
|
+
validation.valid = false;
|
|
352
|
+
validation.errors.push(`Invalid value for parameter ${paramName}: ${paramValue}. Valid values: ${paramDef.validValues.join(', ')}`);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// Check for required parameters
|
|
357
|
+
for (const [paramName, paramDef] of Object.entries(paramDefs)) {
|
|
358
|
+
if (paramDef.required && !(paramName in params)) {
|
|
359
|
+
validation.valid = false;
|
|
360
|
+
validation.errors.push(`Required parameter missing: ${paramName}`);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// Add warnings for special cases
|
|
365
|
+
if (verb === 'DELETE' && !params.confirm) {
|
|
366
|
+
validation.warnings.push('DELETE command requires confirmation (confirm=true)');
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
if (verb === 'CHECK' && params.timeout && params.timeout < 0) {
|
|
370
|
+
validation.warnings.push('Timeout should be positive');
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
return validation;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Validate parameter type
|
|
378
|
+
* @param {*} value - Parameter value
|
|
379
|
+
* @param {string} type - Expected type
|
|
380
|
+
* @returns {boolean} - Whether type is valid
|
|
381
|
+
*/
|
|
382
|
+
validateParameterType(value, type) {
|
|
383
|
+
switch (type) {
|
|
384
|
+
case 'boolean':
|
|
385
|
+
return typeof value === 'boolean' || value === true || value === false;
|
|
386
|
+
case 'number':
|
|
387
|
+
return !isNaN(Number(value));
|
|
388
|
+
case 'string':
|
|
389
|
+
return typeof value === 'string';
|
|
390
|
+
case 'array':
|
|
391
|
+
return Array.isArray(value);
|
|
392
|
+
default:
|
|
393
|
+
return true; // Unknown type, assume valid
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Initialize command mappings
|
|
399
|
+
* @returns {Object} - Command map
|
|
400
|
+
*/
|
|
401
|
+
initializeCommandMap() {
|
|
402
|
+
return {
|
|
403
|
+
'GET': 'GET',
|
|
404
|
+
'LIST': 'GET',
|
|
405
|
+
'POST': 'POST',
|
|
406
|
+
'CHECK': 'POST',
|
|
407
|
+
'PUT': 'PUT',
|
|
408
|
+
'UPDATE': 'PUT',
|
|
409
|
+
'DELETE': 'DELETE',
|
|
410
|
+
'REMOVE': 'DELETE',
|
|
411
|
+
'ENABLE': 'PUT',
|
|
412
|
+
'DISABLE': 'PUT',
|
|
413
|
+
'STATUS': 'GET',
|
|
414
|
+
'HELP': 'GET'
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* Initialize shortcut mappings
|
|
420
|
+
* @returns {Object} - Shortcut map
|
|
421
|
+
*/
|
|
422
|
+
initializeShortcutMap() {
|
|
423
|
+
return {
|
|
424
|
+
'LA': 'GET', // List agents
|
|
425
|
+
'LI': 'GET', // List agents
|
|
426
|
+
'CH': 'POST', // Check agents
|
|
427
|
+
'CA': 'POST', // Check agents
|
|
428
|
+
'GE': 'GET', // Get agent
|
|
429
|
+
'UP': 'PUT', // Update agent
|
|
430
|
+
'EN': 'PUT', // Enable agent
|
|
431
|
+
'DI': 'PUT', // Disable agent
|
|
432
|
+
'RE': 'DELETE', // Remove agent
|
|
433
|
+
'RM': 'DELETE', // Remove agent
|
|
434
|
+
'ST': 'GET', // Status
|
|
435
|
+
'HE': 'GET' // Help
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* Initialize parameter definitions
|
|
441
|
+
* @returns {Object} - Parameter definitions
|
|
442
|
+
*/
|
|
443
|
+
initializeParameterDefinitions() {
|
|
444
|
+
return {
|
|
445
|
+
'GET': {
|
|
446
|
+
'includeDisabled': { type: 'boolean', default: false },
|
|
447
|
+
'includeStatus': { type: 'boolean', default: true },
|
|
448
|
+
'includeLogs': { type: 'boolean', default: false },
|
|
449
|
+
'format': { type: 'string', validValues: ['table', 'json', 'csv'] },
|
|
450
|
+
'sort': { type: 'string', validValues: ['name', 'status', 'type', 'priority'] },
|
|
451
|
+
'status': { type: 'string' },
|
|
452
|
+
'limit': { type: 'number' },
|
|
453
|
+
'offset': { type: 'number' }
|
|
454
|
+
},
|
|
455
|
+
'POST': {
|
|
456
|
+
'agentIds': { type: 'array' },
|
|
457
|
+
'forceReinstall': { type: 'boolean', default: false },
|
|
458
|
+
'skipVerification': { type: 'boolean', default: false },
|
|
459
|
+
'timeout': { type: 'number', default: 300000 },
|
|
460
|
+
'parallel': { type: 'boolean', default: true },
|
|
461
|
+
'maxConcurrency': { type: 'number', default: 2 }
|
|
462
|
+
},
|
|
463
|
+
'PUT': {
|
|
464
|
+
'enabled': { type: 'boolean' },
|
|
465
|
+
'status': { type: 'string' },
|
|
466
|
+
'message': { type: 'string' }
|
|
467
|
+
},
|
|
468
|
+
'DELETE': {
|
|
469
|
+
'confirm': { type: 'boolean', required: true }
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Get command suggestions
|
|
476
|
+
* @param {string} partial - Partial command
|
|
477
|
+
* @returns {Array} - Suggestions
|
|
478
|
+
*/
|
|
479
|
+
getSuggestions(partial) {
|
|
480
|
+
if (!partial) return [];
|
|
481
|
+
|
|
482
|
+
const normalized = this.caseSensitive ? partial : partial.toUpperCase();
|
|
483
|
+
const suggestions = [];
|
|
484
|
+
|
|
485
|
+
// Command suggestions
|
|
486
|
+
for (const [command, normalizedCommand] of Object.entries(this.commandMap)) {
|
|
487
|
+
if (normalizedCommand.startsWith(normalized)) {
|
|
488
|
+
suggestions.push({
|
|
489
|
+
type: 'command',
|
|
490
|
+
value: command,
|
|
491
|
+
description: this.getCommandDescription(command)
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// Shortcut suggestions
|
|
497
|
+
if (this.allowShortcuts) {
|
|
498
|
+
for (const [shortcut, command] of Object.entries(this.shortcutMap)) {
|
|
499
|
+
if (shortcut.startsWith(normalized)) {
|
|
500
|
+
suggestions.push({
|
|
501
|
+
type: 'shortcut',
|
|
502
|
+
value: shortcut,
|
|
503
|
+
description: this.getCommandDescription(command)
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
return suggestions;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Get command description
|
|
514
|
+
* @param {string} command - Command
|
|
515
|
+
* @returns {string} - Description
|
|
516
|
+
*/
|
|
517
|
+
getCommandDescription(command) {
|
|
518
|
+
const descriptions = {
|
|
519
|
+
'GET': 'Get agent or list agents',
|
|
520
|
+
'POST': 'Check agents',
|
|
521
|
+
'PUT': 'Update agent (enable/disable)',
|
|
522
|
+
'DELETE': 'Remove agent',
|
|
523
|
+
'LIST': 'List agents',
|
|
524
|
+
'CHECK': 'Check agents',
|
|
525
|
+
'ENABLE': 'Enable agent',
|
|
526
|
+
'DISABLE': 'Disable agent',
|
|
527
|
+
'REMOVE': 'Remove agent',
|
|
528
|
+
'STATUS': 'Get agent status',
|
|
529
|
+
'HELP': 'Show help'
|
|
530
|
+
};
|
|
531
|
+
|
|
532
|
+
return descriptions[command] || 'Unknown command';
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* Format command for display
|
|
537
|
+
* @param {Object} parsedCommand - Parsed command object
|
|
538
|
+
* @returns {string} - Formatted command
|
|
539
|
+
*/
|
|
540
|
+
formatCommand(parsedCommand) {
|
|
541
|
+
if (!parsedCommand || !parsedCommand.verb) {
|
|
542
|
+
return '';
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
let command = parsedCommand.verb;
|
|
546
|
+
|
|
547
|
+
if (parsedCommand.resource) {
|
|
548
|
+
command += ' ' + parsedCommand.resource;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
// Add parameters
|
|
552
|
+
for (const [param, value] of Object.entries(parsedCommand.params || {})) {
|
|
553
|
+
if (param === 'positional') continue;
|
|
554
|
+
|
|
555
|
+
if (typeof value === 'boolean' && value === true) {
|
|
556
|
+
command += ` --${param}`;
|
|
557
|
+
} else if (typeof value === 'string' && value.includes(' ')) {
|
|
558
|
+
command += ` --${param}="${value}"`;
|
|
559
|
+
} else {
|
|
560
|
+
command += ` --${param}=${value}`;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
// Add positional parameters
|
|
565
|
+
if (parsedCommand.params && parsedCommand.params.positional) {
|
|
566
|
+
for (const param of parsedCommand.params.positional) {
|
|
567
|
+
command += ` ${param}`;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
return command;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
/**
|
|
575
|
+
* Get parser information
|
|
576
|
+
* @returns {Object} - Parser info
|
|
577
|
+
*/
|
|
578
|
+
getInfo() {
|
|
579
|
+
return {
|
|
580
|
+
name: 'RUI Agent Command Parser',
|
|
581
|
+
version: '1.0.0',
|
|
582
|
+
caseSensitive: this.caseSensitive,
|
|
583
|
+
allowShortcuts: this.allowShortcuts,
|
|
584
|
+
strictMode: this.strictMode,
|
|
585
|
+
supportedVerbs: Object.keys(this.commandMap),
|
|
586
|
+
supportedShortcuts: Object.keys(this.shortcutMap),
|
|
587
|
+
features: [
|
|
588
|
+
'command parsing',
|
|
589
|
+
'parameter validation',
|
|
590
|
+
'shortcut support',
|
|
591
|
+
'type checking',
|
|
592
|
+
'auto-completion',
|
|
593
|
+
'error handling',
|
|
594
|
+
'command formatting'
|
|
595
|
+
]
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
module.exports = AgentCommandParser;
|