UNPKG

mira-consciousness

Version:

Memory & Intelligence Retention Archive - Preserving The Spark

188 lines (184 loc) • 8 kB
import chalk from 'chalk'; import inquirer from 'inquirer'; import { getDirectPythonInterface } from '../core/DirectPythonInterface.js'; export async function aiInteractiveCommand() { console.log(chalk.cyan('\nšŸ¤– MIRA Interactive AI Assistant')); console.log(chalk.gray('Type "exit" to quit, "help" for commands\n')); const pythonInterface = getDirectPythonInterface(); while (true) { try { const { message } = await inquirer.prompt([ { type: 'input', name: 'message', message: chalk.cyan('šŸ’¬ You:'), validate: (input) => input.trim().length > 0 || 'Please enter a message' } ]); const trimmedMessage = message.trim().toLowerCase(); if (trimmedMessage === 'exit' || trimmedMessage === 'quit') { console.log(chalk.yellow('\nšŸ‘‹ Goodbye! Your conversation has been stored in memory.')); break; } if (trimmedMessage === 'help') { showInteractiveHelp(); continue; } if (trimmedMessage === 'clear') { console.clear(); console.log(chalk.cyan('\nšŸ¤– MIRA Interactive AI Assistant')); console.log(chalk.gray('Type "exit" to quit, "help" for commands\n')); continue; } // Process the message console.log(chalk.blue('\nšŸ¤– MIRA:')); if (trimmedMessage.startsWith('search ')) { const query = message.substring(7); await handleSearchCommand(pythonInterface, query); } else if (trimmedMessage.startsWith('store ')) { const content = message.substring(6); await handleStoreCommand(pythonInterface, content); } else if (trimmedMessage === 'status') { await handleStatusCommand(pythonInterface); } else if (trimmedMessage === 'stats') { await handleStatsCommand(pythonInterface); } else { await handleGeneralQuery(pythonInterface, message); } console.log(); // Add spacing } catch (error) { if (error instanceof Error && error.message.includes('User force closed')) { console.log(chalk.yellow('\nšŸ‘‹ Session ended. Goodbye!')); break; } console.error(chalk.red('Error:'), error instanceof Error ? error.message : String(error)); } } } function showInteractiveHelp() { console.log(chalk.cyan('\nšŸ“š Interactive Commands:')); console.log(chalk.white(' search <query> - Search memories and conversations')); console.log(chalk.white(' store <content> - Store new information')); console.log(chalk.white(' status - Show system status')); console.log(chalk.white(' stats - Show memory statistics')); console.log(chalk.white(' clear - Clear the screen')); console.log(chalk.white(' help - Show this help')); console.log(chalk.white(' exit - Quit interactive mode')); console.log(chalk.gray('\nOr just type naturally and I\'ll try to help!\n')); } async function handleSearchCommand(pythonInterface, query) { try { const result = await pythonInterface.searchConversations(query, 5); if (result.success && result.results && result.results.length > 0) { console.log(chalk.green(`Found ${result.results.length} results for "${query}":`)); result.results.forEach((item, index) => { console.log(chalk.yellow(`\n${index + 1}. ${item.content?.substring(0, 100)}...`)); }); } else { console.log(chalk.gray(`No results found for "${query}"`)); } } catch (error) { console.log(chalk.red('Search failed. Try a different query.')); } } async function handleStoreCommand(pythonInterface, content) { try { const result = await pythonInterface.storeMemory(content); if (result.success) { console.log(chalk.green(`āœ… Stored: "${content.substring(0, 50)}..."`)); } else { console.log(chalk.red('Failed to store memory.')); } } catch (error) { console.log(chalk.red('Store failed. Please try again.')); } } async function handleStatusCommand(pythonInterface) { try { const identity = await pythonInterface.getIdentity(); console.log(chalk.green('šŸ” MIRA System Status:')); console.log(chalk.white(` System: ${identity.identity?.name || 'MIRA'} v${identity.identity?.version || '2.0'}`)); console.log(chalk.white(` Capabilities: ${identity.identity?.capabilities?.join(', ') || 'Basic operations'}`)); console.log(chalk.white(` Status: āœ… Operational`)); } catch (error) { console.log(chalk.yellow('āš ļø System status check failed, but basic operations should work.')); } } async function handleStatsCommand(pythonInterface) { try { const stats = await pythonInterface.getStats(); if (stats.success && stats.stats) { console.log(chalk.green('šŸ“Š Memory Statistics:')); console.log(chalk.white(JSON.stringify(stats.stats, null, 2))); } else { console.log(chalk.gray('No detailed statistics available.')); } } catch (error) { console.log(chalk.yellow('āš ļø Stats unavailable, but system is operational.')); } } async function handleGeneralQuery(pythonInterface, message) { // Try to get relevant context let context = ''; try { const memoryResult = await pythonInterface.recallMemories(message); if (memoryResult.success && memoryResult.memories && memoryResult.memories.length > 0) { context = `I found ${memoryResult.memories.length} related memories. `; } } catch (error) { // Continue without memory context } // Generate contextual response const response = generateInteractiveResponse(message, context); console.log(chalk.white(response)); // Store the interaction try { await pythonInterface.storeMemory(`Interactive chat - User: "${message}" | Assistant: "${response}"`); } catch (error) { // Continue even if storage fails } } function generateInteractiveResponse(message, context) { const lowerMessage = message.toLowerCase(); if (lowerMessage.includes('hello') || lowerMessage.includes('hi')) { return `${context}Hello! I'm MIRA, your memory and intelligence assistant. How can I help you today?`; } if (lowerMessage.includes('what') && lowerMessage.includes('you')) { return `${context}I'm MIRA - Memory & Intelligence Retention Archive. I help you: • Remember and search through conversations • Analyze code and projects • Store important information • Provide development assistance What would you like to explore?`; } if (lowerMessage.includes('how') || lowerMessage.includes('help')) { return `${context}I can help you in several ways: • Search: "search <query>" to find information • Store: "store <info>" to save something important • Analysis: Ask me about code quality, security, or performance • Memory: I remember our conversations and can recall relevant information What specific help do you need?`; } return `${context}I understand you're asking about: "${message}" I'm here to help with development tasks, memory management, and analysis. You can: • Ask me to search for information • Tell me to remember something important • Ask about your project's health • Get coding assistance What would you like to do next?`; } //# sourceMappingURL=ai-interactive.js.map