sophia-code
Version:
Production-ready agentic CLI code editor with AI-powered coding assistance, planning, and multi-agent delegation. Enterprise-grade security and reliability.
113 lines (94 loc) • 3.75 kB
JavaScript
/**
* Manual Python setup script for sophia-code
* Can be run manually if postinstall fails
*/
const { spawn } = require('child_process');
const fs = require('fs');
const path = require('path');
const chalk = require('chalk');
const ora = require('ora');
const packageRoot = process.cwd();
const setupScript = process.platform === 'win32' ? 'setup.bat' : './setup.sh';
console.log(chalk.blue('🐍 Manual Python Environment Setup'));
console.log(chalk.blue('==================================='));
// Check if setup script exists
if (!fs.existsSync(path.join(packageRoot, 'setup.sh'))) {
console.error(chalk.red('❌ Error: setup.sh not found in current directory.'));
console.log(chalk.yellow('💡 Make sure you are in the sophia-code package directory.'));
console.log(chalk.gray(' Usually: cd node_modules/sophia-code'));
process.exit(1);
}
// Check if Python is available
const pythonCheck = spawn('python3', ['--version'], { stdio: 'pipe' });
pythonCheck.on('close', (code) => {
if (code !== 0) {
console.error(chalk.red('❌ Error: Python 3 not found.'));
console.log(chalk.yellow('💡 Please install Python 3.9+ from: https://python.org/downloads/'));
process.exit(1);
}
runSetup();
});
pythonCheck.on('error', (error) => {
console.error(chalk.red('❌ Error: Python 3 not found.'));
console.log(chalk.yellow('💡 Please install Python 3.9+ from: https://python.org/downloads/'));
process.exit(1);
});
function runSetup() {
const spinner = ora('Setting up Python virtual environment...').start();
const setupProcess = spawn(setupScript, [], {
cwd: packageRoot,
stdio: 'pipe',
shell: true
});
let output = '';
let errorOutput = '';
setupProcess.stdout.on('data', (data) => {
const text = data.toString();
output += text;
// Show important messages
if (text.includes('✅') || text.includes('⬆️') || text.includes('📦')) {
spinner.text = text.trim();
}
});
setupProcess.stderr.on('data', (data) => {
errorOutput += data.toString();
});
setupProcess.on('close', (code) => {
if (code === 0) {
spinner.succeed('Python environment setup complete!');
console.log('');
console.log(chalk.green('🎉 Setup successful!'));
console.log('');
console.log(chalk.cyan('You can now use:'));
console.log(chalk.white(' sophia --help # Show help'));
console.log(chalk.white(' sophia --version # Show version'));
console.log(chalk.white(' sophia # Start interactive mode'));
console.log('');
console.log(chalk.yellow('⚠️ Don\'t forget to set your GROQ_API_KEY:'));
console.log(chalk.white(' export GROQ_API_KEY="your_api_key_here"'));
console.log(chalk.gray(' Get your key from: https://console.groq.com/'));
} else {
spinner.fail('Setup failed');
console.log('');
console.error(chalk.red('❌ Setup failed with exit code:', code));
if (errorOutput) {
console.log('');
console.log(chalk.yellow('Error details:'));
console.log(errorOutput);
}
console.log('');
console.log(chalk.cyan('💡 Common solutions:'));
console.log(chalk.white(' - Make sure Python 3.9+ is installed'));
console.log(chalk.white(' - Check if you have write permissions'));
console.log(chalk.white(' - Try running with sudo (Linux/macOS)'));
console.log(chalk.white(' - Check your internet connection'));
process.exit(1);
}
});
setupProcess.on('error', (error) => {
spinner.fail('Failed to run setup script');
console.error(chalk.red('❌ Error:', error.message));
process.exit(1);
});
}