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.
Files changed (202) hide show
  1. package/README.md +240 -0
  2. package/package.json +10 -2
  3. package/src/agents/Agent.js +300 -0
  4. package/src/agents/AgentAdditionService.js +311 -0
  5. package/src/agents/AgentCheckService.js +690 -0
  6. package/src/agents/AgentInstallationService.js +140 -0
  7. package/src/agents/AgentSetupService.js +467 -0
  8. package/src/agents/AgentStatus.js +183 -0
  9. package/src/agents/AgentVerificationService.js +634 -0
  10. package/src/agents/ConfigurationSchemaValidator.js +543 -0
  11. package/src/agents/EnvironmentConfigurationManager.js +602 -0
  12. package/src/agents/InstallationErrorHandler.js +372 -0
  13. package/src/agents/InstallationLog.js +363 -0
  14. package/src/agents/InstallationMethod.js +510 -0
  15. package/src/agents/InstallationOrchestrator.js +352 -0
  16. package/src/agents/InstallationProgressReporter.js +372 -0
  17. package/src/agents/InstallationRetryManager.js +322 -0
  18. package/src/agents/InstallationType.js +254 -0
  19. package/src/agents/OperationTypes.js +310 -0
  20. package/src/agents/PerformanceMetricsCollector.js +493 -0
  21. package/src/agents/SecurityValidationService.js +534 -0
  22. package/src/agents/VerificationTest.js +354 -0
  23. package/src/agents/VerificationType.js +226 -0
  24. package/src/agents/WindowsPermissionHandler.js +518 -0
  25. package/src/agents/config/AgentConfigManager.js +393 -0
  26. package/src/agents/config/AgentDefaultsRegistry.js +373 -0
  27. package/src/agents/config/ConfigValidator.js +281 -0
  28. package/src/agents/discovery/AgentDiscoveryService.js +707 -0
  29. package/src/agents/logging/AgentLogger.js +511 -0
  30. package/src/agents/status/AgentStatusManager.js +481 -0
  31. package/src/agents/storage/FileManager.js +454 -0
  32. package/src/agents/verification/AgentCommunicationTester.js +474 -0
  33. package/src/agents/verification/BaseVerifier.js +430 -0
  34. package/src/agents/verification/CommandVerifier.js +480 -0
  35. package/src/agents/verification/FileOperationVerifier.js +453 -0
  36. package/src/agents/verification/ResultAnalyzer.js +707 -0
  37. package/src/agents/verification/TestRequirementManager.js +495 -0
  38. package/src/agents/verification/VerificationRunner.js +433 -0
  39. package/src/agents/windows/BaseWindowsInstaller.js +441 -0
  40. package/src/agents/windows/ChocolateyInstaller.js +509 -0
  41. package/src/agents/windows/DirectInstaller.js +443 -0
  42. package/src/agents/windows/InstallerFactory.js +391 -0
  43. package/src/agents/windows/NpmInstaller.js +505 -0
  44. package/src/agents/windows/PowerShellInstaller.js +458 -0
  45. package/src/agents/windows/WinGetInstaller.js +390 -0
  46. package/src/analysis/analysis-reporter.js +132 -0
  47. package/src/analysis/boundary-detector.js +712 -0
  48. package/src/analysis/categorizer.js +340 -0
  49. package/src/analysis/codebase-scanner.js +384 -0
  50. package/src/analysis/line-counter.js +513 -0
  51. package/src/analysis/priority-calculator.js +679 -0
  52. package/src/analysis/report/analysis-report.js +250 -0
  53. package/src/analysis/report/package-analyzer.js +278 -0
  54. package/src/analysis/report/recommendation-generator.js +382 -0
  55. package/src/analysis/report/statistics-generator.js +515 -0
  56. package/src/analysis/reports/analysis-report-model.js +101 -0
  57. package/src/analysis/reports/recommendation-generator.js +283 -0
  58. package/src/analysis/reports/report-generators.js +191 -0
  59. package/src/analysis/reports/statistics-calculator.js +231 -0
  60. package/src/analysis/reports/trend-analyzer.js +219 -0
  61. package/src/analysis/strategy-generator.js +814 -0
  62. package/src/auto-mode/AutoModeBusinessLogic.js +836 -0
  63. package/src/config/refactoring-config.js +307 -0
  64. package/src/health-tracking/json-storage.js +38 -2
  65. package/src/ide-integration/applescript-manager-core.js +233 -0
  66. package/src/ide-integration/applescript-manager.cjs +357 -28
  67. package/src/ide-integration/applescript-manager.js +89 -3599
  68. package/src/ide-integration/cdp-manager.js +306 -0
  69. package/src/ide-integration/claude-code-cli-manager.cjs +1 -1
  70. package/src/ide-integration/continuation-handler.js +337 -0
  71. package/src/ide-integration/ide-status-checker.js +292 -0
  72. package/src/ide-integration/macos-ide-manager.js +627 -0
  73. package/src/ide-integration/macos-text-sender.js +528 -0
  74. package/src/ide-integration/response-reader.js +548 -0
  75. package/src/ide-integration/windows-automation-manager.js +121 -0
  76. package/src/ide-integration/windows-ide-manager.js +373 -0
  77. package/src/index.cjs +25 -3
  78. package/src/index.js +15 -1
  79. package/src/llm/direct-llm-manager.cjs +90 -2
  80. package/src/models/compliance-report.js +538 -0
  81. package/src/models/file-analysis.js +681 -0
  82. package/src/models/refactoring-plan.js +770 -0
  83. package/src/monitoring/alert-system.js +834 -0
  84. package/src/monitoring/compliance-progress-tracker.js +437 -0
  85. package/src/monitoring/continuous-scan-notifications.js +661 -0
  86. package/src/monitoring/continuous-scanner.js +279 -0
  87. package/src/monitoring/file-monitor/file-analyzer.js +262 -0
  88. package/src/monitoring/file-monitor/file-monitor.js +237 -0
  89. package/src/monitoring/file-monitor/watcher.js +194 -0
  90. package/src/monitoring/file-monitor.js +17 -0
  91. package/src/monitoring/notification-manager.js +437 -0
  92. package/src/monitoring/scanner-core.js +368 -0
  93. package/src/monitoring/scanner-events.js +214 -0
  94. package/src/monitoring/violation-notification-system.js +515 -0
  95. package/src/refactoring/boundaries/cohesion-analyzer.js +316 -0
  96. package/src/refactoring/boundaries/extraction-result.js +285 -0
  97. package/src/refactoring/boundaries/extraction-strategies.js +392 -0
  98. package/src/refactoring/boundaries/module-boundary.js +209 -0
  99. package/src/refactoring/boundary/boundary-detector.js +741 -0
  100. package/src/refactoring/boundary/boundary-types.js +405 -0
  101. package/src/refactoring/boundary/extraction-strategies.js +554 -0
  102. package/src/refactoring/boundary-extraction-result.js +77 -0
  103. package/src/refactoring/boundary-extraction-strategies.js +330 -0
  104. package/src/refactoring/boundary-extractor.js +384 -0
  105. package/src/refactoring/boundary-types.js +46 -0
  106. package/src/refactoring/circular/circular-dependency.js +88 -0
  107. package/src/refactoring/circular/cycle-detection.js +147 -0
  108. package/src/refactoring/circular/dependency-node.js +82 -0
  109. package/src/refactoring/circular/dependency-result.js +107 -0
  110. package/src/refactoring/circular/dependency-types.js +58 -0
  111. package/src/refactoring/circular/graph-builder.js +213 -0
  112. package/src/refactoring/circular/resolution-strategy.js +72 -0
  113. package/src/refactoring/circular/strategy-generator.js +229 -0
  114. package/src/refactoring/circular-dependency-resolver-original.js +809 -0
  115. package/src/refactoring/circular-dependency-resolver.js +200 -0
  116. package/src/refactoring/code-mover.js +761 -0
  117. package/src/refactoring/file-splitter.js +696 -0
  118. package/src/refactoring/functionality-validator.js +816 -0
  119. package/src/refactoring/import-manager.js +774 -0
  120. package/src/refactoring/module-boundary.js +107 -0
  121. package/src/refactoring/refactoring-executor.js +672 -0
  122. package/src/refactoring/refactoring-rollback.js +614 -0
  123. package/src/refactoring/test-validator.js +631 -0
  124. package/src/requirement-management/default-requirement-manager.js +321 -0
  125. package/src/requirement-management/requirement-file-parser.js +159 -0
  126. package/src/requirement-management/requirement-sequencer.js +221 -0
  127. package/src/rui/commands/AgentCommandParser.js +600 -0
  128. package/src/rui/commands/AgentCommands.js +487 -0
  129. package/src/rui/commands/AgentResponseFormatter.js +832 -0
  130. package/src/scripts/verify-full-compliance.js +269 -0
  131. package/src/sync/sync-engine-core.js +1 -0
  132. package/src/sync/sync-engine-remote-handlers.js +135 -0
  133. package/src/task-generation/automated-task-generator.js +351 -0
  134. package/src/task-generation/prioritizer.js +287 -0
  135. package/src/task-generation/task-list-updater.js +215 -0
  136. package/src/task-generation/task-management-integration.js +480 -0
  137. package/src/task-generation/task-manager-integration.js +270 -0
  138. package/src/task-generation/violation-task-generator.js +474 -0
  139. package/src/task-management/continuous-scan-integration.js +342 -0
  140. package/src/timeout-management/index.js +12 -3
  141. package/src/timeout-management/response-time-tracker.js +167 -0
  142. package/src/timeout-management/timeout-calculator.js +159 -0
  143. package/src/timeout-management/timeout-config-manager.js +172 -0
  144. package/src/utils/ast-analyzer.js +417 -0
  145. package/src/utils/current-requirement-manager.js +276 -0
  146. package/src/utils/current-requirement-operations.js +472 -0
  147. package/src/utils/dependency-mapper.js +456 -0
  148. package/src/utils/download-with-progress.js +4 -2
  149. package/src/utils/electron-update-checker.js +4 -1
  150. package/src/utils/file-size-analyzer.js +272 -0
  151. package/src/utils/import-updater.js +280 -0
  152. package/src/utils/refactoring-tools.js +512 -0
  153. package/src/utils/report-generator.js +569 -0
  154. package/src/utils/reports/report-analysis.js +218 -0
  155. package/src/utils/reports/report-types.js +55 -0
  156. package/src/utils/reports/summary-generators.js +102 -0
  157. package/src/utils/requirement-file-management.js +157 -0
  158. package/src/utils/requirement-helpers/requirement-file-ops.js +392 -0
  159. package/src/utils/requirement-helpers/requirement-mover.js +414 -0
  160. package/src/utils/requirement-helpers/requirement-parser.js +326 -0
  161. package/src/utils/requirement-helpers/requirement-status.js +320 -0
  162. package/src/utils/requirement-helpers-new.js +55 -0
  163. package/src/utils/requirement-helpers-refactored.js +367 -0
  164. package/src/utils/requirement-helpers.js +291 -1191
  165. package/src/utils/requirement-movement-operations.js +450 -0
  166. package/src/utils/requirement-movement.js +312 -0
  167. package/src/utils/requirement-parsing-helpers.js +56 -0
  168. package/src/utils/requirement-statistics.js +200 -0
  169. package/src/utils/requirement-text-utils.js +58 -0
  170. package/src/utils/rollback/rollback-handlers.js +125 -0
  171. package/src/utils/rollback/rollback-operation.js +63 -0
  172. package/src/utils/rollback/rollback-recorder.js +166 -0
  173. package/src/utils/rollback/rollback-state-manager.js +175 -0
  174. package/src/utils/rollback/rollback-types.js +33 -0
  175. package/src/utils/rollback/rollback-utils.js +110 -0
  176. package/src/utils/rollback-manager-original.js +569 -0
  177. package/src/utils/rollback-manager.js +202 -0
  178. package/src/utils/smoke-test-cli.js +362 -0
  179. package/src/utils/smoke-test-gui.js +351 -0
  180. package/src/utils/smoke-test-orchestrator.js +321 -0
  181. package/src/utils/smoke-test-runner.js +60 -0
  182. package/src/utils/smoke-test-web.js +347 -0
  183. package/src/utils/specification-helpers.js +39 -13
  184. package/src/utils/specification-migration.js +97 -0
  185. package/src/utils/test-runner.js +579 -0
  186. package/src/utils/validation-framework.js +518 -0
  187. package/src/validation/compliance-analyzer.js +197 -0
  188. package/src/validation/compliance-report-generator.js +343 -0
  189. package/src/validation/compliance-reporter.js +711 -0
  190. package/src/validation/compliance-rules.js +127 -0
  191. package/src/validation/constitution-validator-new.js +196 -0
  192. package/src/validation/constitution-validator.js +17 -0
  193. package/src/validation/file-validators.js +170 -0
  194. package/src/validation/line-limit/file-analyzer.js +201 -0
  195. package/src/validation/line-limit/line-limit-validator.js +208 -0
  196. package/src/validation/line-limit/validation-result.js +144 -0
  197. package/src/validation/line-limit-core.js +225 -0
  198. package/src/validation/line-limit-reporter.js +134 -0
  199. package/src/validation/line-limit-result.js +125 -0
  200. package/src/validation/line-limit-validator.js +41 -0
  201. package/src/validation/metrics-calculator.js +660 -0
  202. 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;