vibecodingmachine-core 2026.2.20-438 → 2026.2.26-1739
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,480 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Command Execution Verifier
|
|
3
|
+
*
|
|
4
|
+
* Command execution verification implementation.
|
|
5
|
+
* Follows constitutional requirements: <555 lines, test-first approach.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const BaseVerifier = require('./BaseVerifier');
|
|
9
|
+
const { VerificationType } = require('../VerificationType');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Command execution verifier class
|
|
13
|
+
*/
|
|
14
|
+
class CommandVerifier extends BaseVerifier {
|
|
15
|
+
/**
|
|
16
|
+
* Create command execution verifier instance
|
|
17
|
+
* @param {Object} config - Verifier configuration
|
|
18
|
+
*/
|
|
19
|
+
constructor(config = {}) {
|
|
20
|
+
super({
|
|
21
|
+
type: VerificationType.COMMAND_EXECUTION,
|
|
22
|
+
description: 'Basic command execution test',
|
|
23
|
+
command: config.command || '{agentCommand} --version',
|
|
24
|
+
expectedResult: config.expectedResult || 'version',
|
|
25
|
+
timeout: config.timeout || 15,
|
|
26
|
+
...config
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
this.agentCommand = config.agentCommand || '';
|
|
30
|
+
this.versionFlag = config.versionFlag || '--version';
|
|
31
|
+
this.helpFlag = config.helpFlag || '--help';
|
|
32
|
+
this.testCommand = config.testCommand || '';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Execute command verification
|
|
37
|
+
* @param {Object} options - Verification options
|
|
38
|
+
* @returns {Promise<Object>} - Verification result
|
|
39
|
+
*/
|
|
40
|
+
async verify(options = {}) {
|
|
41
|
+
const { context = {} } = options;
|
|
42
|
+
|
|
43
|
+
if (this.logger) {
|
|
44
|
+
await this.logger.info('Starting command execution verification', {
|
|
45
|
+
agentCommand: this.agentCommand,
|
|
46
|
+
testCommand: this.testCommand,
|
|
47
|
+
context
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const startTime = Date.now();
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
// Build test command
|
|
55
|
+
const testCommand = this.buildTestCommand(context);
|
|
56
|
+
|
|
57
|
+
// Execute command
|
|
58
|
+
const result = await this.executeCommand(testCommand, this.timeout * 1000);
|
|
59
|
+
|
|
60
|
+
// Evaluate result
|
|
61
|
+
const passed = this.evaluateResult(result);
|
|
62
|
+
|
|
63
|
+
const verificationResult = {
|
|
64
|
+
id: this.generateId(),
|
|
65
|
+
agentId: options.agentId || '',
|
|
66
|
+
type: this.type,
|
|
67
|
+
description: this.description,
|
|
68
|
+
passed,
|
|
69
|
+
command: testCommand,
|
|
70
|
+
result,
|
|
71
|
+
duration: Date.now() - startTime,
|
|
72
|
+
timeout: this.timeout * 1000,
|
|
73
|
+
timestamp: new Date().toISOString(),
|
|
74
|
+
agentCommand: this.agentCommand,
|
|
75
|
+
versionFlag: this.versionFlag
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
if (this.logger) {
|
|
79
|
+
const level = passed ? 'info' : 'warn';
|
|
80
|
+
const message = passed
|
|
81
|
+
? 'Command execution verification passed'
|
|
82
|
+
: 'Command execution verification failed';
|
|
83
|
+
|
|
84
|
+
await this.logger[level](message, {
|
|
85
|
+
agentId: options.agentId,
|
|
86
|
+
agentCommand: this.agentCommand,
|
|
87
|
+
passed,
|
|
88
|
+
duration: verificationResult.duration,
|
|
89
|
+
exitCode: result.exitCode
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return verificationResult;
|
|
94
|
+
} catch (error) {
|
|
95
|
+
const errorResult = {
|
|
96
|
+
id: this.generateId(),
|
|
97
|
+
agentId: options.agentId || '',
|
|
98
|
+
type: this.type,
|
|
99
|
+
description: this.description,
|
|
100
|
+
passed: false,
|
|
101
|
+
error: error.message,
|
|
102
|
+
duration: Date.now() - startTime,
|
|
103
|
+
timeout: this.timeout * 1000,
|
|
104
|
+
timestamp: new Date().toISOString(),
|
|
105
|
+
agentCommand: this.agentCommand
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
if (this.logger) {
|
|
109
|
+
await this.logger.error('Command execution verification error', {
|
|
110
|
+
agentId: options.agentId,
|
|
111
|
+
agentCommand: this.agentCommand,
|
|
112
|
+
error: error.message,
|
|
113
|
+
duration: errorResult.duration
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return errorResult;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Build test command with context
|
|
123
|
+
* @param {Object} context - Test context
|
|
124
|
+
* @returns {string} - Test command
|
|
125
|
+
*/
|
|
126
|
+
buildTestCommand(context) {
|
|
127
|
+
let command = this.command;
|
|
128
|
+
|
|
129
|
+
// Replace common placeholders
|
|
130
|
+
Object.entries(context).forEach(([key, value]) => {
|
|
131
|
+
const placeholder = `{${key}}`;
|
|
132
|
+
command = command.replace(new RegExp(placeholder, 'g'), value);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
return command;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Execute command with enhanced error handling
|
|
140
|
+
* @param {string} command - Command to execute
|
|
141
|
+
* @param {number} timeout - Timeout in milliseconds
|
|
142
|
+
* @returns {Promise<Object>} - Execution result
|
|
143
|
+
*/
|
|
144
|
+
async executeCommand(command, timeout) {
|
|
145
|
+
return new Promise((resolve, reject) => {
|
|
146
|
+
const { spawn } = require('child_process');
|
|
147
|
+
|
|
148
|
+
const startTime = Date.now();
|
|
149
|
+
const child = spawn(command, [], {
|
|
150
|
+
shell: true,
|
|
151
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
152
|
+
windowsHide: true
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
let stdout = '';
|
|
156
|
+
let stderr = '';
|
|
157
|
+
|
|
158
|
+
child.stdout.on('data', (data) => {
|
|
159
|
+
stdout += data.toString();
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
child.stderr.on('data', (data) => {
|
|
163
|
+
stderr += data.toString();
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
const timeoutId = setTimeout(() => {
|
|
167
|
+
child.kill('SIGTERM');
|
|
168
|
+
reject(new Error(`Command execution timed out after ${timeout}ms`));
|
|
169
|
+
}, timeout);
|
|
170
|
+
|
|
171
|
+
child.on('close', (code) => {
|
|
172
|
+
clearTimeout(timeoutId);
|
|
173
|
+
|
|
174
|
+
const duration = Date.now() - startTime;
|
|
175
|
+
|
|
176
|
+
resolve({
|
|
177
|
+
success: code === 0,
|
|
178
|
+
exitCode: code,
|
|
179
|
+
stdout: stdout.trim(),
|
|
180
|
+
stderr: stderr.trim(),
|
|
181
|
+
duration,
|
|
182
|
+
command
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
child.on('error', (error) => {
|
|
187
|
+
clearTimeout(timeoutId);
|
|
188
|
+
reject(error);
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Evaluate command execution result
|
|
195
|
+
* @param {Object} result - Command result
|
|
196
|
+
* @returns {boolean} - True if verification passed
|
|
197
|
+
*/
|
|
198
|
+
evaluateResult(result) {
|
|
199
|
+
// Basic success check - command should exit with code 0
|
|
200
|
+
if (!result.success) {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Check for expected result in output
|
|
205
|
+
if (this.expectedResult) {
|
|
206
|
+
const output = result.stdout.toLowerCase();
|
|
207
|
+
const expected = this.expectedResult.toLowerCase();
|
|
208
|
+
|
|
209
|
+
if (expected !== 'any' && !output.includes(expected)) {
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Additional checks based on command type
|
|
215
|
+
return this.performAdditionalChecks(result);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Perform additional verification checks
|
|
220
|
+
* @param {Object} result - Command result
|
|
221
|
+
* @returns {boolean} - True if additional checks pass
|
|
222
|
+
*/
|
|
223
|
+
performAdditionalChecks(result) {
|
|
224
|
+
// Check for common error indicators
|
|
225
|
+
const errorIndicators = [
|
|
226
|
+
'command not found',
|
|
227
|
+
'not recognized',
|
|
228
|
+
'permission denied',
|
|
229
|
+
'access denied',
|
|
230
|
+
'no such file',
|
|
231
|
+
'file not found',
|
|
232
|
+
'error:',
|
|
233
|
+
'failed',
|
|
234
|
+
'unable to'
|
|
235
|
+
];
|
|
236
|
+
|
|
237
|
+
const output = result.stdout.toLowerCase() + ' ' + result.stderr.toLowerCase();
|
|
238
|
+
|
|
239
|
+
for (const indicator of errorIndicators) {
|
|
240
|
+
if (output.includes(indicator)) {
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// Check for version-like output
|
|
246
|
+
const versionPatterns = [
|
|
247
|
+
/\d+\.\d+\.\d+/, // x.y.z
|
|
248
|
+
/\d+\.\d+/, // x.y
|
|
249
|
+
/v\d+\.\d+\.\d+/, // vx.y.z
|
|
250
|
+
/version \d+/, // version x
|
|
251
|
+
/\d+\.\d+\.\d+-\w+/, // x.y.z-beta
|
|
252
|
+
];
|
|
253
|
+
|
|
254
|
+
const hasVersionOutput = versionPatterns.some(pattern =>
|
|
255
|
+
pattern.test(result.stdout) || pattern.test(result.stderr)
|
|
256
|
+
);
|
|
257
|
+
|
|
258
|
+
return hasVersionOutput || result.success;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Test command availability
|
|
263
|
+
* @param {string} command - Command to test
|
|
264
|
+
* @returns {Promise<boolean>} - True if command is available
|
|
265
|
+
*/
|
|
266
|
+
async testCommandAvailability(command) {
|
|
267
|
+
try {
|
|
268
|
+
const result = await this.executeCommand(`${command} --version`, 5000);
|
|
269
|
+
return result.success;
|
|
270
|
+
} catch (error) {
|
|
271
|
+
return false;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Get command version information
|
|
277
|
+
* @param {string} command - Command to check
|
|
278
|
+
* @returns {Promise<string|null>} - Version string or null
|
|
279
|
+
*/
|
|
280
|
+
async getCommandVersion(command) {
|
|
281
|
+
try {
|
|
282
|
+
const result = await this.executeCommand(`${command} --version`, 10000);
|
|
283
|
+
|
|
284
|
+
if (result.success) {
|
|
285
|
+
// Parse version from output
|
|
286
|
+
const lines = result.stdout.split('\n');
|
|
287
|
+
const versionLine = lines.find(line =>
|
|
288
|
+
line.toLowerCase().includes('version') ||
|
|
289
|
+
/\d+\.\d+\.\d+/.test(line)
|
|
290
|
+
);
|
|
291
|
+
|
|
292
|
+
if (versionLine) {
|
|
293
|
+
const match = versionLine.match(/(\d+\.\d+\.\d+)/);
|
|
294
|
+
return match ? match[1] : null;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
return null;
|
|
299
|
+
} catch (error) {
|
|
300
|
+
return null;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Test command with different flags
|
|
306
|
+
* @param {string} command - Base command
|
|
307
|
+
* @param {Array<string>} flags - Flags to test
|
|
308
|
+
* @returns {Promise<Object>} - Test results
|
|
309
|
+
*/
|
|
310
|
+
async testCommandFlags(command, flags) {
|
|
311
|
+
const results = {};
|
|
312
|
+
|
|
313
|
+
for (const flag of flags) {
|
|
314
|
+
try {
|
|
315
|
+
const testCommand = `${command} ${flag}`;
|
|
316
|
+
const result = await this.executeCommand(testCommand, 10000);
|
|
317
|
+
results[flag] = {
|
|
318
|
+
success: result.success,
|
|
319
|
+
output: result.stdout,
|
|
320
|
+
error: result.stderr
|
|
321
|
+
};
|
|
322
|
+
} catch (error) {
|
|
323
|
+
results[flag] = {
|
|
324
|
+
success: false,
|
|
325
|
+
error: error.message
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
return results;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Check if command is installed in PATH
|
|
335
|
+
* @param {string} command - Command to check
|
|
336
|
+
* @returns {Promise<boolean>} - True if command is in PATH
|
|
337
|
+
*/
|
|
338
|
+
async isCommandInPath(command) {
|
|
339
|
+
try {
|
|
340
|
+
const { execSync } = require('child_process');
|
|
341
|
+
|
|
342
|
+
// Use 'where' on Windows, 'which' on Unix-like systems
|
|
343
|
+
const checkCommand = process.platform === 'win32' ? `where ${command}` : `which ${command}`;
|
|
344
|
+
|
|
345
|
+
execSync(checkCommand, { stdio: 'ignore' });
|
|
346
|
+
return true;
|
|
347
|
+
} catch (error) {
|
|
348
|
+
return false;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Get command help information
|
|
354
|
+
* @param {string} command - Command to get help for
|
|
355
|
+
* @returns {Promise<string|null>} - Help output or null
|
|
356
|
+
*/
|
|
357
|
+
async getCommandHelp(command) {
|
|
358
|
+
try {
|
|
359
|
+
const helpCommand = `${command} ${this.helpFlag}`;
|
|
360
|
+
const result = await this.executeCommand(helpCommand, 15000);
|
|
361
|
+
|
|
362
|
+
return result.success ? result.stdout : null;
|
|
363
|
+
} catch (error) {
|
|
364
|
+
return null;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Validate command syntax
|
|
370
|
+
* @param {string} command - Command to validate
|
|
371
|
+
* @returns {Object} - Validation result
|
|
372
|
+
*/
|
|
373
|
+
validateCommandSyntax(command) {
|
|
374
|
+
const result = {
|
|
375
|
+
valid: true,
|
|
376
|
+
errors: [],
|
|
377
|
+
warnings: []
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
// Check for dangerous commands
|
|
381
|
+
const dangerousCommands = [
|
|
382
|
+
'rm -rf /',
|
|
383
|
+
'del /s /q',
|
|
384
|
+
'format',
|
|
385
|
+
'fdisk',
|
|
386
|
+
'shutdown',
|
|
387
|
+
'reboot'
|
|
388
|
+
];
|
|
389
|
+
|
|
390
|
+
const commandLower = command.toLowerCase();
|
|
391
|
+
for (const dangerous of dangerousCommands) {
|
|
392
|
+
if (commandLower.includes(dangerous)) {
|
|
393
|
+
result.valid = false;
|
|
394
|
+
result.errors.push(`Potentially dangerous command detected: ${dangerous}`);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// Check for command injection patterns
|
|
399
|
+
const injectionPatterns = [
|
|
400
|
+
/&&\s*rm/,
|
|
401
|
+
/\|\s*del/,
|
|
402
|
+
/;\s*format/,
|
|
403
|
+
/`.*rm/,
|
|
404
|
+
/\$\(.*del/
|
|
405
|
+
];
|
|
406
|
+
|
|
407
|
+
for (const pattern of injectionPatterns) {
|
|
408
|
+
if (pattern.test(command)) {
|
|
409
|
+
result.valid = false;
|
|
410
|
+
result.errors.push('Potential command injection detected');
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
return result;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Get command execution verifier information
|
|
419
|
+
* @returns {Object} - Verifier info
|
|
420
|
+
*/
|
|
421
|
+
getVerifierInfo() {
|
|
422
|
+
return {
|
|
423
|
+
...this.getInfo(),
|
|
424
|
+
type: VerificationType.COMMAND_EXECUTION,
|
|
425
|
+
supportedPlatforms: ['win32', 'darwin', 'linux'],
|
|
426
|
+
requirements: [
|
|
427
|
+
'command line access',
|
|
428
|
+
'agent installation',
|
|
429
|
+
'execution permissions'
|
|
430
|
+
],
|
|
431
|
+
features: [
|
|
432
|
+
'command execution',
|
|
433
|
+
'version checking',
|
|
434
|
+
'help support',
|
|
435
|
+
'error detection',
|
|
436
|
+
'syntax validation'
|
|
437
|
+
],
|
|
438
|
+
limitations: [
|
|
439
|
+
'requires agent installation',
|
|
440
|
+
'command dependent',
|
|
441
|
+
'platform specific',
|
|
442
|
+
'permission dependent'
|
|
443
|
+
]
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Create command execution verifier from configuration
|
|
449
|
+
* @param {Object} config - Configuration object
|
|
450
|
+
* @param {AgentLogger} logger - Logger instance
|
|
451
|
+
* @returns {CommandVerifier} - Verifier instance
|
|
452
|
+
*/
|
|
453
|
+
static fromConfig(config, logger = null) {
|
|
454
|
+
return new CommandVerifier({
|
|
455
|
+
...config,
|
|
456
|
+
logger
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Create default command execution verifier
|
|
462
|
+
* @param {string} agentId - Agent identifier
|
|
463
|
+
* @param {string} agentCommand - Agent command
|
|
464
|
+
* @param {AgentLogger} logger - Logger instance
|
|
465
|
+
* @returns {CommandVerifier} - Default verifier instance
|
|
466
|
+
*/
|
|
467
|
+
static createDefault(agentId, agentCommand, logger = null) {
|
|
468
|
+
return new CommandVerifier({
|
|
469
|
+
id: `${agentId}-cmd-exec`,
|
|
470
|
+
agentId,
|
|
471
|
+
command: `${agentCommand} --version`,
|
|
472
|
+
expectedResult: 'version',
|
|
473
|
+
timeout: 15,
|
|
474
|
+
agentCommand,
|
|
475
|
+
logger
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
module.exports = CommandVerifier;
|