mira-consciousness
Version:
Memory & Intelligence Retention Archive - Preserving The Spark
98 lines (86 loc) • 4.7 kB
JavaScript
import chalk from 'chalk';
import ora from 'ora';
import { getDirectPythonInterface } from '../core/DirectPythonInterface.js';
export async function aiChatCommand(message) {
console.log(chalk.cyan('\n🤖 MIRA AI Assistant\n'));
const spinner = ora('Processing your message...').start();
try {
const pythonInterface = getDirectPythonInterface();
// Try to get relevant memories first
const memoryResult = await pythonInterface.recallMemories(message);
// Generate a response based on available context
let response = generateResponse(message, memoryResult);
spinner.succeed(chalk.green('Response generated'));
console.log(chalk.white('\n💬 Response:'));
console.log(chalk.gray('─'.repeat(50)));
console.log(chalk.white(response));
// Store the interaction
await pythonInterface.storeMemory(`User asked: "${message}" | AI responded: "${response}"`);
console.log(chalk.gray('\n💾 Interaction stored in memory for future reference'));
}
catch (error) {
spinner.fail('Failed to process message');
console.error(chalk.red('Error:'), error instanceof Error ? error.message : String(error));
// Fallback response
console.log(chalk.yellow('\n🔄 Fallback Response:'));
console.log(chalk.white(generateFallbackResponse(message)));
}
}
function generateResponse(message, memoryResult) {
const memories = memoryResult?.memories || [];
const lowerMessage = message.toLowerCase();
// Context-aware responses based on message content
if (lowerMessage.includes('help') || lowerMessage.includes('how')) {
return `I can help you with MIRA commands and memory management. Based on your message "${message}", here are some suggestions:
• Use "mira search <query>" to find relevant information
• Use "mira store <content>" to save important information
• Use "mira quick" for a health check
• Use "mira analyze" for project analysis
${memories.length > 0 ? `\nI found ${memories.length} related memories that might be helpful.` : ''}`;
}
if (lowerMessage.includes('memory') || lowerMessage.includes('remember')) {
return `Memory management is one of my core capabilities. ${memories.length > 0 ? `I found ${memories.length} related memories.` : 'No specific memories found for this query, but I can help you store new information.'}
I can help you:
• Store new memories with "mira store"
• Search existing memories with "mira search"
• View memory essence with "mira essence"
• Check neural state with "mira neural"`;
}
if (lowerMessage.includes('analyze') || lowerMessage.includes('code')) {
return `I can help analyze your code and project. Here's what I can do:
• Run security analysis to find vulnerabilities
• Check performance issues and optimization opportunities
• Analyze documentation coverage
• Review dependencies for problems
Try "mira analyze" for a comprehensive analysis or "mira quick" for a fast check.`;
}
if (lowerMessage.includes('search') || lowerMessage.includes('find')) {
return `I can help you search through your conversation history and stored memories. ${memories.length > 0 ? `I found ${memories.length} items related to your query.` : ''}
Use these commands:
• "mira search <query>" - Search conversations
• "mira journey search <query>" - Search development journey
• "mira essence <topic>" - Get memory essence for a topic`;
}
// General response with memory context
return `I understand you're asking about: "${message}"
${memories.length > 0 ?
`I found ${memories.length} related memories that might be relevant to your question.` :
'I don\'t have specific memories related to this topic, but I can help you explore it further.'}
I'm MIRA, your Memory & Intelligence Retention Archive. I can help with:
• Code analysis and security scanning
• Memory storage and retrieval
• Project health checks
• Development assistance
What would you like to explore?`;
}
function generateFallbackResponse(message) {
return `I apologize, but I'm having trouble accessing my full capabilities right now. However, I can still help you with basic MIRA commands.
Your message: "${message}"
Try these commands:
• mira help - Show all available commands
• mira quick - Quick system health check
• mira search "${message}" - Search for relevant information
• mira store "Follow-up on: ${message}" - Store this for later
I'm designed to learn and remember our interactions, so feel free to ask me anything about your development work!`;
}
//# sourceMappingURL=ai-chat.js.map