terminal-jarvis
Version:
AI Coding Tools Wrapper - Unified interface for claude-code, gemini-cli, qwen-code, opencode, llxprt, codex, and crush
169 lines ⢠7.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const child_process_1 = require("child_process");
const fs_1 = require("fs");
const os_1 = require("os");
const path_1 = require("path");
function getBundledBinaryPath() {
const currentPlatform = (0, os_1.platform)();
const currentArch = (0, os_1.arch)();
// Map Node.js platform/arch to our binary naming convention
let binaryName = 'terminal-jarvis';
if (currentPlatform === 'linux') {
binaryName += '-linux';
}
else if (currentPlatform === 'darwin') {
binaryName += '-macos';
}
else if (currentPlatform === 'win32') {
binaryName += '-windows.exe';
}
else {
binaryName += '-linux'; // fallback
}
if (currentPlatform !== 'win32') {
if (currentArch === 'x64' || currentArch === 'x86_64') {
binaryName += '-x64';
}
else if (currentArch === 'arm64') {
binaryName += '-arm64';
}
else {
binaryName += '-x64'; // fallback
}
}
return (0, path_1.join)(__dirname, '..', 'bin', binaryName);
}
// Try to find the Rust binary in common locations
const possibleBinaries = [
(0, path_1.join)(__dirname, '..', 'bin', 'terminal-jarvis'), // Bundled binary (generic)
(0, path_1.join)(__dirname, '..', 'bin', 'terminal-jarvis-linux-x64'), // Bundled binary (platform-specific)
(0, path_1.join)(__dirname, '..', '..', '..', 'target', 'debug', 'terminal-jarvis'), // Local debug build
(0, path_1.join)(__dirname, '..', '..', '..', 'target', 'release', 'terminal-jarvis'), // Local release build
(0, path_1.join)(process.env.HOME || '', '.cargo', 'bin', 'terminal-jarvis'), // Cargo home
'/usr/local/bin/terminal-jarvis', // System install
];
async function findRustBinary() {
// First check local build and other possible locations
for (const path of possibleBinaries) {
if ((0, fs_1.existsSync)(path)) {
return path;
}
}
// Then check if terminal-jarvis is available in PATH
return new Promise((resolve) => {
const child = (0, child_process_1.spawn)('which', ['terminal-jarvis'], { stdio: 'pipe' });
let output = '';
child.stdout.on('data', (data) => {
output += data.toString();
});
child.on('close', (code) => {
if (code === 0 && output.trim()) {
const binaryPath = output.trim();
// Simple check: if it's not in node_modules and exists, assume it's the Rust binary
if (!binaryPath.includes('node_modules') && !binaryPath.includes('.npm') && (0, fs_1.existsSync)(binaryPath)) {
resolve(binaryPath);
}
else {
resolve(null);
}
}
else {
resolve(null);
}
});
child.on('error', () => resolve(null));
});
}
async function main() {
const rustBinary = await findRustBinary();
if (rustBinary) {
// Run the Rust binary with all arguments
const child = (0, child_process_1.spawn)(rustBinary, process.argv.slice(2), {
stdio: 'inherit',
cwd: process.cwd()
});
// Add a reasonable timeout to prevent indefinite hanging
const timeout = setTimeout(() => {
console.log('\nā ļø T.JARVIS process timed out after 60 seconds');
console.log(' This usually happens with long-running interactive tools.');
console.log('');
console.log('š” If this was intentional:');
console.log(' ⢠The tool might still be running in the background');
console.log(' ⢠Use Ctrl+C next time to stop manually');
console.log(' ⢠Some AI tools take time to initialize');
console.log('');
child.kill('SIGTERM');
process.exit(1);
}, 60000); // 60 second timeout
child.on('close', (code) => {
clearTimeout(timeout);
process.exit(code || 0);
});
child.on('error', (err) => {
clearTimeout(timeout);
console.error('\nā Error running terminal-jarvis binary:');
console.error(' ' + err.message);
console.error('');
// Provide specific error context
if (err.message.includes('ENOENT')) {
console.error('š Binary not found or not executable.');
console.error(' This usually means the binary is missing or has wrong permissions.');
}
else if (err.message.includes('EACCES')) {
console.error('š Permission denied.');
console.error(' The binary exists but cannot be executed.');
console.error(' š” Try: chmod +x ' + rustBinary);
}
else if (err.message.includes('spawn')) {
console.error('š« Failed to spawn process.');
console.error(' This might be a system-level issue.');
}
console.error('');
showFallbackMessage();
});
}
else {
showFallbackMessage();
}
}
function showFallbackMessage() {
console.log("Terminal Jarvis v0.0.55");
console.log("");
console.log("ā Error: Could not find or execute the T.JARVIS binary.");
console.log("");
console.log("š Debug: Searched for binary in:");
console.log(" ⢠Bundled binary (bin/terminal-jarvis)");
console.log(" ⢠Local builds (target/debug, target/release)");
console.log(" ⢠~/.cargo/bin/terminal-jarvis");
console.log(" ⢠/usr/local/bin/terminal-jarvis");
console.log(" ⢠PATH (excluding node_modules)");
console.log("");
console.log("ļæ½ This should not happen! The binary should be bundled with this package.");
console.log("");
console.log("š§ Quick Fix (try these in order):");
console.log(" 1. npm uninstall -g terminal-jarvis");
console.log(" 2. npm cache clean --force");
console.log(" 3. npm install -g terminal-jarvis");
console.log("");
console.log("š Detailed Troubleshooting:");
console.log(" ⢠Check binary exists: ls -la $(npm root -g)/terminal-jarvis/bin/");
console.log(" ⢠Fix permissions: chmod +x $(npm root -g)/terminal-jarvis/bin/*");
console.log(" ⢠Check npm global: npm list -g terminal-jarvis");
console.log(" ⢠Verify Node.js: node --version (need 16+)");
console.log("");
console.log("š Alternative Installation Methods:");
console.log(" ⢠From source: cargo install --git https://github.com/BA-CalderonMorales/terminal-jarvis");
console.log(" ⢠Direct download: Check releases at github.com/BA-CalderonMorales/terminal-jarvis");
console.log("");
console.log("š¬ Need Help?");
console.log(" ⢠Report issue: https://github.com/BA-CalderonMorales/terminal-jarvis/issues");
console.log(" ⢠Include output of: npm --version && node --version && npm list -g terminal-jarvis");
process.exit(1);
}
main().catch((err) => {
console.error('Unexpected error:', err);
process.exit(1);
});
//# sourceMappingURL=index.js.map