mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-02-12 02:37:45 +08:00
refactor: Rename command-registry.js to command-registry.cjs and update references
This commit is contained in:
@@ -5,8 +5,8 @@
|
|||||||
## 命令注册表集成
|
## 命令注册表集成
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// 从 ./tools/command-registry.js 按需提取命令元数据
|
// 从 ./tools/command-registry.cjs 按需提取命令元数据
|
||||||
const CommandRegistry = require('./tools/command-registry.js');
|
const CommandRegistry = require('./tools/command-registry.cjs');
|
||||||
const registry = new CommandRegistry();
|
const registry = new CommandRegistry();
|
||||||
|
|
||||||
// 只提取当前任务链中的命令
|
// 只提取当前任务链中的命令
|
||||||
|
|||||||
@@ -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 中自动集成:
|
在 action-command-execute 中自动集成:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const CommandRegistry = require('./tools/command-registry.js');
|
const CommandRegistry = require('./tools/command-registry.cjs');
|
||||||
const registry = new CommandRegistry();
|
const registry = new CommandRegistry();
|
||||||
|
|
||||||
// 只提取任务链中的命令
|
// 只提取任务链中的命令
|
||||||
|
|||||||
@@ -1,48 +1,64 @@
|
|||||||
# CCW Coordinator Tools
|
# CCW Coordinator Tools
|
||||||
|
|
||||||
## command-registry.js
|
## command-registry.cjs
|
||||||
|
|
||||||
命令注册表工具:按需查找并提取命令 YAML 头元数据。
|
命令注册表工具:获取和提取命令元数据。
|
||||||
|
|
||||||
### 功能
|
### 功能
|
||||||
|
|
||||||
- **按需提取**: 只提取用户任务链中的命令(不是全量扫描)
|
- **按需提取**: 只提取指定命令的完整信息(name, description, argumentHint, allowedTools 等)
|
||||||
|
- **全量获取**: 获取所有命令的名称和描述(快速查询)
|
||||||
- **自动查找**: 从全局 `.claude/commands/workflow` 目录读取(项目相对路径 > 用户 home)
|
- **自动查找**: 从全局 `.claude/commands/workflow` 目录读取(项目相对路径 > 用户 home)
|
||||||
- **解析 YAML 头**: 提取 name, description, argument-hint, allowed-tools
|
|
||||||
- **缓存机制**: 避免重复读取文件
|
- **缓存机制**: 避免重复读取文件
|
||||||
|
|
||||||
### 编程接口
|
### 编程接口
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const CommandRegistry = require('./tools/command-registry.js');
|
const CommandRegistry = require('./tools/command-registry.cjs');
|
||||||
const registry = new CommandRegistry();
|
const registry = new CommandRegistry();
|
||||||
|
|
||||||
// 按需提取命令链中的命令元数据
|
// 1. 获取所有命令的名称和描述(快速)
|
||||||
const commandNames = ['/workflow:lite-plan', '/workflow:lite-execute'];
|
const allCommands = registry.getAllCommandsSummary();
|
||||||
const commands = registry.getCommands(commandNames);
|
// {
|
||||||
|
// "/workflow:lite-plan": {
|
||||||
// 输出:
|
// name: 'lite-plan',
|
||||||
|
// description: '轻量级规划...'
|
||||||
|
// },
|
||||||
|
// "/workflow:lite-execute": { ... }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// 2. 按需提取指定命令的完整信息
|
||||||
|
const commands = registry.getCommands([
|
||||||
|
'/workflow:lite-plan',
|
||||||
|
'/workflow:lite-execute'
|
||||||
|
]);
|
||||||
// {
|
// {
|
||||||
// "/workflow:lite-plan": {
|
// "/workflow:lite-plan": {
|
||||||
// name: 'lite-plan',
|
// name: 'lite-plan',
|
||||||
// command: '/workflow:lite-plan',
|
|
||||||
// description: '...',
|
// description: '...',
|
||||||
// argumentHint: '[-e|--explore] "task description"',
|
// argumentHint: '[-e|--explore] "task description"',
|
||||||
// allowedTools: [...],
|
// allowedTools: [...],
|
||||||
// filePath: '...'
|
// filePath: '...'
|
||||||
// },
|
// },
|
||||||
// "/workflow:lite-execute": { ... }
|
// ...
|
||||||
// }
|
// }
|
||||||
```
|
```
|
||||||
|
|
||||||
### 命令行接口
|
### 命令行接口
|
||||||
|
|
||||||
```bash
|
```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
|
# 输出: 23 个命令的简明列表 (name + description)
|
||||||
node .claude/skills/ccw-coordinator/tools/command-registry.js /workflow:lite-plan
|
```
|
||||||
|
|
||||||
|
```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` 中使用:
|
在 `action-command-execute` 中使用:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// 1. 只提取任务链中的命令
|
// 1. 初始化时只提取任务链中的命令(完整信息)
|
||||||
const commandNames = command_chain.map(cmd => cmd.command);
|
const commandNames = command_chain.map(cmd => cmd.command);
|
||||||
const commandMeta = registry.getCommands(commandNames);
|
const commandMeta = registry.getCommands(commandNames);
|
||||||
|
|
||||||
@@ -75,3 +91,5 @@ function generatePrompt(cmd, state, commandMeta) {
|
|||||||
1. `.claude/commands/workflow` (相对于当前工作目录)
|
1. `.claude/commands/workflow` (相对于当前工作目录)
|
||||||
2. `~/.claude/commands/workflow` (用户 home 目录)
|
2. `~/.claude/commands/workflow` (用户 home 目录)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -51,13 +51,14 @@ class CommandRegistry {
|
|||||||
* 解析 YAML 头
|
* 解析 YAML 头
|
||||||
*/
|
*/
|
||||||
parseYamlHeader(content) {
|
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;
|
if (!match) return null;
|
||||||
|
|
||||||
const yamlContent = match[1];
|
const yamlContent = match[1];
|
||||||
const result = {};
|
const result = {};
|
||||||
|
|
||||||
const lines = yamlContent.split('\n');
|
const lines = yamlContent.split(/[\r\n]+/);
|
||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
if (!line.trim()) continue;
|
if (!line.trim()) continue;
|
||||||
|
|
||||||
@@ -151,6 +152,53 @@ class CommandRegistry {
|
|||||||
return result;
|
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
|
* 生成注册表 JSON
|
||||||
*/
|
*/
|
||||||
@@ -164,11 +212,12 @@ class CommandRegistry {
|
|||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
const args = process.argv.slice(2);
|
const args = process.argv.slice(2);
|
||||||
|
|
||||||
if (args.length === 0) {
|
if (args.length === 0 || args[0] === '--all') {
|
||||||
console.error('用法: node command-registry.js <command-name> [command-name2] ...');
|
// 获取所有命令的名称和描述
|
||||||
console.error('示例: node command-registry.js lite-plan lite-execute');
|
const registry = new CommandRegistry();
|
||||||
console.error(' node command-registry.js /workflow:lite-plan');
|
const commands = registry.getAllCommandsSummary();
|
||||||
process.exit(1);
|
console.log(JSON.stringify(commands, null, 2));
|
||||||
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
const registry = new CommandRegistry();
|
const registry = new CommandRegistry();
|
||||||
Reference in New Issue
Block a user