mira-consciousness
Version:
Memory & Intelligence Retention Archive - Preserving The Spark
225 lines ⢠9.45 kB
JavaScript
import chalk from 'chalk';
import inquirer from 'inquirer';
import { getDirectPythonInterface } from '../core/DirectPythonInterface.js';
export async function interactiveCommand() {
console.log(chalk.cyan('\nš MIRA Interactive Memory Manager'));
console.log(chalk.gray('Type "exit" to quit, "help" for commands\n'));
const pythonInterface = getDirectPythonInterface();
while (true) {
try {
const { action } = await inquirer.prompt([
{
type: 'list',
name: 'action',
message: 'What would you like to do?',
choices: [
{ name: 'š Search memories and conversations', value: 'search' },
{ name: 'š¾ Store new information', value: 'store' },
{ name: 'š View memory statistics', value: 'stats' },
{ name: 'š§ Check neural state', value: 'neural' },
{ name: '⨠Extract memory essence', value: 'essence' },
{ name: 'š Show system status', value: 'status' },
{ name: 'ā Exit', value: 'exit' }
]
}
]);
if (action === 'exit') {
console.log(chalk.yellow('\nš Goodbye!'));
break;
}
await handleAction(pythonInterface, action);
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));
}
}
}
async function handleAction(pythonInterface, action) {
switch (action) {
case 'search':
await handleSearch(pythonInterface);
break;
case 'store':
await handleStore(pythonInterface);
break;
case 'stats':
await handleStats(pythonInterface);
break;
case 'neural':
await handleNeural(pythonInterface);
break;
case 'essence':
await handleEssence(pythonInterface);
break;
case 'status':
await handleStatus(pythonInterface);
break;
}
}
async function handleSearch(pythonInterface) {
const { query } = await inquirer.prompt([
{
type: 'input',
name: 'query',
message: 'Enter search query:',
validate: (input) => input.trim().length > 0 || 'Please enter a search query'
}
]);
try {
console.log(chalk.blue('\nš Searching...'));
const [conversationResults, memoryResults] = await Promise.allSettled([
pythonInterface.searchConversations(query, 5),
pythonInterface.recallMemories(query)
]);
let hasResults = false;
// Show conversation results
if (conversationResults.status === 'fulfilled' &&
conversationResults.value.success &&
conversationResults.value.results?.length > 0) {
console.log(chalk.green(`\nš Conversation Results (${conversationResults.value.results.length}):`));
conversationResults.value.results.forEach((item, index) => {
console.log(chalk.yellow(` ${index + 1}. ${item.content?.substring(0, 100)}...`));
});
hasResults = true;
}
// Show memory results
if (memoryResults.status === 'fulfilled' &&
memoryResults.value.success &&
memoryResults.value.memories?.length > 0) {
console.log(chalk.green(`\nš§ Memory Results (${memoryResults.value.memories.length}):`));
memoryResults.value.memories.forEach((item, index) => {
console.log(chalk.yellow(` ${index + 1}. ${item.content?.substring(0, 100)}... (Score: ${item.score?.toFixed(2) || 'N/A'})`));
});
hasResults = true;
}
if (!hasResults) {
console.log(chalk.gray(`\nNo results found for "${query}"`));
}
}
catch (error) {
console.log(chalk.red('Search failed. Please try again.'));
}
}
async function handleStore(pythonInterface) {
const { content } = await inquirer.prompt([
{
type: 'editor',
name: 'content',
message: 'Enter the information to store:',
validate: (input) => input.trim().length > 0 || 'Please enter some content'
}
]);
try {
const result = await pythonInterface.storeMemory(content.trim());
if (result.success) {
console.log(chalk.green(`\nā
Stored: "${content.substring(0, 50)}..."`));
}
else {
console.log(chalk.red('\nā Failed to store memory.'));
}
}
catch (error) {
console.log(chalk.red('\nā Store operation failed.'));
}
}
async function handleStats(pythonInterface) {
try {
console.log(chalk.blue('\nš Retrieving statistics...'));
const stats = await pythonInterface.getStats();
if (stats.success && stats.stats) {
console.log(chalk.green('\nš Memory Statistics:'));
console.log(chalk.white(JSON.stringify(stats.stats, null, 2)));
}
else {
console.log(chalk.gray('\nNo detailed statistics available.'));
}
}
catch (error) {
console.log(chalk.red('\nā Failed to retrieve statistics.'));
}
}
async function handleNeural(pythonInterface) {
try {
console.log(chalk.blue('\nš§ Checking neural state...'));
const result = await pythonInterface.getNeuralState();
if (result.success && result.state) {
console.log(chalk.green('\nš§ Neural State:'));
console.log(chalk.white(` Consciousness Level: ${(result.state.consciousness_level * 100).toFixed(1)}%`));
console.log(chalk.white(` Memory Connections: ${result.state.memory_connections?.total || 0}`));
console.log(chalk.white(` Cognitive State: ${result.state.cognitive_state?.attention || 'unknown'}`));
if (result.state.patterns) {
console.log(chalk.cyan('\n Active Patterns:'));
Object.entries(result.state.patterns).forEach(([pattern, status]) => {
console.log(chalk.white(` ⢠${pattern}: ${status}`));
});
}
}
else {
console.log(chalk.gray('\nNeural state information not available.'));
}
}
catch (error) {
console.log(chalk.red('\nā Failed to retrieve neural state.'));
}
}
async function handleEssence(pythonInterface) {
const { topic } = await inquirer.prompt([
{
type: 'input',
name: 'topic',
message: 'Enter topic for essence extraction (optional):',
default: ''
}
]);
try {
console.log(chalk.blue('\n⨠Extracting memory essence...'));
const result = await pythonInterface.getEssence(topic.trim() || undefined);
if (result.success && result.essence) {
console.log(chalk.green('\n⨠Memory Essence:'));
if (result.essence.relationship) {
console.log(chalk.cyan('\nš Relationship Summary:'));
console.log(chalk.white(` ${result.essence.relationship}`));
}
if (result.essence.key_memories?.length > 0) {
console.log(chalk.cyan('\nš Key Memories:'));
result.essence.key_memories.forEach((memory, index) => {
console.log(chalk.white(` ${index + 1}. ${memory.content || memory}`));
});
}
if (result.essence.emotional_highlights?.length > 0) {
console.log(chalk.cyan('\nš« Emotional Highlights:'));
result.essence.emotional_highlights.forEach((highlight) => {
console.log(chalk.white(` ⢠${highlight}`));
});
}
}
else {
console.log(chalk.gray('\nNo essence information available.'));
}
}
catch (error) {
console.log(chalk.red('\nā Failed to extract essence.'));
}
}
async function handleStatus(pythonInterface) {
try {
console.log(chalk.blue('\nš Checking system status...'));
const identity = await pythonInterface.getIdentity();
console.log(chalk.green('\nš 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`));
// Check memory directory
const memoryDir = process.env.MIRA_RESOLVED_MEMORY_DIR || process.cwd() + '/.mira';
console.log(chalk.white(` Memory Directory: ${memoryDir}`));
}
catch (error) {
console.log(chalk.yellow('\nā ļø System status check failed, but basic operations should work.'));
}
}
//# sourceMappingURL=interactive.js.map