erosolar-cli
Version:
Unified AI agent framework for the command line - Multi-provider support with schema-driven tools, code intelligence, and transparent reasoning
129 lines (120 loc) • 3.91 kB
JavaScript
/**
* Isolated Verification System
*
* Provides runtime isolation for verification tasks by running them in separate processes.
* This ensures that verification failures don't affect the main CLI process.
*/
export class IsolatedVerifier {
/**
* Verify task completion in an isolated process
*/
async verifyTaskCompletion(taskName, config) {
const startTime = Date.now();
try {
const scriptPath = await this.createVerificationScript(config);
const { exec } = await import('node:child_process');
const { promisify } = await import('node:util');
const execAsync = promisify(exec);
const result = await execAsync(`node "${scriptPath}"`, {
timeout: 30000
});
const duration = Date.now() - startTime;
return {
success: true,
report: this.generateReport(taskName, config, result.stdout, result.stderr, duration),
duration
};
}
catch (error) {
const duration = Date.now() - startTime;
return {
success: false,
report: this.generateErrorReport(taskName, config, error, duration),
error: error.message,
duration
};
}
}
/**
* Create a verification script that runs in isolation
*/
async createVerificationScript(config) {
const fs = await import('node:fs');
const os = await import('node:os');
const path = await import('node:path');
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'isolated-verification-'));
const scriptPath = path.join(tempDir, 'verification.js');
const scriptContent = this.generateVerificationScript(config);
fs.writeFileSync(scriptPath, scriptContent, 'utf8');
return scriptPath;
}
/**
* Generate the verification script content
*/
generateVerificationScript(config) {
const fileChecks = config.expectedFiles.map(file => ` if (!require('fs').existsSync("${file}")) {
console.error('MISSING FILE: ${file}');
process.exit(1);
}`).join('\n');
const commandExecutions = config.verificationCommands.map(cmd => ` try {
const { execSync } = require('child_process');
execSync("${cmd}", { stdio: 'inherit' });
} catch (error) {
console.error('COMMAND FAILED: ${cmd}');
console.error(error.message);
process.exit(1);
}`).join('\n');
return `#!/usr/bin/env node
/**
* Isolated Verification Script
* Generated by Erosolar CLI
*/
console.log('ISOLATED VERIFICATION REPORT');
console.log('=============================');
console.log('Task: ${config.taskDescription}');
console.log('');
// File existence checks
${fileChecks}
// Command executions
${commandExecutions}
console.log('');
console.log('VERIFICATION COMPLETED SUCCESSFULLY');
`;
}
/**
* Generate a success report
*/
generateReport(taskName, config, stdout, stderr, duration) {
return `ISOLATED VERIFICATION REPORT
=============================
Task: ${taskName}
Description: ${config.taskDescription}
Duration: ${duration}ms
Status: SUCCESS
VERIFICATION STEPS:
${config.verificationCommands.map((cmd, i) => ` ${i + 1}. ${cmd}`).join('\n')}
OUTPUT:
${stdout}
${stderr ? `ERRORS:\n${stderr}` : ''}
`;
}
/**
* Generate an error report
*/
generateErrorReport(taskName, config, error, duration) {
return `ISOLATED VERIFICATION REPORT
=============================
Task: ${taskName}
Description: ${config.taskDescription}
Duration: ${duration}ms
Status: FAILED
VERIFICATION STEPS:
${config.verificationCommands.map((cmd, i) => ` ${i + 1}. ${cmd}`).join('\n')}
ERROR:
${error.message}
STACK TRACE:
${error.stack}
`;
}
}
//# sourceMappingURL=isolatedVerifier.js.map