jay-code
Version:
Streamlined AI CLI orchestration engine with mathematical rigor and enterprise-grade reliability
136 lines (117 loc) • 3.85 kB
JavaScript
import os from 'node:os';
import path from 'node:path';
import fs from 'node:fs';
import { spawn, exec } from 'node:child_process';
import { promisify } from 'util';
const execAsync = promisify(exec);
console.log('Jay-Code Uninstall: Removing Jay-Code while preserving system components');
async function removeJayCodePackage() {
console.log('Removing Jay-Code npm package...');
try {
await execAsync('npm uninstall -g jay-code');
console.log('Global package removed');
return true;
} catch (globalError) {
try {
await execAsync('npm uninstall jay-code');
console.log('Local package removed');
return true;
} catch (localError) {
console.log('Package removal failed, may not be installed');
return false;
}
}
}
async function removeConfiguration() {
const configDir = path.join(os.homedir(), '.jay-code');
try {
if (fs.existsSync(configDir)) {
console.log('Removing Jay-Code configuration...');
await fs.promises.rm(configDir, { recursive: true, force: true });
console.log('Configuration directory removed:', configDir);
return true;
} else {
console.log('Configuration directory not found');
return true;
}
} catch (error) {
console.error('Failed to remove configuration:', error.message);
return false;
}
}
async function removeBinaryLinks() {
const binPaths = [
'/usr/local/bin/jay-code',
'/usr/bin/jay-code',
path.join(os.homedir(), '.npm-global/bin/jay-code'),
path.join(os.homedir(), '.local/bin/jay-code')
];
for (const binPath of binPaths) {
try {
if (fs.existsSync(binPath)) {
await fs.promises.unlink(binPath);
console.log('Removed binary:', binPath);
}
} catch (error) {
// Silently continue if can't remove
}
}
}
async function cleanupEnvironment() {
console.log('Checking environment cleanup...');
// Check for shell configuration files that might reference jay-code
const shellFiles = [
path.join(os.homedir(), '.bashrc'),
path.join(os.homedir(), '.zshrc'),
path.join(os.homedir(), '.profile')
];
for (const shellFile of shellFiles) {
try {
if (fs.existsSync(shellFile)) {
const content = await fs.promises.readFile(shellFile, 'utf8');
if (content.includes('jay-code')) {
console.log(`Found jay-code references in ${shellFile}`);
console.log('Please manually remove any jay-code PATH additions');
}
}
} catch (error) {
// Continue silently
}
}
}
async function main() {
console.log('\n=== Jay-Code Clean Uninstall ===\n');
console.log('This will remove:');
console.log('- Jay-Code npm package');
console.log('- Jay-Code configuration files');
console.log('- Jay-Code binary links');
console.log('\nThis will NOT remove:');
console.log('- Ollama installation');
console.log('- Downloaded models');
console.log('- System dependencies');
const results = {
package: await removeJayCodePackage(),
config: await removeConfiguration(),
binaries: true
};
await removeBinaryLinks();
await cleanupEnvironment();
console.log('\n=== Uninstall Summary ===');
Object.entries(results).forEach(([step, success]) => {
const status = success ? 'SUCCESS' : 'FAILED';
console.log(`${step}: ${status}`);
});
const overallSuccess = Object.values(results).every(Boolean);
if (overallSuccess) {
console.log('\nJay-Code successfully removed from system');
console.log('Ollama and models preserved for other applications');
} else {
console.log('\nUninstall completed with some issues');
console.log('Manual cleanup may be required');
}
}
main().catch(error => {
console.error('Uninstall failed:', error.message);
process.exit(1);
});