maia-cli
Version:
Command-line interface for MAIA (Modern AI Assistant)
176 lines (155 loc) ⢠5.92 kB
JavaScript
/**
* 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);
}
});