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.
Files changed (192) hide show
  1. package/package.json +1 -1
  2. package/src/agents/AgentCheckDiscoveryService.js +180 -0
  3. package/src/agents/AgentCheckService.js +18 -261
  4. package/src/agents/AgentCheckStatisticsService.js +195 -0
  5. package/src/agents/EnvironmentConfigurationManager.js +31 -380
  6. package/src/agents/InstallationType.js +19 -6
  7. package/src/agents/SimpleAgentCheckService.js +472 -0
  8. package/src/agents/config-managers/ConfigUtils.js +72 -0
  9. package/src/agents/config-managers/DefaultConfig.js +58 -0
  10. package/src/agents/config-managers/EnvVarLoader.js +66 -0
  11. package/src/agents/config-managers/FileConfigLoader.js +124 -0
  12. package/src/agents/config-managers/TypeConverters.js +61 -0
  13. package/src/agents/config-managers/VariableMappings.js +92 -0
  14. package/src/agents/discovery/AgentDiscoveryService-refactored.js +272 -0
  15. package/src/agents/discovery/AgentDiscoveryService.js +29 -403
  16. package/src/agents/discovery/agent-validator.js +262 -0
  17. package/src/agents/discovery/discovery-results.js +176 -0
  18. package/src/agents/discovery/discovery-scanner.js +268 -0
  19. package/src/agents/discovery/discovery-utils.js +161 -0
  20. package/src/agents/discovery/executable-analyzer.js +290 -0
  21. package/src/agents/discovery/history-manager.js +310 -0
  22. package/src/agents/verification/ResultAnalyzer-refactored.js +341 -0
  23. package/src/agents/verification/ResultAnalyzer.js +30 -431
  24. package/src/agents/verification/analysis-utils.js +310 -0
  25. package/src/agents/verification/batch-analyzer.js +440 -0
  26. package/src/agents/verification/pattern-recognizer.js +369 -0
  27. package/src/agents/verification/report-generator.js +320 -0
  28. package/src/agents/verification/test-analyzer.js +290 -0
  29. package/src/agents/windows/InstallerFactory.js +4 -0
  30. package/src/agents/windows/VSCodeExtensionInstaller.js +404 -0
  31. package/src/analysis/analysis-engine.js +314 -0
  32. package/src/analysis/ast-analyzer.js +342 -0
  33. package/src/analysis/boundary-detector-refactored.js +378 -0
  34. package/src/analysis/boundary-detector.js +200 -603
  35. package/src/analysis/boundary-scanner.js +609 -0
  36. package/src/analysis/boundary-types.js +118 -0
  37. package/src/analysis/boundary-utils.js +293 -0
  38. package/src/analysis/deadline-priority-calculator.js +18 -0
  39. package/src/analysis/detection-methods.js +347 -0
  40. package/src/analysis/importance-priority-calculator.js +18 -0
  41. package/src/analysis/priority/factor-calculators.js +204 -0
  42. package/src/analysis/priority/factor-helpers.js +71 -0
  43. package/src/analysis/priority/priority-constants.js +73 -0
  44. package/src/analysis/priority/priority-factor-calculators.js +301 -0
  45. package/src/analysis/priority/reasons-generator.js +44 -0
  46. package/src/analysis/priority-calculator.js +15 -580
  47. package/src/analysis/strategy-generator.js +16 -66
  48. package/src/analysis/type-priority-calculator.js +18 -0
  49. package/src/analysis/urgency-priority-calculator.js +18 -0
  50. package/src/auto-mode/AutoModeBusinessLogic.js +2 -40
  51. package/src/commands/disable-requirement.js +60 -0
  52. package/src/commands/disable-spec.js +60 -0
  53. package/src/commands/enable-requirement.js +60 -0
  54. package/src/commands/enable-spec.js +60 -0
  55. package/src/commands/registry.js +1 -6
  56. package/src/commands/requirements.js +8 -2
  57. package/src/ide-integration/applescript-manager.cjs +9 -24
  58. package/src/ide-integration/cdp-handlers/chat-reader.js +44 -0
  59. package/src/ide-integration/cdp-handlers/connection-handler.js +88 -0
  60. package/src/ide-integration/cdp-handlers/continuation-handler.js +314 -0
  61. package/src/ide-integration/cdp-handlers/message-submitter.js +75 -0
  62. package/src/ide-integration/cdp-handlers/text-sender.js +138 -0
  63. package/src/ide-integration/cdp-manager.js +28 -573
  64. package/src/ide-integration/claude-code-cli-manager.cjs +48 -12
  65. package/src/ide-integration/ide-openers/claude-opener.js +171 -0
  66. package/src/ide-integration/ide-openers/cursor-opener.js +53 -0
  67. package/src/ide-integration/ide-openers/other-ides-opener.js +230 -0
  68. package/src/ide-integration/ide-openers/vscode-opener.js +147 -0
  69. package/src/ide-integration/macos-ide-manager.js +20 -582
  70. package/src/ide-integration/macos-quota-checker.js +164 -0
  71. package/src/ide-integration/macos-text-sender.js +19 -38
  72. package/src/ide-integration/provider-manager.cjs +52 -7
  73. package/src/index.cjs +6 -0
  74. package/src/index.js +10 -0
  75. package/src/llm/direct-llm-manager.cjs +501 -0
  76. package/src/localization/translations/en-part1.js +363 -0
  77. package/src/localization/translations/en-part2.js +320 -0
  78. package/src/localization/translations/en.js +4 -687
  79. package/src/localization/translations/es-part1.js +363 -0
  80. package/src/localization/translations/es-part2.js +320 -0
  81. package/src/localization/translations/es.js +4 -688
  82. package/src/models/file-analysis-collection.js +139 -0
  83. package/src/models/file-analysis-metrics.js +50 -0
  84. package/src/models/file-analysis.js +15 -262
  85. package/src/models/plan-manager.js +410 -0
  86. package/src/models/refactoring-models.js +380 -0
  87. package/src/models/refactoring-plan-refactored.js +81 -0
  88. package/src/models/refactoring-plan.js +2 -663
  89. package/src/monitoring/alert-system.js +4 -45
  90. package/src/monitoring/continuous-scan-notifications.js +37 -191
  91. package/src/monitoring/notification-handlers/base-handler.js +58 -0
  92. package/src/monitoring/notification-handlers/error-handler.js +36 -0
  93. package/src/monitoring/notification-handlers/index.js +21 -0
  94. package/src/monitoring/notification-handlers/new-violation-handler.js +91 -0
  95. package/src/monitoring/notification-handlers/progress-handler.js +48 -0
  96. package/src/monitoring/notification-handlers/resolved-violation-handler.js +54 -0
  97. package/src/monitoring/notification-handlers/threshold-handler.js +36 -0
  98. package/src/provider-registry.js +8 -0
  99. package/src/refactoring/boundary/boundary-detector-refactored.js +58 -0
  100. package/src/refactoring/boundary/boundary-detector.js +26 -596
  101. package/src/refactoring/boundary/detectors/boundary-analyzers.js +281 -0
  102. package/src/refactoring/boundary/detectors/boundary-core.js +167 -0
  103. package/src/refactoring/boundary/detectors/class-detector.js +247 -0
  104. package/src/refactoring/boundary/detectors/config-detector.js +270 -0
  105. package/src/refactoring/boundary/detectors/constant-detector.js +269 -0
  106. package/src/refactoring/boundary/detectors/function-detector.js +248 -0
  107. package/src/refactoring/boundary/detectors/module-detector.js +249 -0
  108. package/src/refactoring/boundary/detectors/object-detector.js +247 -0
  109. package/src/refactoring/boundary/detectors/type-detectors.js +338 -0
  110. package/src/refactoring/boundary/detectors/utility-detector.js +270 -0
  111. package/src/refactoring/circular-dependency-resolver-original.js +16 -76
  112. package/src/refactoring/code-mover-refactored.js +309 -0
  113. package/src/refactoring/code-mover.js +48 -355
  114. package/src/refactoring/execution-status.js +18 -0
  115. package/src/refactoring/execution-strategies.js +172 -0
  116. package/src/refactoring/file-splitter-core.js +568 -0
  117. package/src/refactoring/file-splitter-types.js +136 -0
  118. package/src/refactoring/file-splitter.js +2 -682
  119. package/src/refactoring/functionality-validator.js +11 -51
  120. package/src/refactoring/import-manager-refactored.js +385 -0
  121. package/src/refactoring/import-manager.js +112 -487
  122. package/src/refactoring/import-models.js +189 -0
  123. package/src/refactoring/import-parser.js +306 -0
  124. package/src/refactoring/move-executor.js +431 -0
  125. package/src/refactoring/move-utils.js +368 -0
  126. package/src/refactoring/operation-executor.js +76 -0
  127. package/src/refactoring/plan-creator.js +36 -0
  128. package/src/refactoring/plan-executor.js +143 -0
  129. package/src/refactoring/plan-validator.js +68 -0
  130. package/src/refactoring/refactoring-executor-result.js +70 -0
  131. package/src/refactoring/refactoring-executor.js +34 -569
  132. package/src/refactoring/refactoring-operation.js +94 -0
  133. package/src/refactoring/refactoring-plan.js +69 -0
  134. package/src/refactoring/refactoring-rollback.js +22 -527
  135. package/src/refactoring/rollback-handlers/RollbackExecutor.js +107 -0
  136. package/src/refactoring/rollback-handlers/RollbackManager.js +265 -0
  137. package/src/refactoring/rollback-handlers/RollbackOperation.js +105 -0
  138. package/src/refactoring/rollback-handlers/RollbackResult.js +109 -0
  139. package/src/refactoring/rollback-handlers/RollbackStatistics.js +77 -0
  140. package/src/refactoring/test-validator.js +32 -448
  141. package/src/refactoring/validation/baseline-runner.js +71 -0
  142. package/src/refactoring/validation/report-generator.js +136 -0
  143. package/src/refactoring/validation/result-comparator.js +92 -0
  144. package/src/refactoring/validation/test-suite.js +59 -0
  145. package/src/refactoring/validation/test-validation-result.js +83 -0
  146. package/src/refactoring/validation/validation-runner.js +95 -0
  147. package/src/refactoring/validation/validation-status.js +18 -0
  148. package/src/rui/commands/AgentCommandParser.js +60 -369
  149. package/src/rui/commands/AgentResponseFormatter.js +7 -47
  150. package/src/rui/commands/parsers/CommandMapper.js +148 -0
  151. package/src/rui/commands/parsers/CommandValidator.js +228 -0
  152. package/src/rui/commands/parsers/ComponentExtractor.js +100 -0
  153. package/src/rui/commands/parsers/TokenParser.js +69 -0
  154. package/src/rui/commands/parsers/tokenizer.js +153 -0
  155. package/src/utils/current-requirement-operations.js +50 -1
  156. package/src/utils/report-generator.js +18 -514
  157. package/src/utils/report-generators/analysis-generator.js +115 -0
  158. package/src/utils/report-generators/base-generator.js +141 -0
  159. package/src/utils/report-generators/compliance-generator.js +41 -0
  160. package/src/utils/report-generators/format-handlers.js +185 -0
  161. package/src/utils/report-generators/refactoring-generator.js +46 -0
  162. package/src/utils/report-generators/validation-generator.js +63 -0
  163. package/src/utils/requirement-enable-disable.js +265 -0
  164. package/src/utils/requirement-helpers/requirement-file-ops.js +69 -1
  165. package/src/utils/requirement-helpers/requirement-mover.js +88 -1
  166. package/src/utils/requirement-helpers.js +5 -2
  167. package/src/utils/smoke-test-cli.js +45 -8
  168. package/src/utils/specification-enable-disable.js +122 -0
  169. package/src/utils/specification-helpers.js +30 -4
  170. package/src/utils/specification-migration.js +5 -5
  171. package/src/utils/test-comparator.js +118 -0
  172. package/src/utils/test-config.js +54 -0
  173. package/src/utils/test-executor.js +133 -0
  174. package/src/utils/test-parser.js +215 -0
  175. package/src/utils/test-runner-baseline.js +63 -0
  176. package/src/utils/test-runner-core.js +98 -0
  177. package/src/utils/test-runner-report.js +39 -0
  178. package/src/utils/test-runner-validation.js +71 -0
  179. package/src/utils/test-runner.js +11 -535
  180. package/src/validation/comparison-analyzer.js +333 -0
  181. package/src/validation/compliance-reporter-new.js +282 -0
  182. package/src/validation/compliance-reporter-refactored.js +344 -0
  183. package/src/validation/compliance-reporter.js +278 -591
  184. package/src/validation/compliance-utils.js +278 -0
  185. package/src/validation/html-generator.js +446 -0
  186. package/src/validation/metrics/category-calculator.js +137 -0
  187. package/src/validation/metrics/metrics-helpers.js +155 -0
  188. package/src/validation/metrics/overview-calculator.js +85 -0
  189. package/src/validation/metrics/overview-metrics.js +41 -0
  190. package/src/validation/metrics/quality-calculator.js +166 -0
  191. package/src/validation/metrics/size-calculator.js +69 -0
  192. package/src/validation/metrics-calculator.js +27 -551
