mira-consciousness
Version:
Memory & Intelligence Retention Archive - Preserving The Spark
155 lines ⢠7.77 kB
JavaScript
import { Command } from 'commander';
import chalk from 'chalk';
import ora from 'ora';
import { getDirectPythonInterface } from '../core/DirectPythonInterface.js';
import inquirer from 'inquirer';
export function createJourneyCommand() {
return new Command('journey')
.description('Search and explore development journey using semantic memory')
.option('-b, --build', 'Build journey memory from all stored memories')
.option('-i, --interactive', 'Interactive journey exploration')
.option('-q, --query <query>', 'Search journey with specific query')
.option('-l, --limit <number>', 'Maximum results to return', '5')
.action(async (options) => {
const pythonInterface = getDirectPythonInterface();
if (options.build) {
// Build journey memory
console.log(chalk.cyan('\nš„ Building Development Journey Memory\n'));
const spinner = ora('Encoding development journey into semantic video memory...').start();
try {
const result = await pythonInterface.buildJourney();
if (result.success) {
spinner.succeed('Journey memory built successfully');
console.log(chalk.green('\nā
Your development journey is now searchable!'));
console.log(chalk.gray('Use "mira journey -q <query>" to search'));
}
else {
throw new Error(result.error || 'Failed to build journey memory');
}
}
catch (error) {
spinner.fail('Failed to build journey memory');
console.error(chalk.red(`Error: ${error instanceof Error ? error.message : String(error)}`));
process.exit(1);
}
}
else if (options.interactive) {
// Interactive journey exploration
console.log(chalk.cyan('\nš Interactive Journey Explorer\n'));
console.log(chalk.gray('Explore your development journey through natural language queries'));
console.log(chalk.gray('Type "exit" to quit\n'));
while (true) {
const { query } = await inquirer.prompt([
{
type: 'input',
name: 'query',
message: chalk.blue('Journey search:'),
validate: (input) => input.trim() !== '' || 'Please enter a search query'
}
]);
if (query.toLowerCase() === 'exit') {
console.log(chalk.gray('\nExiting journey explorer...'));
break;
}
const spinner = ora('Searching journey memory...').start();
try {
const result = await pythonInterface.searchJourney(query, parseInt(options.limit));
spinner.stop();
if (result.success && result.data) {
displayJourneyResults(result.data);
}
else {
console.log(chalk.yellow('No results found for your query'));
}
}
catch (error) {
spinner.fail('Search failed');
console.error(chalk.red(`Error: ${error instanceof Error ? error.message : String(error)}`));
}
console.log(); // Add spacing between searches
}
}
else if (options.query) {
// Single query search
const spinner = ora('Searching journey memory...').start();
try {
const result = await pythonInterface.searchJourney(options.query, parseInt(options.limit));
spinner.stop();
if (result.success && result.data) {
console.log(chalk.cyan(`\nš Journey Search Results for "${options.query}"\n`));
displayJourneyResults(result.data);
}
else {
console.log(chalk.yellow('\nNo results found for your query'));
console.log(chalk.gray('Try different keywords or build the journey memory first'));
}
}
catch (error) {
spinner.fail('Search failed');
console.error(chalk.red(`Error: ${error instanceof Error ? error.message : String(error)}`));
if (error instanceof Error && error.message.includes('not built yet')) {
console.log(chalk.yellow('\nš” Run "mira journey --build" first to create the journey memory'));
}
process.exit(1);
}
}
else {
// Show journey status
console.log(chalk.cyan('\nš Development Journey Status\n'));
const spinner = ora('Checking journey memory...').start();
try {
const result = await pythonInterface.getJourneyStatus();
spinner.stop();
if (result.success && result.data) {
const status = result.data;
if (status.built) {
console.log(chalk.green('ā
Journey memory is built and ready'));
console.log(chalk.gray(`š
Last updated: ${status.lastUpdated || 'Unknown'}`));
console.log(chalk.gray(`š Total memories: ${status.memoryCount || 0}`));
console.log(chalk.gray(`š¬ Video size: ${status.videoSize || 'Unknown'}`));
console.log(chalk.cyan('\nš Available commands:'));
console.log(chalk.gray(' ⢠mira journey -q "when did we implement auth?"'));
console.log(chalk.gray(' ⢠mira journey -i (interactive exploration)'));
console.log(chalk.gray(' ⢠mira journey -b (rebuild journey memory)'));
}
else {
console.log(chalk.yellow('ā ļø Journey memory not built yet'));
console.log(chalk.gray('\nRun "mira journey --build" to create it'));
}
}
else {
console.log(chalk.yellow('Unable to check journey status'));
}
}
catch (error) {
spinner.fail('Failed to check journey status');
console.error(chalk.red(`Error: ${error instanceof Error ? error.message : String(error)}`));
}
}
});
}
function displayJourneyResults(results) {
if (!results || results.length === 0) {
console.log(chalk.yellow('No results found'));
return;
}
results.forEach((result, index) => {
console.log(chalk.cyan(`\n[${index + 1}] ${result.title || 'Memory'}`));
console.log(chalk.gray(`š
${result.timestamp || 'Unknown time'}`));
if (result.score) {
const scoreBar = 'ā'.repeat(Math.round(result.score * 10));
console.log(chalk.gray(`š Relevance: ${scoreBar} ${(result.score * 100).toFixed(1)}%`));
}
console.log(chalk.white(`\n${result.content || result.text || 'No content'}`));
if (result.metadata) {
console.log(chalk.gray('\nš Metadata:'));
Object.entries(result.metadata).forEach(([key, value]) => {
if (key !== 'embedding' && value) {
console.log(chalk.gray(` ⢠${key}: ${value}`));
}
});
}
console.log(chalk.gray('ā'.repeat(60)));
});
}
//# sourceMappingURL=journey.js.map