blue-beatle
Version:
š¤ AI-Powered Development Assistant - Intelligent code analysis, problem solving, and terminal automation using Gemini API
304 lines (271 loc) ⢠11.1 kB
JavaScript
/**
* š¤ Blue Beatle - AI-Powered Development Assistant
* Main application entry point
*/
const { program } = require('commander');
const chalk = require('chalk');
const figlet = require('figlet');
const gradient = require('gradient-string');
const boxen = require('boxen');
const pkg = require('../package.json');
// Import core modules
const AIAssistant = require('./ai-assistant');
const CodeAnalyzer = require('./code-analyzer');
const TerminalExecutor = require('./terminal-executor');
const ProjectManager = require('./project-manager');
const ConfigManager = require('./config-manager');
const WorkspaceIntegration = require('./workspace-integration');
const { showBanner, showHelp } = require('./utils/display');
// Version info
const version = pkg.version;
// Initialize core components
let aiAssistant;
let codeAnalyzer;
let terminalExecutor;
let projectManager;
let configManager;
async function initializeComponents() {
try {
configManager = new ConfigManager();
await configManager.initialize();
aiAssistant = new AIAssistant(configManager);
codeAnalyzer = new CodeAnalyzer();
terminalExecutor = new TerminalExecutor();
projectManager = new ProjectManager();
return true;
} catch (error) {
console.error(chalk.red('ā Failed to initialize components:'), error.message);
return false;
}
}
// CLI Configuration
program
.name('blue-beatle')
.description('š¤ AI-Powered Development Assistant with Gemini API')
.version(pkg.version)
.option('-v, --verbose', 'Enable verbose output')
.option('-q, --quiet', 'Suppress non-essential output')
.option('--no-banner', 'Hide the startup banner');
// AI Commands
program
.command('ai <prompt>')
.description('š§ Ask AI assistant to solve coding problems')
.option('-f, --file <file>', 'Analyze specific file')
.option('-d, --directory <dir>', 'Analyze directory')
.option('-c, --context', 'Include full project context')
.option('-e, --execute', 'Execute suggested commands automatically')
.option('-m, --model <model>', 'Specify AI model (gemini-2.0-flash, gemini-1.5-pro)')
.action(async (prompt, options) => {
if (!await initializeComponents()) return;
await aiAssistant.processPrompt(prompt, options);
});
// Code Analysis Commands
program
.command('analyze [path]')
.description('š Analyze codebase for issues and improvements')
.option('-t, --type <type>', 'Analysis type (security, performance, quality, all)', 'all')
.option('-r, --recursive', 'Analyze recursively')
.option('-o, --output <format>', 'Output format (json, table, markdown)', 'table')
.option('--fix', 'Automatically fix detected issues')
.action(async (path, options) => {
if (!await initializeComponents()) return;
await codeAnalyzer.analyze(path || process.cwd(), options);
});
// Terminal Execution Commands
program
.command('exec <command>')
.description('ā” Execute terminal commands with AI assistance')
.option('-i, --interactive', 'Interactive mode with AI suggestions')
.option('-s, --safe', 'Safe mode - confirm before execution')
.option('-l, --log', 'Log all commands and outputs')
.action(async (command, options) => {
if (!await initializeComponents()) return;
await terminalExecutor.execute(command, options);
});
// Project Management Commands
program
.command('project')
.description('š Project management and automation')
.option('-i, --init', 'Initialize new project with AI assistance')
.option('-s, --setup <type>', 'Setup project type (react, node, python, etc.)')
.option('-d, --deploy', 'Deploy project with AI guidance')
.option('-t, --test', 'Run tests with AI analysis')
.action(async (options) => {
if (!await initializeComponents()) return;
await projectManager.manage(options);
});
// Configuration Commands
program
.command('config')
.description('āļø Configure MacAdida settings')
.option('-s, --set <key=value>', 'Set configuration value')
.option('-g, --get <key>', 'Get configuration value')
.option('-l, --list', 'List all configurations')
.option('-r, --reset', 'Reset to default configuration')
.option('--setup-api', 'Setup Gemini API key')
.action(async (options) => {
if (!await initializeComponents()) return;
await configManager.handleCommand(options);
});
// Interactive Mode
program
.command('interactive')
.alias('i')
.description('šÆ Start interactive AI assistant mode')
.option('-m, --mode <mode>', 'Interactive mode (chat, code, terminal)', 'chat')
.action(async (options) => {
if (!await initializeComponents()) return;
await aiAssistant.startInteractiveMode(options);
});
// Agentic AI Agent Mode
program
.command('agent')
.alias('a')
.description('š¤ Start permanent AI agent with workspace integration')
.option('-b, --background', 'Run agent in background')
.option('-w, --workspace <path>', 'Workspace path to monitor', process.cwd())
.action(async (options) => {
console.log(chalk.cyan('š Starting Blue Beatle Agentic AI Agent...'));
const integration = new WorkspaceIntegration();
await integration.initialize();
await integration.startPermanentAgent();
});
// Workspace Integration
program
.command('integrate')
.description('š§ Integrate Blue Beatle into your workspace permanently')
.option('-g, --global', 'Install globally for all projects')
.option('-s, --startup', 'Add to system startup')
.action(async (options) => {
console.log(chalk.cyan('š§ Setting up workspace integration...'));
const integration = new WorkspaceIntegration();
await integration.initialize();
console.log(chalk.green('ā
Blue Beatle is now integrated into your workspace!'));
});
// Watch Mode
program
.command('watch [path]')
.description('š Watch files and provide AI assistance on changes')
.option('-p, --pattern <pattern>', 'File pattern to watch', '**/*.{js,ts,py,java,cpp,c,go,rs}')
.option('-a, --auto-fix', 'Automatically fix issues when detected')
.option('-n, --notify', 'Send notifications for issues')
.action(async (path, options) => {
if (!await initializeComponents()) return;
await codeAnalyzer.watchMode(path || process.cwd(), options);
});
// Learning Mode
program
.command('learn <topic>')
.description('š Learn about development topics with AI tutor')
.option('-l, --level <level>', 'Difficulty level (beginner, intermediate, advanced)', 'intermediate')
.option('-e, --examples', 'Include practical examples')
.option('-q, --quiz', 'Interactive quiz mode')
.action(async (topic, options) => {
if (!await initializeComponents()) return;
await aiAssistant.learnMode(topic, options);
});
// Debug Mode
program
.command('debug [file]')
.description('š Debug code with AI assistance')
.option('-e, --error <error>', 'Specific error message to debug')
.option('-l, --logs <logfile>', 'Analyze log file for issues')
.option('-s, --stack-trace', 'Analyze stack trace')
.action(async (file, options) => {
if (!await initializeComponents()) return;
await aiAssistant.debugMode(file, options);
});
// Performance Analysis
program
.command('perf [path]')
.description('ā” Performance analysis and optimization')
.option('-p, --profile', 'Run performance profiling')
.option('-m, --memory', 'Memory usage analysis')
.option('-b, --benchmark', 'Run benchmarks')
.action(async (path, options) => {
if (!await initializeComponents()) return;
await codeAnalyzer.performanceAnalysis(path || process.cwd(), options);
});
// Security Audit
program
.command('security [path]')
.description('š Security audit and vulnerability detection')
.option('-d, --dependencies', 'Check dependency vulnerabilities')
.option('-c, --code', 'Static code security analysis')
.option('-f, --fix', 'Auto-fix security issues where possible')
.action(async (path, options) => {
if (!await initializeComponents()) return;
await codeAnalyzer.securityAudit(path || process.cwd(), options);
});
// Code Generation
program
.command('generate <type>')
.description('šØ Generate code with AI assistance')
.option('-n, --name <name>', 'Component/function name')
.option('-f, --framework <framework>', 'Target framework')
.option('-l, --language <language>', 'Programming language')
.option('-t, --template <template>', 'Use specific template')
.action(async (type, options) => {
if (!await initializeComponents()) return;
await aiAssistant.generateCode(type, options);
});
// Setup Command
program
.command('setup')
.description('š Initial setup and configuration')
.action(async () => {
showBanner();
if (!await initializeComponents()) return;
await configManager.runSetup();
});
// Handle unknown commands
program.on('command:*', function (operands) {
console.error(chalk.red(`ā Unknown command: ${operands[0]}`));
console.log(chalk.yellow('š” Use --help to see available commands'));
process.exit(1);
});
// Main execution
async function main() {
try {
// Show banner unless disabled
if (!process.argv.includes('--no-banner') && !process.argv.includes('--quiet')) {
showBanner();
}
// If no arguments provided, show help
if (process.argv.length <= 2) {
showHelp();
return;
}
// Parse and execute commands
await program.parseAsync(process.argv);
} catch (error) {
console.error(chalk.red('ā An error occurred:'), error.message);
if (process.argv.includes('--verbose')) {
console.error(error.stack);
}
process.exit(1);
}
}
// Handle process termination
process.on('SIGINT', () => {
console.log(chalk.yellow('\nš Blue Beatle terminated by user'));
process.exit(0);
});
process.on('uncaughtException', (error) => {
console.error(chalk.red('ā Uncaught Exception:'), error.message);
process.exit(1);
});
process.on('unhandledRejection', (reason, promise) => {
console.error(chalk.red('ā Unhandled Rejection at:'), promise, 'reason:', reason);
process.exit(1);
});
// Start the application
main();
module.exports = {
AIAssistant,
CodeAnalyzer,
TerminalExecutor,
ProjectManager,
ConfigManager
};