@@ -0,0 +1,148 @@
1
+ /**
2
+ * Command Mapper
3
+ *
4
+ * Handles command and shortcut mappings.
5
+ * Part of AgentCommandParser refactoring.
6
+ */
7
+
8
+ class CommandMapper {
9
+ /**
10
+ * Create command mapper
11
+ * @param {Object} options - Mapper options
12
+ */
13
+ constructor(options = {}) {
14
+ this.caseSensitive = options.caseSensitive || false;
15
+ this.allowShortcuts = options.allowShortcuts !== false;
16
+
17
+ this.commandMap = this.initializeCommandMap();
18
+ this.shortcutMap = this.initializeShortcutMap();
19
+ }
20
+
21
+ /**
22
+ * Normalize verb using command map
23
+ * @param {string} verb - Raw verb
24
+ * @returns {string} - Normalized verb
25
+ */
26
+ normalizeVerb(verb) {
27
+ if (!verb) return verb;
28
+
29
+ const normalized = this.caseSensitive ? verb : verb.toUpperCase();
30
+
31
+ // Check shortcuts first
32
+ if (this.allowShortcuts && this.shortcutMap[normalized]) {
33
+ return this.shortcutMap[normalized];
34
+ }
35
+
36
+ // Check full commands
37
+ if (this.commandMap[normalized]) {
38
+ return this.commandMap[normalized];
39
+ }
40
+
41
+ return normalized;
42
+ }
43
+
44
+ /**
45
+ * Initialize command mappings
46
+ * @returns {Object} - Command map
47
+ */
48
+ initializeCommandMap() {
49
+ return {
50
+ 'GET': 'GET',
51
+ 'LIST': 'GET',
52
+ 'POST': 'POST',
53
+ 'CHECK': 'POST',
54
+ 'PUT': 'PUT',
55
+ 'UPDATE': 'PUT',
56
+ 'DELETE': 'DELETE',
57
+ 'REMOVE': 'DELETE',
58
+ 'ENABLE': 'PUT',
59
+ 'DISABLE': 'PUT',
60
+ 'STATUS': 'GET',
61
+ 'HELP': 'GET'
62
+ };
63
+ }
64
+
65
+ /**
66
+ * Initialize shortcut mappings
67
+ * @returns {Object} - Shortcut map
68
+ */
69
+ initializeShortcutMap() {
70
+ return {
71
+ 'LA': 'GET', // List agents
72
+ 'LI': 'GET', // List agents
73
+ 'CH': 'POST', // Check agents
74
+ 'CA': 'POST', // Check agents
75
+ 'GE': 'GET', // Get agent
76
+ 'UP': 'PUT', // Update agent
77
+ 'EN': 'PUT', // Enable agent
78
+ 'DI': 'PUT', // Disable agent
79
+ 'RE': 'DELETE', // Remove agent
80
+ 'RM': 'DELETE', // Remove agent
81
+ 'ST': 'GET', // Status
82
+ 'HE': 'GET' // Help
83
+ };
84
+ }
85
+
86
+ /**
87
+ * Get command suggestions
88
+ * @param {string} partial - Partial command
89
+ * @returns {Array} - Suggestions
90
+ */
91
+ getSuggestions(partial) {
92
+ if (!partial) return [];
93
+
94
+ const normalized = this.caseSensitive ? partial : partial.toUpperCase();
95
+ const suggestions = [];
96
+
97
+ // Command suggestions
98
+ for (const [command, normalizedCommand] of Object.entries(this.commandMap)) {
99
+ if (normalizedCommand.startsWith(normalized)) {
100
+ suggestions.push({
101
+ type: 'command',
102
+ value: command,
103
+ description: this.getCommandDescription(command)
104
+ });
105
+ }
106
+ }
107
+
108
+ // Shortcut suggestions
109
+ if (this.allowShortcuts) {
110
+ for (const [shortcut, command] of Object.entries(this.shortcutMap)) {
111
+ if (shortcut.startsWith(normalized)) {
112
+ suggestions.push({
113
+ type: 'shortcut',
114
+ value: shortcut,
115
+ description: this.getCommandDescription(command)
116
+ });
117
+ }
118
+ }
119
+ }
120
+
121
+ return suggestions;
122
+ }
123
+
124
+ /**
125
+ * Get command description
126
+ * @param {string} command - Command
127
+ * @returns {string} - Description
128
+ */
129
+ getCommandDescription(command) {
130
+ const descriptions = {
131
+ 'GET': 'Get agent or list agents',
132
+ 'POST': 'Check agents',
133
+ 'PUT': 'Update agent (enable/disable)',
134
+ 'DELETE': 'Remove agent',
135
+ 'LIST': 'List agents',
136
+ 'CHECK': 'Check agents',
137
+ 'ENABLE': 'Enable agent',
138
+ 'DISABLE': 'Disable agent',
139
+ 'REMOVE': 'Remove agent',
140
+ 'STATUS': 'Get agent status',
141
+ 'HELP': 'Show help'
142
+ };
143
+
144
+ return descriptions[command] || 'Unknown command';
145
+ }
146
+ }
147
+
148
+ module.exports = CommandMapper;
@@ -0,0 +1,228 @@
1
+ /**
2
+ * Command Validator
3
+ *
4
+ * Validates commands and parameters.
5
+ * Part of AgentCommandParser refactoring.
6
+ */
7
+
8
+ class CommandValidator {
9
+ /**
10
+ * Create command validator
11
+ * @param {Object} options - Validator options
12
+ */
13
+ constructor(options = {}) {
14
+ this.strictMode = options.strictMode || false;
15
+ this.parameterDefinitions = this.initializeParameterDefinitions();
16
+ }
17
+
18
+ /**
19
+ * Validate command components
20
+ * @param {string} verb - Command verb
21
+ * @param {string} resource - Command resource
22
+ * @param {Object} params - Command parameters
23
+ * @returns {Object} - Validation result
24
+ */
25
+ validateCommand(verb, resource, params) {
26
+ const validation = {
27
+ success: true,
28
+ verb,
29
+ resource,
30
+ params,
31
+ errors: [],
32
+ warnings: []
33
+ };
34
+
35
+ // Validate verb
36
+ if (!this.isValidVerb(verb)) {
37
+ validation.success = false;
38
+ validation.errors.push(`Unknown command: ${verb}`);
39
+ return validation;
40
+ }
41
+
42
+ // Validate resource based on verb
43
+ const resourceValidation = this.validateResource(verb, resource);
44
+ if (!resourceValidation.valid) {
45
+ validation.success = false;
46
+ validation.errors.push(...resourceValidation.errors);
47
+ }
48
+
49
+ // Validate parameters
50
+ const paramValidation = this.validateParameters(verb, resource, params);
51
+ if (!paramValidation.valid) {
52
+ validation.success = false;
53
+ validation.errors.push(...paramValidation.errors);
54
+ }
55
+
56
+ validation.warnings.push(...paramValidation.warnings);
57
+
58
+ return validation;
59
+ }
60
+
61
+ /**
62
+ * Check if verb is valid
63
+ * @param {string} verb - Verb to check
64
+ * @returns {boolean} - Whether verb is valid
65
+ */
66
+ isValidVerb(verb) {
67
+ const validVerbs = new Set([
68
+ 'GET', 'LIST', 'POST', 'CHECK', 'PUT', 'UPDATE', 'DELETE', 'REMOVE',
69
+ 'ENABLE', 'DISABLE', 'STATUS', 'HELP'
70
+ ]);
71
+
72
+ return validVerbs.has(verb);
73
+ }
74
+
75
+ /**
76
+ * Validate resource for given verb
77
+ * @param {string} verb - Command verb
78
+ * @param {string} resource - Resource to validate
79
+ * @returns {Object} - Validation result
80
+ */
81
+ validateResource(verb, resource) {
82
+ const validation = { valid: true, errors: [] };
83
+
84
+ // Verbs that require resource
85
+ const resourceRequiredVerbs = new Set(['GET', 'PUT', 'UPDATE', 'DELETE', 'REMOVE', 'ENABLE', 'DISABLE']);
86
+
87
+ if (resourceRequiredVerbs.has(verb) && !resource) {
88
+ validation.valid = false;
89
+ validation.errors.push('Resource is required for this command');
90
+ }
91
+
92
+ // Validate resource format
93
+ if (resource && !this.isValidResource(resource)) {
94
+ validation.valid = false;
95
+ validation.errors.push(`Invalid resource: ${resource}`);
96
+ }
97
+
98
+ return validation;
99
+ }
100
+
101
+ /**
102
+ * Check if resource is valid
103
+ * @param {string} resource - Resource to check
104
+ * @returns {boolean} - Whether resource is valid
105
+ */
106
+ isValidResource(resource) {
107
+ const validResources = ['agents', 'agent'];
108
+ return validResources.includes(resource.toLowerCase()) ||
109
+ resource.toLowerCase().startsWith('agent-');
110
+ }
111
+
112
+ /**
113
+ * Validate command parameters
114
+ * @param {string} verb - Command verb
115
+ * @param {string} resource - Command resource
116
+ * @param {Object} params - Parameters to validate
117
+ * @returns {Object} - Validation result
118
+ */
119
+ validateParameters(verb, resource, params) {
120
+ const validation = { valid: true, errors: [], warnings: [] };
121
+
122
+ // Get parameter definitions for this verb
123
+ const paramDefs = this.parameterDefinitions[verb] || {};
124
+
125
+ // Validate each parameter
126
+ for (const [paramName, paramValue] of Object.entries(params)) {
127
+ if (paramName === 'positional') continue;
128
+
129
+ const paramDef = paramDefs[paramName];
130
+ if (!paramDef) {
131
+ if (this.strictMode) {
132
+ validation.valid = false;
133
+ validation.errors.push(`Unknown parameter: ${paramName}`);
134
+ }
135
+ continue;
136
+ }
137
+
138
+ // Type validation
139
+ if (paramDef.type && !this.validateParameterType(paramValue, paramDef.type)) {
140
+ validation.valid = false;
141
+ validation.errors.push(`Invalid type for parameter ${paramName}: expected ${paramDef.type}`);
142
+ }
143
+
144
+ // Value validation
145
+ if (paramDef.validValues && !paramDef.validValues.includes(paramValue)) {
146
+ validation.valid = false;
147
+ validation.errors.push(`Invalid value for parameter ${paramName}: ${paramValue}. Valid values: ${paramDef.validValues.join(', ')}`);
148
+ }
149
+ }
150
+
151
+ // Check for required parameters
152
+ for (const [paramName, paramDef] of Object.entries(paramDefs)) {
153
+ if (paramDef.required && !(paramName in params)) {
154
+ validation.valid = false;
155
+ validation.errors.push(`Required parameter missing: ${paramName}`);
156
+ }
157
+ }
158
+
159
+ // Add warnings for special cases
160
+ if (verb === 'DELETE' && !params.confirm) {
161
+ validation.warnings.push('DELETE command requires confirmation (confirm=true)');
162
+ }
163
+
164
+ if (verb === 'CHECK' && params.timeout && params.timeout < 0) {
165
+ validation.warnings.push('Timeout should be positive');
166
+ }
167
+
168
+ return validation;
169
+ }
170
+
171
+ /**
172
+ * Validate parameter type
173
+ * @param {*} value - Parameter value
174
+ * @param {string} type - Expected type
175
+ * @returns {boolean} - Whether type is valid
176
+ */
177
+ validateParameterType(value, type) {
178
+ switch (type) {
179
+ case 'boolean':
180
+ return typeof value === 'boolean' || value === true || value === false;
181
+ case 'number':
182
+ return !isNaN(Number(value));
183
+ case 'string':
184
+ return typeof value === 'string';
185
+ case 'array':
186
+ return Array.isArray(value);
187
+ default:
188
+ return true; // Unknown type, assume valid
189
+ }
190
+ }
191
+
192
+ /**
193
+ * Initialize parameter definitions
194
+ * @returns {Object} - Parameter definitions
195
+ */
196
+ initializeParameterDefinitions() {
197
+ return {
198
+ 'GET': {
199
+ 'includeDisabled': { type: 'boolean', default: false },
200
+ 'includeStatus': { type: 'boolean', default: true },
201
+ 'includeLogs': { type: 'boolean', default: false },
202
+ 'format': { type: 'string', validValues: ['table', 'json', 'csv'] },
203
+ 'sort': { type: 'string', validValues: ['name', 'status', 'type', 'priority'] },
204
+ 'status': { type: 'string' },
205
+ 'limit': { type: 'number' },
206
+ 'offset': { type: 'number' }
207
+ },
208
+ 'POST': {
209
+ 'agentIds': { type: 'array' },
210
+ 'forceReinstall': { type: 'boolean', default: false },
211
+ 'skipVerification': { type: 'boolean', default: false },
212
+ 'timeout': { type: 'number', default: 300000 },
213
+ 'parallel': { type: 'boolean', default: true },
214
+ 'maxConcurrency': { type: 'number', default: 2 }
215
+ },
216
+ 'PUT': {
217
+ 'enabled': { type: 'boolean' },
218
+ 'status': { type: 'string' },
219
+ 'message': { type: 'string' }
220
+ },
221
+ 'DELETE': {
222
+ 'confirm': { type: 'boolean', required: true }
223
+ }
224
+ };
225
+ }
226
+ }
227
+
228
+ module.exports = CommandValidator;
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Component Extractor
3
+ *
4
+ * Extracts verb, resource, and parameters from tokens.
5
+ * Part of AgentCommandParser refactoring.
6
+ */
7
+
8
+ class ComponentExtractor {
9
+ /**
10
+ * Create component extractor
11
+ * @param {Object} options - Extractor options
12
+ */
13
+ constructor(options = {}) {
14
+ this.allowShortcuts = options.allowShortcuts !== false;
15
+ this.tokenParser = options.tokenParser;
16
+ }
17
+
18
+ /**
19
+ * Extract verb, resource, and parameters from tokens
20
+ * @param {Array} tokens - Command tokens
21
+ * @returns {Object} - Extracted components
22
+ */
23
+ extractComponents(tokens) {
24
+ if (tokens.length === 0) {
25
+ throw new Error('Empty command');
26
+ }
27
+
28
+ let verb = tokens[0];
29
+ let resource = '';
30
+ let params = {};
31
+
32
+ // Handle shortcuts (2-character commands)
33
+ if (this.allowShortcuts && tokens.length >= 2 && tokens[0].length <= 3) {
34
+ verb = tokens[0];
35
+ resource = tokens[1];
36
+
37
+ // Extract parameters from remaining tokens
38
+ for (let i = 2; i < tokens.length; i++) {
39
+ this.parseParameter(tokens[i], params);
40
+ }
41
+ }
42
+ // Handle full commands
43
+ else if (tokens.length >= 2) {
44
+ verb = tokens[0];
45
+ resource = tokens[1];
46
+
47
+ // Extract parameters from remaining tokens
48
+ for (let i = 2; i < tokens.length; i++) {
49
+ this.parseParameter(tokens[i], params);
50
+ }
51
+ } else {
52
+ // Single token - might be verb only or verb+resource
53
+ const parts = tokens[0].split(/\s+/);
54
+ if (parts.length >= 2) {
55
+ verb = parts[0];
56
+ resource = parts[1];
57
+ }
58
+ }
59
+
60
+ return { verb, resource, params };
61
+ }
62
+
63
+ /**
64
+ * Parse parameter token
65
+ * @param {string} token - Parameter token
66
+ * @param {Object} params - Parameters object to update
67
+ */
68
+ parseParameter(token, params) {
69
+ // Handle flag parameters (--flag)
70
+ if (token.startsWith('--')) {
71
+ const flag = token.substring(2);
72
+ params[flag] = true;
73
+ }
74
+ // Handle short flags (-f)
75
+ else if (token.startsWith('-') && !token.startsWith('--')) {
76
+ const flag = token.substring(1);
77
+ params[flag] = true;
78
+ }
79
+ // Handle key=value parameters (--key=value)
80
+ else if (token.includes('=')) {
81
+ const [key, value] = token.split('=', 2);
82
+ const cleanKey = key.startsWith('--') ? key.substring(2) : key.startsWith('-') ? key.substring(1) : key;
83
+ params[cleanKey] = this.tokenParser.parseValue(value);
84
+ }
85
+ // Handle key value parameters (--key value)
86
+ else if (token.startsWith('--')) {
87
+ const key = token.substring(2);
88
+ params[key] = true; // Will be updated with next token if it's a value
89
+ }
90
+ // Positional parameter
91
+ else {
92
+ if (!params.positional) {
93
+ params.positional = [];
94
+ }
95
+ params.positional.push(this.tokenParser.parseValue(token));
96
+ }
97
+ }
98
+ }
99
+
100
+ module.exports = ComponentExtractor;
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Token Parser
3
+ *
4
+ * Handles tokenization of command strings.
5
+ * Part of AgentCommandParser refactoring.
6
+ */
7
+
8
+ class TokenParser {
9
+ /**
10
+ * Tokenize command string
11
+ * @param {string} commandString - Command string to tokenize
12
+ * @returns {Array} - Array of tokens
13
+ */
14
+ tokenize(commandString) {
15
+ // Handle quoted strings and parameters
16
+ const tokens = [];
17
+ let current = '';
18
+ let inQuotes = false;
19
+ let quoteChar = '';
20
+
21
+ for (let i = 0; i < commandString.length; i++) {
22
+ const char = commandString[i];
23
+
24
+ if ((char === '"' || char === "'") && !inQuotes) {
25
+ inQuotes = true;
26
+ quoteChar = char;
27
+ } else if (char === quoteChar && inQuotes) {
28
+ inQuotes = false;
29
+ quoteChar = '';
30
+ } else if (char === ' ' && !inQuotes) {
31
+ if (current.trim()) {
32
+ tokens.push(current.trim());
33
+ current = '';
34
+ }
35
+ } else {
36
+ current += char;
37
+ }
38
+ }
39
+
40
+ if (current.trim()) {
41
+ tokens.push(current.trim());
42
+ }
43
+
44
+ return tokens;
45
+ }
46
+
47
+ /**
48
+ * Parse parameter value
49
+ * @param {string} value - Raw value
50
+ * @returns {*} - Parsed value
51
+ */
52
+ parseValue(value) {
53
+ // Remove quotes if present
54
+ if ((value.startsWith('"') && value.endsWith('"')) ||
55
+ (value.startsWith("'") && value.endsWith("'"))) {
56
+ value = value.slice(1, -1);
57
+ }
58
+
59
+ // Parse as JSON if possible
60
+ try {
61
+ return JSON.parse(value);
62
+ } catch {
63
+ // Return as string if not valid JSON
64
+ return value;
65
+ }
66
+ }
67
+ }
68
+
69
+ module.exports = TokenParser;
@@ -0,0 +1,153 @@
1
+ /**
2
+ * RUI Command Tokenizer
3
+ *
4
+ * Handles tokenization of command strings with quote and parameter support.
5
+ */
6
+
7
+ /**
8
+ * Tokenize command string
9
+ * @param {string} commandString - Command string to tokenize
10
+ * @returns {Array} - Array of tokens
11
+ */
12
+ function tokenize(commandString) {
13
+ // Handle quoted strings and parameters
14
+ const tokens = [];
15
+ let current = '';
16
+ let inQuotes = false;
17
+ let quoteChar = '';
18
+
19
+ for (let i = 0; i < commandString.length; i++) {
20
+ const char = commandString[i];
21
+
22
+ if ((char === '"' || char === "'") && !inQuotes) {
23
+ inQuotes = true;
24
+ quoteChar = char;
25
+ } else if (char === quoteChar && inQuotes) {
26
+ inQuotes = false;
27
+ quoteChar = '';
28
+ } else if (char === ' ' && !inQuotes) {
29
+ if (current.trim()) {
30
+ tokens.push(current.trim());
31
+ current = '';
32
+ }
33
+ } else {
34
+ current += char;
35
+ }
36
+ }
37
+
38
+ if (current.trim()) {
39
+ tokens.push(current.trim());
40
+ }
41
+
42
+ return tokens;
43
+ }
44
+
45
+ /**
46
+ * Extract verb, resource, and parameters from tokens
47
+ * @param {Array} tokens - Command tokens
48
+ * @param {boolean} allowShortcuts - Whether shortcuts are allowed
49
+ * @returns {Object} - Extracted components
50
+ */
51
+ function extractComponents(tokens, allowShortcuts = true) {
52
+ if (tokens.length === 0) {
53
+ throw new Error('Empty command');
54
+ }
55
+
56
+ let verb = tokens[0];
57
+ let resource = '';
58
+ let params = {};
59
+
60
+ // Handle shortcuts (2-character commands)
61
+ if (allowShortcuts && tokens.length >= 2 && tokens[0].length <= 3) {
62
+ verb = tokens[0];
63
+ resource = tokens[1];
64
+
65
+ // Extract parameters from remaining tokens
66
+ for (let i = 2; i < tokens.length; i++) {
67
+ parseParameter(tokens[i], params);
68
+ }
69
+ }
70
+ // Handle full commands
71
+ else if (tokens.length >= 2) {
72
+ verb = tokens[0];
73
+ resource = tokens[1];
74
+
75
+ // Extract parameters from remaining tokens
76
+ for (let i = 2; i < tokens.length; i++) {
77
+ parseParameter(tokens[i], params);
78
+ }
79
+ } else {
80
+ // Single token - might be verb only or verb+resource
81
+ const parts = tokens[0].split(/\s+/);
82
+ if (parts.length >= 2) {
83
+ verb = parts[0];
84
+ resource = parts[1];
85
+ }
86
+ }
87
+
88
+ return { verb, resource, params };
89
+ }
90
+
91
+ /**
92
+ * Parse parameter token
93
+ * @param {string} token - Parameter token
94
+ * @param {Object} params - Parameters object to update
95
+ */
96
+ function parseParameter(token, params) {
97
+ // Handle flag parameters (--flag)
98
+ if (token.startsWith('--')) {
99
+ const flag = token.substring(2);
100
+ params[flag] = true;
101
+ }
102
+ // Handle short flags (-f)
103
+ else if (token.startsWith('-') && !token.startsWith('--')) {
104
+ const flag = token.substring(1);
105
+ params[flag] = true;
106
+ }
107
+ // Handle key=value parameters (--key=value)
108
+ else if (token.includes('=')) {
109
+ const [key, value] = token.split('=', 2);
110
+ const cleanKey = key.startsWith('--') ? key.substring(2) : key.startsWith('-') ? key.substring(1) : key;
111
+ params[cleanKey] = parseValue(value);
112
+ }
113
+ // Handle key value parameters (--key value)
114
+ else if (token.startsWith('--')) {
115
+ const key = token.substring(2);
116
+ params[key] = true; // Will be updated with next token if it's a value
117
+ }
118
+ // Positional parameter
119
+ else {
120
+ if (!params.positional) {
121
+ params.positional = [];
122
+ }
123
+ params.positional.push(parseValue(token));
124
+ }
125
+ }
126
+
127
+ /**
128
+ * Parse parameter value
129
+ * @param {string} value - Raw value
130
+ * @returns {*} - Parsed value
131
+ */
132
+ function parseValue(value) {
133
+ // Remove quotes if present
134
+ if ((value.startsWith('"') && value.endsWith('"')) ||
135
+ (value.startsWith("'") && value.endsWith("'"))) {
136
+ value = value.slice(1, -1);
137
+ }
138
+
139
+ // Parse as JSON if possible
140
+ try {
141
+ return JSON.parse(value);
142
+ } catch {
143
+ // Return as string if not valid JSON
144
+ return value;
145
+ }
146
+ }
147
+
148
+ module.exports = {
149
+ tokenize,
150
+ extractComponents,
151
+ parseParameter,
152
+ parseValue
153
+ };