import { accountRequiredMessage } from '../lib/desktop-mode.js'; import { existsSync, writeFileSync } from 'fs'; import { Command } from 'commander'; import { AuthStore } from '../lib/auth.js'; import { getProfileMemoryFile } from '../lib/init-command.js'; import { loadMemorySnapshot } from '../lib/load-context.js'; function getMemoryFile(): string { const profile = new AuthStore().getActive(); if (!profile) throw new Error(accountRequiredMessage('Not logged in.')); return getProfileMemoryFile(profile); } function ensureMemoryFile(path: string): void { if (!existsSync(path)) writeFileSync(path, ''); } export function createMemoryCommand(): Command { const memory = new Command('memory'); memory .alias('mem') .description('Persistent Behavior and run memory'); memory .command('path') .description('Print the absolute memory file path') .action(() => { const path = getMemoryFile(); ensureMemoryFile(path); console.log(JSON.stringify({ path }, null, 2)); }); memory .command('load', { hidden: true }) .description('Read the memory file') .action(() => { console.log(JSON.stringify(loadMemorySnapshot(), null, 2)); }); return memory; }