diff --git a/.claude/skills/ccw-coordinator/phases/actions/action-command-execute.md b/.claude/skills/ccw-coordinator/phases/actions/action-command-execute.md index 387791f6..ec4f0203 100644 --- a/.claude/skills/ccw-coordinator/phases/actions/action-command-execute.md +++ b/.claude/skills/ccw-coordinator/phases/actions/action-command-execute.md @@ -5,8 +5,8 @@ ## 命令注册表集成 ```javascript -// 从 ./tools/command-registry.js 按需提取命令元数据 -const CommandRegistry = require('./tools/command-registry.js'); +// 从 ./tools/command-registry.cjs 按需提取命令元数据 +const CommandRegistry = require('./tools/command-registry.cjs'); const registry = new CommandRegistry(); // 只提取当前任务链中的命令 diff --git a/.claude/skills/ccw-coordinator/specs/specs.md b/.claude/skills/ccw-coordinator/specs/specs.md index 882eaab1..50fa7bb0 100644 --- a/.claude/skills/ccw-coordinator/specs/specs.md +++ b/.claude/skills/ccw-coordinator/specs/specs.md @@ -299,7 +299,7 @@ node tools/chain-validate.js plan execute test-cycle-execute ### 工具位置 -位置: `tools/command-registry.js` (skill 内置) +位置: `tools/command-registry.cjs` (skill 内置) ### 工作模式 @@ -324,7 +324,7 @@ const commandMeta = registry.getCommands(commandNames); 在 action-command-execute 中自动集成: ```javascript -const CommandRegistry = require('./tools/command-registry.js'); +const CommandRegistry = require('./tools/command-registry.cjs'); const registry = new CommandRegistry(); // 只提取任务链中的命令 diff --git a/.claude/skills/ccw-coordinator/tools/README.md b/.claude/skills/ccw-coordinator/tools/README.md index d5a37949..b44335b0 100644 --- a/.claude/skills/ccw-coordinator/tools/README.md +++ b/.claude/skills/ccw-coordinator/tools/README.md @@ -1,48 +1,64 @@ # CCW Coordinator Tools -## command-registry.js +## command-registry.cjs -命令注册表工具:按需查找并提取命令 YAML 头元数据。 +命令注册表工具:获取和提取命令元数据。 ### 功能 -- **按需提取**: 只提取用户任务链中的命令(不是全量扫描) +- **按需提取**: 只提取指定命令的完整信息(name, description, argumentHint, allowedTools 等) +- **全量获取**: 获取所有命令的名称和描述(快速查询) - **自动查找**: 从全局 `.claude/commands/workflow` 目录读取(项目相对路径 > 用户 home) -- **解析 YAML 头**: 提取 name, description, argument-hint, allowed-tools - **缓存机制**: 避免重复读取文件 ### 编程接口 ```javascript -const CommandRegistry = require('./tools/command-registry.js'); +const CommandRegistry = require('./tools/command-registry.cjs'); const registry = new CommandRegistry(); -// 按需提取命令链中的命令元数据 -const commandNames = ['/workflow:lite-plan', '/workflow:lite-execute']; -const commands = registry.getCommands(commandNames); - -// 输出: +// 1. 获取所有命令的名称和描述(快速) +const allCommands = registry.getAllCommandsSummary(); +// { +// "/workflow:lite-plan": { +// name: 'lite-plan', +// description: '轻量级规划...' +// }, +// "/workflow:lite-execute": { ... } +// } + +// 2. 按需提取指定命令的完整信息 +const commands = registry.getCommands([ + '/workflow:lite-plan', + '/workflow:lite-execute' +]); // { // "/workflow:lite-plan": { // name: 'lite-plan', -// command: '/workflow:lite-plan', // description: '...', // argumentHint: '[-e|--explore] "task description"', // allowedTools: [...], // filePath: '...' // }, -// "/workflow:lite-execute": { ... } +// ... // } ``` ### 命令行接口 ```bash -# 提取指定命令 -node .claude/skills/ccw-coordinator/tools/command-registry.js lite-plan lite-execute +# 获取所有命令的名称和描述 +node .claude/skills/ccw-coordinator/tools/command-registry.cjs +node .claude/skills/ccw-coordinator/tools/command-registry.cjs --all -# 输出 JSON -node .claude/skills/ccw-coordinator/tools/command-registry.js /workflow:lite-plan +# 输出: 23 个命令的简明列表 (name + description) +``` + +```bash +# 按需提取指定命令的完整信息 +node .claude/skills/ccw-coordinator/tools/command-registry.cjs lite-plan lite-execute + +# 输出: 完整信息 (name, description, argumentHint, allowedTools, filePath) ``` ### 集成用途 @@ -50,7 +66,7 @@ node .claude/skills/ccw-coordinator/tools/command-registry.js /workflow:lite-pla 在 `action-command-execute` 中使用: ```javascript -// 1. 只提取任务链中的命令 +// 1. 初始化时只提取任务链中的命令(完整信息) const commandNames = command_chain.map(cmd => cmd.command); const commandMeta = registry.getCommands(commandNames); @@ -75,3 +91,5 @@ function generatePrompt(cmd, state, commandMeta) { 1. `.claude/commands/workflow` (相对于当前工作目录) 2. `~/.claude/commands/workflow` (用户 home 目录) + + diff --git a/.claude/skills/ccw-coordinator/tools/command-registry.js b/.claude/skills/ccw-coordinator/tools/command-registry.cjs similarity index 73% rename from .claude/skills/ccw-coordinator/tools/command-registry.js rename to .claude/skills/ccw-coordinator/tools/command-registry.cjs index 4753e521..4409f0a4 100644 --- a/.claude/skills/ccw-coordinator/tools/command-registry.js +++ b/.claude/skills/ccw-coordinator/tools/command-registry.cjs @@ -51,13 +51,14 @@ class CommandRegistry { * 解析 YAML 头 */ parseYamlHeader(content) { - const match = content.match(/^---\n([\s\S]*?)\n---/); + // 处理 Windows 行结尾 (\r\n) + const match = content.match(/^---[\r\n]+([\s\S]*?)[\r\n]+---/); if (!match) return null; const yamlContent = match[1]; const result = {}; - const lines = yamlContent.split('\n'); + const lines = yamlContent.split(/[\r\n]+/); for (const line of lines) { if (!line.trim()) continue; @@ -151,6 +152,53 @@ class CommandRegistry { return result; } + /** + * 获取所有命令的名称和描述 + * @returns {object} 命令名称和描述的映射 + */ + getAllCommandsSummary() { + const result = {}; + const commandDir = this.commandDir; + + if (!commandDir) { + return result; + } + + try { + const files = fs.readdirSync(commandDir); + + for (const file of files) { + if (!file.endsWith('.md')) continue; + + const filePath = path.join(commandDir, file); + const stat = fs.statSync(filePath); + + if (stat.isDirectory()) continue; + + try { + const content = fs.readFileSync(filePath, 'utf-8'); + const header = this.parseYamlHeader(content); + + if (header && header.name) { + const commandName = `/workflow:${header.name}`; + result[commandName] = { + name: header.name, + description: header.description || '' + }; + } + } catch (error) { + // 跳过读取失败的文件 + continue; + } + } + } catch (error) { + // 目录读取失败 + return result; + } + + return result; + } + /** * 生成注册表 JSON */ @@ -164,11 +212,12 @@ class CommandRegistry { if (require.main === module) { const args = process.argv.slice(2); - if (args.length === 0) { - console.error('用法: node command-registry.js [command-name2] ...'); - console.error('示例: node command-registry.js lite-plan lite-execute'); - console.error(' node command-registry.js /workflow:lite-plan'); - process.exit(1); + if (args.length === 0 || args[0] === '--all') { + // 获取所有命令的名称和描述 + const registry = new CommandRegistry(); + const commands = registry.getAllCommandsSummary(); + console.log(JSON.stringify(commands, null, 2)); + process.exit(0); } const registry = new CommandRegistry();