UNPKG

maia-cli

Version:

Command-line interface for MAIA (Modern AI Assistant)

176 lines (155 loc) • 5.92 kB
/** * MAIA Config Command - Manage configuration */ import { Command } from 'commander'; import chalk from 'chalk'; import { ConfigManager } from 'maia-core'; export const configCommand = new Command('config') .description('Manage MAIA configuration'); // Show configuration configCommand .command('show') .description('Show current configuration') .option('--json', 'output as JSON') .action(async (options) => { try { const configManager = new ConfigManager(); if (!configManager.exists()) { console.log(chalk.red('āŒ MAIA not initialized. Run "maia init" first.')); return; } const config = configManager.load(); if (options.json) { // Hide sensitive data in JSON output const safeConfig = { ...config }; if (safeConfig.ai.claude?.apiKey) { safeConfig.ai.claude.apiKey = '***hidden***'; } if (safeConfig.ai.openai?.apiKey) { safeConfig.ai.openai.apiKey = '***hidden***'; } console.log(JSON.stringify(safeConfig, null, 2)); } else { console.log(chalk.cyan('šŸ“‹ MAIA Configuration\n')); // AI Provider console.log(chalk.yellow('šŸ¤– AI Provider:')); console.log(` Provider: ${config.ai.provider}`); console.log(` Model: ${config.ai[config.ai.provider]?.model || 'default'}`); console.log(` API Key: ${config.ai[config.ai.provider]?.apiKey ? 'āœ… Set' : 'āŒ Not set'}`); // User console.log(chalk.yellow('\nšŸ‘¤ User:')); console.log(` Name: ${config.user.name || 'Not set'}`); console.log(` ID: ${config.user.id}`); // Tools console.log(chalk.yellow('\nšŸ”§ Tools:')); if (config.tools.enabled.length > 0) { config.tools.enabled.forEach(tool => { console.log(` āœ… ${tool}`); }); } else { console.log(' No tools enabled'); } // Voice console.log(chalk.yellow('\nšŸŽ¤ Voice:')); console.log(` Enabled: ${config.voice?.enabled ? 'āœ… Yes' : 'āŒ No'}`); if (config.voice?.enabled) { console.log(` TTS: ${config.voice.tts?.apiKey ? 'āœ… Configured' : 'āŒ Not configured'}`); console.log(` STT: ${config.voice.stt?.apiKey ? 'āœ… Configured' : 'āŒ Not configured'}`); } console.log(chalk.gray(`\nConfig file: ${configManager.getConfigPath()}`)); } } catch (error) { console.error(chalk.red('āŒ Failed to show configuration:'), error.message); } }); // Set configuration value configCommand .command('set <key> <value>') .description('Set configuration value') .action(async (key, value) => { try { const configManager = new ConfigManager(); if (!configManager.exists()) { console.log(chalk.red('āŒ MAIA not initialized. Run "maia init" first.')); return; } // Parse value (try to convert to appropriate type) let parsedValue = value; if (value === 'true') parsedValue = true; else if (value === 'false') parsedValue = false; else if (!isNaN(value) && !isNaN(parseFloat(value))) parsedValue = parseFloat(value); configManager.set(key, parsedValue); console.log(chalk.green(`āœ… Set ${key} = ${parsedValue}`)); } catch (error) { console.error(chalk.red('āŒ Failed to set configuration:'), error.message); } }); // Get configuration value configCommand .command('get <key>') .description('Get configuration value') .action(async (key) => { try { const configManager = new ConfigManager(); if (!configManager.exists()) { console.log(chalk.red('āŒ MAIA not initialized. Run "maia init" first.')); return; } const value = configManager.get(key); if (value !== undefined) { console.log(value); } else { console.log(chalk.yellow(`āš ļø Key "${key}" not found`)); } } catch (error) { console.error(chalk.red('āŒ Failed to get configuration:'), error.message); } }); // Validate configuration configCommand .command('validate') .description('Validate current configuration') .action(async () => { try { const configManager = new ConfigManager(); if (!configManager.exists()) { console.log(chalk.red('āŒ MAIA not initialized. Run "maia init" first.')); return; } const validation = configManager.validate(); if (validation.valid) { console.log(chalk.green('āœ… Configuration is valid')); } else { console.log(chalk.red('āŒ Configuration validation failed:')); validation.errors.forEach(error => { console.log(chalk.red(` • ${error}`)); }); } } catch (error) { console.error(chalk.red('āŒ Failed to validate configuration:'), error.message); } }); // Reset configuration configCommand .command('reset') .description('Reset configuration to defaults') .option('-f, --force', 'skip confirmation') .action(async (options) => { try { const configManager = new ConfigManager(); if (!configManager.exists()) { console.log(chalk.red('āŒ MAIA not initialized. Run "maia init" first.')); return; } if (!options.force) { console.log(chalk.yellow('āš ļø This will reset all configuration to defaults.')); console.log(chalk.gray('Use --force to skip this confirmation.')); return; } // This would reset to defaults - for now just show message console.log(chalk.yellow('🚧 Reset functionality coming soon!')); console.log(chalk.gray('For now, delete the config file and run "maia init" again.')); } catch (error) { console.error(chalk.red('āŒ Failed to reset configuration:'), error.message); } });