UNPKG

evolve-memory-system

Version:

一个集成了LlamaIndex RAG, LMCE和MCP工具的本地记忆系统,专为小说《进化》设计。

137 lines (125 loc) 4.89 kB
#!/usr/bin/env node const { program } = require('commander'); const chalk = require('chalk'); const spawn = require('cross-spawn'); const path = require('path'); const fs = require('fs'); const os = require('os'); // 获取Evolve主目录 const EVOLVE_HOME = path.join(os.homedir(), '.evolve'); // 获取当前包的根目录(处理npx和全局安装环境) const getPackageRoot = () => { // 如果是从全局安装的包运行 if (__dirname.includes('node_modules')) { // 找到包的根目录 let current = __dirname; while (current && !fs.existsSync(path.join(current, 'package.json'))) { current = path.dirname(current); if (current === path.dirname(current)) break; // 到达根目录 } return current; } // 如果是本地开发环境 return path.dirname(__filename); }; const PACKAGE_ROOT = getPackageRoot(); const SCRIPTS_DIR = path.join(PACKAGE_ROOT, 'scripts'); program .version('1.2.3') .description(chalk.cyan('Evolve Memory System CLI - 小说《进化》记忆系统管理工具')); program .command('start') .description(chalk.green('🚀 启动所有服务 (RAG, LMCE, MCP)')) .action(() => { console.log(chalk.blue('正在启动所有服务...')); const scriptPath = path.join(SCRIPTS_DIR, 'start-all.sh'); // 确保脚本存在 if (!fs.existsSync(scriptPath)) { console.error(chalk.red(`错误: 找不到启动脚本 ${scriptPath}`)); // 尝试在npx环境中查找 const npxScriptPath = path.join(__dirname, 'scripts', 'start-all.sh'); if (fs.existsSync(npxScriptPath)) { spawn.sync(npxScriptPath, [], { stdio: 'inherit', cwd: EVOLVE_HOME }); return; } process.exit(1); } // 设置工作目录为EVOLVE_HOME spawn.sync(scriptPath, [], { stdio: 'inherit', cwd: EVOLVE_HOME }); }); program .command('stop') .description(chalk.red('🛑 停止所有服务')) .action(() => { console.log(chalk.yellow('正在停止所有服务...')); const scriptPath = path.join(SCRIPTS_DIR, 'stop-all.sh'); // 确保脚本存在 if (!fs.existsSync(scriptPath)) { console.error(chalk.red(`错误: 找不到停止脚本 ${scriptPath}`)); // 尝试在npx环境中查找 const npxScriptPath = path.join(__dirname, 'scripts', 'stop-all.sh'); if (fs.existsSync(npxScriptPath)) { spawn.sync(npxScriptPath, [], { stdio: 'inherit', cwd: EVOLVE_HOME }); return; } process.exit(1); } // 设置工作目录为EVOLVE_HOME spawn.sync(scriptPath, [], { stdio: 'inherit', cwd: EVOLVE_HOME }); }); program .command('status') .description(chalk.yellow('📊 检查所有服务状态')) .action(() => { console.log(chalk.magenta('正在检查服务状态...')); const scriptPath = path.join(SCRIPTS_DIR, 'status.sh'); // 确保脚本存在 if (!fs.existsSync(scriptPath)) { console.error(chalk.red(`错误: 找不到状态检查脚本 ${scriptPath}`)); // 尝试在npx环境中查找 const npxScriptPath = path.join(__dirname, 'scripts', 'status.sh'); if (fs.existsSync(npxScriptPath)) { spawn.sync(npxScriptPath, [], { stdio: 'inherit', cwd: EVOLVE_HOME }); return; } process.exit(1); } // 设置工作目录为EVOLVE_HOME spawn.sync(scriptPath, [], { stdio: 'inherit', cwd: EVOLVE_HOME }); }); program .command('init-rag') .description(chalk.blue('🔄 初始化或重置LlamaIndex RAG知识库')) .option('--reset', '清空并重置知识库') .action((options) => { console.log(chalk.blue('正在初始化LlamaIndex RAG知识库...')); const scriptPath = path.join(SCRIPTS_DIR, 'init-rag-llama.py'); // 确保脚本存在 if (!fs.existsSync(scriptPath)) { console.error(chalk.red(`错误: 找不到RAG初始化脚本 ${scriptPath}`)); // 尝试在npx环境中查找 const npxScriptPath = path.join(__dirname, 'scripts', 'init-rag-llama.py'); if (fs.existsSync(npxScriptPath)) { const args = options.reset ? ['reset'] : []; spawn.sync('python3', [npxScriptPath, ...args], { stdio: 'inherit', cwd: EVOLVE_HOME }); return; } process.exit(1); } const args = options.reset ? ['reset'] : []; // 设置工作目录为EVOLVE_HOME spawn.sync('python3', [scriptPath, ...args], { stdio: 'inherit', cwd: EVOLVE_HOME }); }); program .command('connect-claude') .description(chalk.magenta('🔗 连接到Claude Code')) .action(() => { console.log(chalk.blue('正在配置Claude Code工具...')); const configPath = path.join(PACKAGE_ROOT, '.claude', 'tools'); console.log(chalk.green(`请将以下路径添加到Claude Code的工具配置中:`)); console.log(chalk.yellow(configPath)); }); program.parse(process.argv); if (!program.args.length) { program.help(); }