/* eslint-disable no-console */ import { Command } from 'commander'; import chalk from 'chalk'; import { saveMemory, getMemoryStats } from '../utils/memory-store.js'; import type { MemoryCategory } from '@rigstate/shared'; import { getProjectId } from '../utils/config.js'; // ───────────────────────────────────────────────────────────────────────────── // rigstate remember "" // Saves a memory to the local .rigstate/memories/ directory. // // Examples: // rigstate remember "We chose Supabase for real-time and RLS" // rigstate remember "Never use 'any' in shared types" --category LESSON --tags "typescript,shared" // rigstate remember "ADR-001: Monorepo over polyrepo" --category ADR --importance 9 // ───────────────────────────────────────────────────────────────────────────── export function createRememberCommand(): Command { return new Command('remember') .description('Save a memory to the local knowledge base (.rigstate/memories/)') .argument('', 'The memory content to save') .option('-t, --title ', 'Title for the memory (defaults to first 60 chars of text)') .option('-c, --category <category>', 'Category: ADR, DECISION, LESSON, CONTEXT, INSTRUCTION, PATTERN, GOTCHA', 'CONTEXT') .option('--tags <tags>', 'Comma-separated tags (e.g. "supabase,architecture")') .option('-i, --importance <n>', 'Importance 1-10 (default: 5)', '5') .option('--source <source>', 'Source: USER, AGENT, COUNCIL, GOVERNANCE, HARVEST, IMPORT', 'USER') .action(async (text: string, options) => { try { const projectId = getProjectId(); const title = options.title || text.substring(0, 60) + (text.length > 60 ? '...' : ''); const tags = options.tags ? options.tags.split(',').map((t: string) => t.trim()) : []; const importance = Math.min(10, Math.max(1, parseInt(options.importance, 10) || 5)); const memory = saveMemory({ title, content: text, category: (options.category as MemoryCategory) || 'CONTEXT', source: options.source || 'USER', tags, importance, project_id: projectId || undefined, }); console.log(''); console.log(chalk.bold.green('🧠 Memory Saved')); console.log(chalk.dim('────────────────────────────────────────')); console.log(`${chalk.bold('ID:')} ${chalk.dim(memory.id)}`); console.log(`${chalk.bold('Title:')} ${chalk.cyan(memory.title)}`); console.log(`${chalk.bold('Category:')} ${chalk.magenta(memory.category)}`); console.log(`${chalk.bold('Importance:')} ${'⭐'.repeat(Math.min(5, Math.ceil(importance / 2)))} (${importance}/10)`); if (tags.length > 0) { console.log(`${chalk.bold('Tags:')} ${tags.map((t: string) => chalk.yellow(`#${t}`)).join(' ')}`); } console.log(chalk.dim('────────────────────────────────────────')); // Show stats const stats = getMemoryStats(); console.log(chalk.dim(`Total memories: ${stats.total}`)); console.log(''); } catch (err: any) { console.error(chalk.red(`❌ Failed to save memory: ${err.message}`)); process.exit(1); } }); }