import * as fs from 'fs'; import * as path from 'path'; import { fileURLToPath } from 'url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); // 工具名到子目录的映射 const TOOL_CATEGORY_MAP: Record = { // shell bash: 'shell', // filesystem read_file: 'filesystem', write_file: 'filesystem', edit_file: 'filesystem', multi_edit: 'filesystem', glob: 'filesystem', grep: 'filesystem', // web web_search: 'web', web_extract: 'web', // git git_status: 'git', git_diff: 'git', git_log: 'git', git_branch: 'git', git_add: 'git', git_commit: 'git', git_push: 'git', git_pull: 'git', git_checkout: 'git', git_stash: 'git', // todo todo_write: 'todo', // plan ask_user_question: 'plan', enter_plan_mode: 'plan', exit_plan_mode: 'plan', // task task: 'task', task_output: 'task', // checkpoint checkpoint_create: 'checkpoint', checkpoint_list: 'checkpoint', checkpoint_diff: 'checkpoint', checkpoint_restore: 'checkpoint', undo: 'checkpoint', // repomap repo_map: 'repomap', }; export function loadDescription(toolName: string): string { const category = TOOL_CATEGORY_MAP[toolName]; const filePath = category ? path.join(__dirname, 'descriptions', category, `${toolName}.txt`) : path.join(__dirname, 'descriptions', `${toolName}.txt`); try { return fs.readFileSync(filePath, 'utf-8').trim(); } catch { throw new Error(`无法加载工具描述文件: ${filePath}`); } }