mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-02-14 02:42:04 +08:00
feat: Add templates for autonomous actions, orchestrators, sequential phases, and skill documentation
- Introduced a comprehensive template for autonomous actions, detailing structure, execution, and error handling. - Added an orchestrator template to manage state and decision logic for autonomous actions. - Created a sequential phase template to outline execution steps and objectives for structured workflows. - Developed a skill documentation template to standardize the generation of skill entry files. - Implemented a Python script to compare search results between hybrid and cascade methods, analyzing ranking changes.
This commit is contained in:
506
.claude/skills/skill-generator/templates/autonomous-action.md
Normal file
506
.claude/skills/skill-generator/templates/autonomous-action.md
Normal file
@@ -0,0 +1,506 @@
|
||||
# Autonomous Action Template
|
||||
|
||||
自主模式动作文件的模板。
|
||||
|
||||
## 模板结构
|
||||
|
||||
```markdown
|
||||
# Action: {{action_name}}
|
||||
|
||||
{{action_description}}
|
||||
|
||||
## Purpose
|
||||
|
||||
{{purpose}}
|
||||
|
||||
## Preconditions
|
||||
|
||||
{{preconditions_list}}
|
||||
|
||||
## Execution
|
||||
|
||||
\`\`\`javascript
|
||||
async function execute(state) {
|
||||
{{execution_code}}
|
||||
}
|
||||
\`\`\`
|
||||
|
||||
## State Updates
|
||||
|
||||
\`\`\`javascript
|
||||
return {
|
||||
stateUpdates: {
|
||||
{{state_updates}}
|
||||
}
|
||||
};
|
||||
\`\`\`
|
||||
|
||||
## Error Handling
|
||||
|
||||
| Error Type | Recovery |
|
||||
|------------|----------|
|
||||
{{error_handling_table}}
|
||||
|
||||
## Next Actions (Hints)
|
||||
|
||||
{{next_actions_hints}}
|
||||
```
|
||||
|
||||
## 变量说明
|
||||
|
||||
| 变量 | 说明 |
|
||||
|------|------|
|
||||
| `{{action_name}}` | 动作名称 |
|
||||
| `{{action_description}}` | 动作描述 |
|
||||
| `{{purpose}}` | 详细目的 |
|
||||
| `{{preconditions_list}}` | 前置条件列表 |
|
||||
| `{{execution_code}}` | 执行代码 |
|
||||
| `{{state_updates}}` | 状态更新 |
|
||||
| `{{error_handling_table}}` | 错误处理表格 |
|
||||
| `{{next_actions_hints}}` | 后续动作提示 |
|
||||
|
||||
## 动作类型模板
|
||||
|
||||
### 1. 初始化动作 (Init)
|
||||
|
||||
```markdown
|
||||
# Action: Initialize
|
||||
|
||||
初始化 Skill 执行状态。
|
||||
|
||||
## Purpose
|
||||
|
||||
设置初始状态,准备执行环境。
|
||||
|
||||
## Preconditions
|
||||
|
||||
- [ ] state.status === 'pending'
|
||||
|
||||
## Execution
|
||||
|
||||
\`\`\`javascript
|
||||
async function execute(state) {
|
||||
// 1. 创建工作目录
|
||||
Bash(\`mkdir -p "\${workDir}"\`);
|
||||
|
||||
// 2. 初始化数据
|
||||
const initialData = {
|
||||
items: [],
|
||||
metadata: {}
|
||||
};
|
||||
|
||||
// 3. 返回状态更新
|
||||
return {
|
||||
stateUpdates: {
|
||||
status: 'running',
|
||||
context: initialData
|
||||
}
|
||||
};
|
||||
}
|
||||
\`\`\`
|
||||
|
||||
## State Updates
|
||||
|
||||
\`\`\`javascript
|
||||
return {
|
||||
stateUpdates: {
|
||||
status: 'running',
|
||||
started_at: new Date().toISOString(),
|
||||
context: { /* 初始数据 */ }
|
||||
}
|
||||
};
|
||||
\`\`\`
|
||||
|
||||
## Next Actions
|
||||
|
||||
- 成功: 进入主处理循环
|
||||
- 失败: action-abort
|
||||
```
|
||||
|
||||
### 2. 列表动作 (List)
|
||||
|
||||
```markdown
|
||||
# Action: List Items
|
||||
|
||||
显示当前项目列表。
|
||||
|
||||
## Purpose
|
||||
|
||||
展示所有项目供用户查看和选择。
|
||||
|
||||
## Preconditions
|
||||
|
||||
- [ ] state.status === 'running'
|
||||
|
||||
## Execution
|
||||
|
||||
\`\`\`javascript
|
||||
async function execute(state) {
|
||||
const items = state.context.items || [];
|
||||
|
||||
if (items.length === 0) {
|
||||
console.log('暂无项目');
|
||||
} else {
|
||||
console.log('项目列表:');
|
||||
items.forEach((item, i) => {
|
||||
console.log(\`\${i + 1}. \${item.name} - \${item.status}\`);
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
stateUpdates: {
|
||||
last_action: 'list',
|
||||
current_view: 'list'
|
||||
}
|
||||
};
|
||||
}
|
||||
\`\`\`
|
||||
|
||||
## State Updates
|
||||
|
||||
\`\`\`javascript
|
||||
return {
|
||||
stateUpdates: {
|
||||
current_view: 'list',
|
||||
last_viewed_at: new Date().toISOString()
|
||||
}
|
||||
};
|
||||
\`\`\`
|
||||
|
||||
## Next Actions
|
||||
|
||||
- 用户选择创建: action-create
|
||||
- 用户选择编辑: action-edit
|
||||
- 用户退出: action-complete
|
||||
```
|
||||
|
||||
### 3. 创建动作 (Create)
|
||||
|
||||
```markdown
|
||||
# Action: Create Item
|
||||
|
||||
创建新项目。
|
||||
|
||||
## Purpose
|
||||
|
||||
引导用户创建新项目。
|
||||
|
||||
## Preconditions
|
||||
|
||||
- [ ] state.status === 'running'
|
||||
|
||||
## Execution
|
||||
|
||||
\`\`\`javascript
|
||||
async function execute(state) {
|
||||
// 1. 收集信息
|
||||
const input = await AskUserQuestion({
|
||||
questions: [{
|
||||
question: "请输入项目名称:",
|
||||
header: "名称",
|
||||
multiSelect: false,
|
||||
options: [
|
||||
{ label: "手动输入", description: "输入自定义名称" }
|
||||
]
|
||||
}]
|
||||
});
|
||||
|
||||
// 2. 创建项目
|
||||
const newItem = {
|
||||
id: Date.now().toString(),
|
||||
name: input["名称"],
|
||||
status: 'pending',
|
||||
created_at: new Date().toISOString()
|
||||
};
|
||||
|
||||
// 3. 返回状态更新
|
||||
return {
|
||||
stateUpdates: {
|
||||
context: {
|
||||
...state.context,
|
||||
items: [...(state.context.items || []), newItem]
|
||||
},
|
||||
last_created_id: newItem.id
|
||||
}
|
||||
};
|
||||
}
|
||||
\`\`\`
|
||||
|
||||
## State Updates
|
||||
|
||||
\`\`\`javascript
|
||||
return {
|
||||
stateUpdates: {
|
||||
'context.items': [...items, newItem],
|
||||
last_action: 'create',
|
||||
last_created_id: newItem.id
|
||||
}
|
||||
};
|
||||
\`\`\`
|
||||
|
||||
## Next Actions
|
||||
|
||||
- 继续创建: action-create
|
||||
- 返回列表: action-list
|
||||
```
|
||||
|
||||
### 4. 编辑动作 (Edit)
|
||||
|
||||
```markdown
|
||||
# Action: Edit Item
|
||||
|
||||
编辑现有项目。
|
||||
|
||||
## Purpose
|
||||
|
||||
修改已存在的项目。
|
||||
|
||||
## Preconditions
|
||||
|
||||
- [ ] state.status === 'running'
|
||||
- [ ] state.selected_item_id !== null
|
||||
|
||||
## Execution
|
||||
|
||||
\`\`\`javascript
|
||||
async function execute(state) {
|
||||
const itemId = state.selected_item_id;
|
||||
const items = state.context.items || [];
|
||||
const item = items.find(i => i.id === itemId);
|
||||
|
||||
if (!item) {
|
||||
throw new Error(\`Item not found: \${itemId}\`);
|
||||
}
|
||||
|
||||
// 1. 显示当前值
|
||||
console.log(\`当前名称: \${item.name}\`);
|
||||
|
||||
// 2. 收集新值
|
||||
const input = await AskUserQuestion({
|
||||
questions: [{
|
||||
question: "请输入新名称(留空保持不变):",
|
||||
header: "新名称",
|
||||
multiSelect: false,
|
||||
options: [
|
||||
{ label: "保持不变", description: \`当前: \${item.name}\` },
|
||||
{ label: "手动输入", description: "输入新名称" }
|
||||
]
|
||||
}]
|
||||
});
|
||||
|
||||
// 3. 更新项目
|
||||
const updatedItems = items.map(i =>
|
||||
i.id === itemId
|
||||
? { ...i, name: input["新名称"] || i.name, updated_at: new Date().toISOString() }
|
||||
: i
|
||||
);
|
||||
|
||||
return {
|
||||
stateUpdates: {
|
||||
context: { ...state.context, items: updatedItems },
|
||||
selected_item_id: null
|
||||
}
|
||||
};
|
||||
}
|
||||
\`\`\`
|
||||
|
||||
## State Updates
|
||||
|
||||
\`\`\`javascript
|
||||
return {
|
||||
stateUpdates: {
|
||||
'context.items': updatedItems,
|
||||
selected_item_id: null,
|
||||
last_action: 'edit'
|
||||
}
|
||||
};
|
||||
\`\`\`
|
||||
|
||||
## Next Actions
|
||||
|
||||
- 返回列表: action-list
|
||||
```
|
||||
|
||||
### 5. 删除动作 (Delete)
|
||||
|
||||
```markdown
|
||||
# Action: Delete Item
|
||||
|
||||
删除项目。
|
||||
|
||||
## Purpose
|
||||
|
||||
从列表中移除项目。
|
||||
|
||||
## Preconditions
|
||||
|
||||
- [ ] state.status === 'running'
|
||||
- [ ] state.selected_item_id !== null
|
||||
|
||||
## Execution
|
||||
|
||||
\`\`\`javascript
|
||||
async function execute(state) {
|
||||
const itemId = state.selected_item_id;
|
||||
const items = state.context.items || [];
|
||||
|
||||
// 1. 确认删除
|
||||
const confirm = await AskUserQuestion({
|
||||
questions: [{
|
||||
question: "确认删除此项目?",
|
||||
header: "确认",
|
||||
multiSelect: false,
|
||||
options: [
|
||||
{ label: "确认删除", description: "不可恢复" },
|
||||
{ label: "取消", description: "返回列表" }
|
||||
]
|
||||
}]
|
||||
});
|
||||
|
||||
if (confirm["确认"] === "取消") {
|
||||
return { stateUpdates: { selected_item_id: null } };
|
||||
}
|
||||
|
||||
// 2. 执行删除
|
||||
const updatedItems = items.filter(i => i.id !== itemId);
|
||||
|
||||
return {
|
||||
stateUpdates: {
|
||||
context: { ...state.context, items: updatedItems },
|
||||
selected_item_id: null
|
||||
}
|
||||
};
|
||||
}
|
||||
\`\`\`
|
||||
|
||||
## State Updates
|
||||
|
||||
\`\`\`javascript
|
||||
return {
|
||||
stateUpdates: {
|
||||
'context.items': filteredItems,
|
||||
selected_item_id: null,
|
||||
last_action: 'delete'
|
||||
}
|
||||
};
|
||||
\`\`\`
|
||||
|
||||
## Next Actions
|
||||
|
||||
- 返回列表: action-list
|
||||
```
|
||||
|
||||
### 6. 完成动作 (Complete)
|
||||
|
||||
```markdown
|
||||
# Action: Complete
|
||||
|
||||
完成任务并退出。
|
||||
|
||||
## Purpose
|
||||
|
||||
保存最终状态,结束 Skill 执行。
|
||||
|
||||
## Preconditions
|
||||
|
||||
- [ ] state.status === 'running'
|
||||
|
||||
## Execution
|
||||
|
||||
\`\`\`javascript
|
||||
async function execute(state) {
|
||||
// 1. 保存最终数据
|
||||
Write(\`\${workDir}/final-output.json\`, JSON.stringify(state.context, null, 2));
|
||||
|
||||
// 2. 生成摘要
|
||||
const summary = {
|
||||
total_items: state.context.items?.length || 0,
|
||||
duration: Date.now() - new Date(state.started_at).getTime(),
|
||||
actions_executed: state.completed_actions.length
|
||||
};
|
||||
|
||||
console.log('任务完成!');
|
||||
console.log(\`处理项目: \${summary.total_items}\`);
|
||||
console.log(\`执行动作: \${summary.actions_executed}\`);
|
||||
|
||||
return {
|
||||
stateUpdates: {
|
||||
status: 'completed',
|
||||
summary: summary
|
||||
}
|
||||
};
|
||||
}
|
||||
\`\`\`
|
||||
|
||||
## State Updates
|
||||
|
||||
\`\`\`javascript
|
||||
return {
|
||||
stateUpdates: {
|
||||
status: 'completed',
|
||||
completed_at: new Date().toISOString(),
|
||||
summary: { /* 统计信息 */ }
|
||||
}
|
||||
};
|
||||
\`\`\`
|
||||
|
||||
## Next Actions
|
||||
|
||||
- 无(终止状态)
|
||||
```
|
||||
|
||||
## 生成函数
|
||||
|
||||
```javascript
|
||||
function generateAction(actionConfig, skillConfig) {
|
||||
return `# Action: ${actionConfig.name}
|
||||
|
||||
${actionConfig.description || `执行 ${actionConfig.name} 操作`}
|
||||
|
||||
## Purpose
|
||||
|
||||
${actionConfig.purpose || 'TODO: 描述此动作的详细目的'}
|
||||
|
||||
## Preconditions
|
||||
|
||||
${actionConfig.preconditions?.map(p => `- [ ] ${p}`).join('\n') || '- [ ] 无特殊前置条件'}
|
||||
|
||||
## Execution
|
||||
|
||||
\`\`\`javascript
|
||||
async function execute(state) {
|
||||
// TODO: 实现动作逻辑
|
||||
|
||||
return {
|
||||
stateUpdates: {
|
||||
completed_actions: [...state.completed_actions, '${actionConfig.id}']
|
||||
}
|
||||
};
|
||||
}
|
||||
\`\`\`
|
||||
|
||||
## State Updates
|
||||
|
||||
\`\`\`javascript
|
||||
return {
|
||||
stateUpdates: {
|
||||
// TODO: 定义状态更新
|
||||
${actionConfig.effects?.map(e => ` // Effect: ${e}`).join('\n') || ''}
|
||||
}
|
||||
};
|
||||
\`\`\`
|
||||
|
||||
## Error Handling
|
||||
|
||||
| Error Type | Recovery |
|
||||
|------------|----------|
|
||||
| 数据验证失败 | 返回错误,不更新状态 |
|
||||
| 执行异常 | 记录错误,增加 error_count |
|
||||
|
||||
## Next Actions (Hints)
|
||||
|
||||
- 成功: 由编排器根据状态决定
|
||||
- 失败: 重试或 action-abort
|
||||
`;
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,276 @@
|
||||
# Autonomous Orchestrator Template
|
||||
|
||||
自主模式编排器的模板。
|
||||
|
||||
## 模板结构
|
||||
|
||||
```markdown
|
||||
# Orchestrator
|
||||
|
||||
## Role
|
||||
|
||||
根据当前状态选择并执行下一个动作。
|
||||
|
||||
## State Management
|
||||
|
||||
### 读取状态
|
||||
|
||||
\`\`\`javascript
|
||||
const state = JSON.parse(Read(`${workDir}/state.json`));
|
||||
\`\`\`
|
||||
|
||||
### 更新状态
|
||||
|
||||
\`\`\`javascript
|
||||
function updateState(updates) {
|
||||
const state = JSON.parse(Read(`${workDir}/state.json`));
|
||||
const newState = {
|
||||
...state,
|
||||
...updates,
|
||||
updated_at: new Date().toISOString()
|
||||
};
|
||||
Write(`${workDir}/state.json`, JSON.stringify(newState, null, 2));
|
||||
return newState;
|
||||
}
|
||||
\`\`\`
|
||||
|
||||
## Decision Logic
|
||||
|
||||
\`\`\`javascript
|
||||
function selectNextAction(state) {
|
||||
// 1. 终止条件检查
|
||||
{{termination_checks}}
|
||||
|
||||
// 2. 错误限制检查
|
||||
if (state.error_count >= 3) {
|
||||
return 'action-abort';
|
||||
}
|
||||
|
||||
// 3. 动作选择逻辑
|
||||
{{action_selection_logic}}
|
||||
|
||||
// 4. 默认完成
|
||||
return 'action-complete';
|
||||
}
|
||||
\`\`\`
|
||||
|
||||
## Execution Loop
|
||||
|
||||
\`\`\`javascript
|
||||
async function runOrchestrator() {
|
||||
console.log('=== Orchestrator Started ===');
|
||||
|
||||
let iteration = 0;
|
||||
const MAX_ITERATIONS = 100;
|
||||
|
||||
while (iteration < MAX_ITERATIONS) {
|
||||
iteration++;
|
||||
|
||||
// 1. 读取当前状态
|
||||
const state = JSON.parse(Read(`${workDir}/state.json`));
|
||||
console.log(`[Iteration ${iteration}] Status: ${state.status}`);
|
||||
|
||||
// 2. 选择下一个动作
|
||||
const actionId = selectNextAction(state);
|
||||
|
||||
if (!actionId) {
|
||||
console.log('No action selected, terminating.');
|
||||
break;
|
||||
}
|
||||
|
||||
console.log(`[Iteration ${iteration}] Executing: ${actionId}`);
|
||||
|
||||
// 3. 更新状态:当前动作
|
||||
updateState({ current_action: actionId });
|
||||
|
||||
// 4. 执行动作
|
||||
try {
|
||||
const actionPrompt = Read(`phases/actions/${actionId}.md`);
|
||||
|
||||
const result = await Task({
|
||||
subagent_type: 'universal-executor',
|
||||
run_in_background: false,
|
||||
prompt: \`
|
||||
[STATE]
|
||||
\${JSON.stringify(state, null, 2)}
|
||||
|
||||
[ACTION]
|
||||
\${actionPrompt}
|
||||
|
||||
[RETURN]
|
||||
Return JSON with stateUpdates field.
|
||||
\`
|
||||
});
|
||||
|
||||
const actionResult = JSON.parse(result);
|
||||
|
||||
// 5. 更新状态:动作完成
|
||||
updateState({
|
||||
current_action: null,
|
||||
completed_actions: [...state.completed_actions, actionId],
|
||||
...actionResult.stateUpdates
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
// 错误处理
|
||||
updateState({
|
||||
current_action: null,
|
||||
errors: [...state.errors, {
|
||||
action: actionId,
|
||||
message: error.message,
|
||||
timestamp: new Date().toISOString()
|
||||
}],
|
||||
error_count: state.error_count + 1
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
console.log('=== Orchestrator Finished ===');
|
||||
}
|
||||
\`\`\`
|
||||
|
||||
## Action Catalog
|
||||
|
||||
| Action | Purpose | Preconditions |
|
||||
|--------|---------|---------------|
|
||||
{{action_catalog_table}}
|
||||
|
||||
## Termination Conditions
|
||||
|
||||
{{termination_conditions_list}}
|
||||
|
||||
## Error Recovery
|
||||
|
||||
| Error Type | Recovery Strategy |
|
||||
|------------|-------------------|
|
||||
| 动作执行失败 | 重试最多 3 次 |
|
||||
| 状态不一致 | 回滚到上一个稳定状态 |
|
||||
| 用户中止 | 保存当前状态,允许恢复 |
|
||||
```
|
||||
|
||||
## 变量说明
|
||||
|
||||
| 变量 | 说明 |
|
||||
|------|------|
|
||||
| `{{termination_checks}}` | 终止条件检查代码 |
|
||||
| `{{action_selection_logic}}` | 动作选择逻辑代码 |
|
||||
| `{{action_catalog_table}}` | 动作目录表格 |
|
||||
| `{{termination_conditions_list}}` | 终止条件列表 |
|
||||
|
||||
## 生成函数
|
||||
|
||||
```javascript
|
||||
function generateOrchestrator(config) {
|
||||
const actions = config.autonomous_config.actions;
|
||||
const terminations = config.autonomous_config.termination_conditions || [];
|
||||
|
||||
// 生成终止条件检查
|
||||
const terminationChecks = terminations.map(t => {
|
||||
const checks = {
|
||||
'user_exit': 'if (state.status === "user_exit") return null;',
|
||||
'error_limit': 'if (state.error_count >= 3) return "action-abort";',
|
||||
'task_completed': 'if (state.status === "completed") return null;',
|
||||
'max_iterations': 'if (state.iteration_count >= 100) return "action-abort";'
|
||||
};
|
||||
return checks[t] || `if (state.${t}) return null;`;
|
||||
}).join('\n ');
|
||||
|
||||
// 生成动作选择逻辑
|
||||
const actionSelectionLogic = actions.map(action => {
|
||||
if (!action.preconditions?.length) {
|
||||
return `// ${action.name}: 无前置条件,需要手动添加选择逻辑`;
|
||||
}
|
||||
const conditions = action.preconditions.map(p => `state.${p}`).join(' && ');
|
||||
return `if (${conditions}) return '${action.id}';`;
|
||||
}).join('\n ');
|
||||
|
||||
// 生成动作目录表格
|
||||
const actionCatalogTable = actions.map(a =>
|
||||
`| [${a.id}](actions/${a.id}.md) | ${a.description || a.name} | ${a.preconditions?.join(', ') || '-'} |`
|
||||
).join('\n');
|
||||
|
||||
// 生成终止条件列表
|
||||
const terminationConditionsList = terminations.map(t => `- ${t}`).join('\n');
|
||||
|
||||
return template
|
||||
.replace('{{termination_checks}}', terminationChecks)
|
||||
.replace('{{action_selection_logic}}', actionSelectionLogic)
|
||||
.replace('{{action_catalog_table}}', actionCatalogTable)
|
||||
.replace('{{termination_conditions_list}}', terminationConditionsList);
|
||||
}
|
||||
```
|
||||
|
||||
## 编排策略
|
||||
|
||||
### 1. 优先级策略
|
||||
|
||||
按预定义优先级选择动作:
|
||||
|
||||
```javascript
|
||||
const PRIORITY = ['action-init', 'action-process', 'action-review', 'action-complete'];
|
||||
|
||||
function selectByPriority(state, availableActions) {
|
||||
for (const actionId of PRIORITY) {
|
||||
if (availableActions.includes(actionId) && checkPreconditions(actionId, state)) {
|
||||
return actionId;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
```
|
||||
|
||||
### 2. 用户驱动策略
|
||||
|
||||
询问用户选择下一个动作:
|
||||
|
||||
```javascript
|
||||
async function selectByUser(state, availableActions) {
|
||||
const response = await AskUserQuestion({
|
||||
questions: [{
|
||||
question: "选择下一个操作:",
|
||||
header: "操作",
|
||||
multiSelect: false,
|
||||
options: availableActions.map(a => ({
|
||||
label: a.name,
|
||||
description: a.description
|
||||
}))
|
||||
}]
|
||||
});
|
||||
|
||||
return availableActions.find(a => a.name === response["操作"])?.id;
|
||||
}
|
||||
```
|
||||
|
||||
### 3. 状态驱动策略
|
||||
|
||||
完全基于状态自动决策:
|
||||
|
||||
```javascript
|
||||
function selectByState(state) {
|
||||
// 初始化
|
||||
if (state.status === 'pending') return 'action-init';
|
||||
|
||||
// 有待处理项
|
||||
if (state.pending_items?.length > 0) return 'action-process';
|
||||
|
||||
// 需要审核
|
||||
if (state.needs_review) return 'action-review';
|
||||
|
||||
// 完成
|
||||
return 'action-complete';
|
||||
}
|
||||
```
|
||||
|
||||
## 状态机示例
|
||||
|
||||
```mermaid
|
||||
stateDiagram-v2
|
||||
[*] --> pending
|
||||
pending --> running: action-init
|
||||
running --> running: action-process
|
||||
running --> running: action-review
|
||||
running --> completed: action-complete
|
||||
running --> failed: action-abort
|
||||
completed --> [*]
|
||||
failed --> [*]
|
||||
```
|
||||
393
.claude/skills/skill-generator/templates/sequential-phase.md
Normal file
393
.claude/skills/skill-generator/templates/sequential-phase.md
Normal file
@@ -0,0 +1,393 @@
|
||||
# Sequential Phase Template
|
||||
|
||||
顺序模式 Phase 文件的模板。
|
||||
|
||||
## 模板结构
|
||||
|
||||
```markdown
|
||||
# Phase {{phase_number}}: {{phase_name}}
|
||||
|
||||
{{phase_description}}
|
||||
|
||||
## Objective
|
||||
|
||||
{{objectives}}
|
||||
|
||||
## Input
|
||||
|
||||
- 依赖: `{{input_dependency}}`
|
||||
- 配置: `{workDir}/skill-config.json`
|
||||
|
||||
## Execution Steps
|
||||
|
||||
### Step 1: {{step_1_name}}
|
||||
|
||||
\`\`\`javascript
|
||||
{{step_1_code}}
|
||||
\`\`\`
|
||||
|
||||
### Step 2: {{step_2_name}}
|
||||
|
||||
\`\`\`javascript
|
||||
{{step_2_code}}
|
||||
\`\`\`
|
||||
|
||||
### Step 3: {{step_3_name}}
|
||||
|
||||
\`\`\`javascript
|
||||
{{step_3_code}}
|
||||
\`\`\`
|
||||
|
||||
## Output
|
||||
|
||||
- **File**: `{{output_file}}`
|
||||
- **Format**: {{output_format}}
|
||||
|
||||
## Quality Checklist
|
||||
|
||||
{{quality_checklist}}
|
||||
|
||||
## Next Phase
|
||||
|
||||
{{next_phase_link}}
|
||||
```
|
||||
|
||||
## 变量说明
|
||||
|
||||
| 变量 | 说明 |
|
||||
|------|------|
|
||||
| `{{phase_number}}` | 阶段序号 (1, 2, 3...) |
|
||||
| `{{phase_name}}` | 阶段名称 |
|
||||
| `{{phase_description}}` | 一句话描述 |
|
||||
| `{{objectives}}` | 目标列表 |
|
||||
| `{{input_dependency}}` | 输入依赖文件 |
|
||||
| `{{step_N_name}}` | 步骤名称 |
|
||||
| `{{step_N_code}}` | 步骤代码 |
|
||||
| `{{output_file}}` | 输出文件名 |
|
||||
| `{{output_format}}` | 输出格式 |
|
||||
| `{{quality_checklist}}` | 质量检查项 |
|
||||
| `{{next_phase_link}}` | 下一阶段链接 |
|
||||
|
||||
## Phase 类型模板
|
||||
|
||||
### 1. 收集型 Phase (Collection)
|
||||
|
||||
```markdown
|
||||
# Phase 1: Requirements Collection
|
||||
|
||||
收集用户需求和项目配置。
|
||||
|
||||
## Objective
|
||||
|
||||
- 收集用户输入
|
||||
- 自动检测项目信息
|
||||
- 生成配置文件
|
||||
|
||||
## Execution Steps
|
||||
|
||||
### Step 1: 用户交互
|
||||
|
||||
\`\`\`javascript
|
||||
const userInput = await AskUserQuestion({
|
||||
questions: [
|
||||
{
|
||||
question: "请选择...",
|
||||
header: "选项",
|
||||
multiSelect: false,
|
||||
options: [
|
||||
{ label: "选项A", description: "..." },
|
||||
{ label: "选项B", description: "..." }
|
||||
]
|
||||
}
|
||||
]
|
||||
});
|
||||
\`\`\`
|
||||
|
||||
### Step 2: 自动检测
|
||||
|
||||
\`\`\`javascript
|
||||
// 检测项目信息
|
||||
const packageJson = JSON.parse(Read('package.json'));
|
||||
const projectName = packageJson.name;
|
||||
\`\`\`
|
||||
|
||||
### Step 3: 生成配置
|
||||
|
||||
\`\`\`javascript
|
||||
const config = {
|
||||
name: projectName,
|
||||
userChoice: userInput["选项"],
|
||||
// ...
|
||||
};
|
||||
|
||||
Write(`${workDir}/config.json`, JSON.stringify(config, null, 2));
|
||||
\`\`\`
|
||||
|
||||
## Output
|
||||
|
||||
- **File**: `config.json`
|
||||
- **Format**: JSON
|
||||
```
|
||||
|
||||
### 2. 分析型 Phase (Analysis)
|
||||
|
||||
```markdown
|
||||
# Phase 2: Deep Analysis
|
||||
|
||||
深度分析代码结构。
|
||||
|
||||
## Objective
|
||||
|
||||
- 扫描代码文件
|
||||
- 提取关键信息
|
||||
- 生成分析报告
|
||||
|
||||
## Execution Steps
|
||||
|
||||
### Step 1: 文件扫描
|
||||
|
||||
\`\`\`javascript
|
||||
const files = Glob('src/**/*.ts');
|
||||
\`\`\`
|
||||
|
||||
### Step 2: 内容分析
|
||||
|
||||
\`\`\`javascript
|
||||
const analysisResults = [];
|
||||
for (const file of files) {
|
||||
const content = Read(file);
|
||||
// 分析逻辑
|
||||
analysisResults.push({ file, /* 分析结果 */ });
|
||||
}
|
||||
\`\`\`
|
||||
|
||||
### Step 3: 生成报告
|
||||
|
||||
\`\`\`javascript
|
||||
Write(`${workDir}/analysis.json`, JSON.stringify(analysisResults, null, 2));
|
||||
\`\`\`
|
||||
|
||||
## Output
|
||||
|
||||
- **File**: `analysis.json`
|
||||
- **Format**: JSON
|
||||
```
|
||||
|
||||
### 3. 并行型 Phase (Parallel)
|
||||
|
||||
```markdown
|
||||
# Phase 3: Parallel Processing
|
||||
|
||||
并行处理多个子任务。
|
||||
|
||||
## Objective
|
||||
|
||||
- 启动多个 Agent 并行执行
|
||||
- 收集各 Agent 结果
|
||||
- 合并输出
|
||||
|
||||
## Execution Steps
|
||||
|
||||
### Step 1: 准备任务
|
||||
|
||||
\`\`\`javascript
|
||||
const tasks = [
|
||||
{ id: 'task-a', prompt: '...' },
|
||||
{ id: 'task-b', prompt: '...' },
|
||||
{ id: 'task-c', prompt: '...' }
|
||||
];
|
||||
\`\`\`
|
||||
|
||||
### Step 2: 并行执行
|
||||
|
||||
\`\`\`javascript
|
||||
const results = await Promise.all(
|
||||
tasks.map(task =>
|
||||
Task({
|
||||
subagent_type: 'universal-executor',
|
||||
run_in_background: false,
|
||||
prompt: task.prompt
|
||||
})
|
||||
)
|
||||
);
|
||||
\`\`\`
|
||||
|
||||
### Step 3: 合并结果
|
||||
|
||||
\`\`\`javascript
|
||||
const merged = results.map((r, i) => ({
|
||||
task_id: tasks[i].id,
|
||||
result: JSON.parse(r)
|
||||
}));
|
||||
|
||||
Write(`${workDir}/parallel-results.json`, JSON.stringify(merged, null, 2));
|
||||
\`\`\`
|
||||
|
||||
## Output
|
||||
|
||||
- **File**: `parallel-results.json`
|
||||
- **Format**: JSON
|
||||
```
|
||||
|
||||
### 4. 组装型 Phase (Assembly)
|
||||
|
||||
```markdown
|
||||
# Phase 4: Document Assembly
|
||||
|
||||
组装最终输出文档。
|
||||
|
||||
## Objective
|
||||
|
||||
- 读取各阶段产出
|
||||
- 合并内容
|
||||
- 生成最终文档
|
||||
|
||||
## Execution Steps
|
||||
|
||||
### Step 1: 读取产出
|
||||
|
||||
\`\`\`javascript
|
||||
const config = JSON.parse(Read(`${workDir}/config.json`));
|
||||
const analysis = JSON.parse(Read(`${workDir}/analysis.json`));
|
||||
const sections = Glob(`${workDir}/sections/*.md`).map(f => Read(f));
|
||||
\`\`\`
|
||||
|
||||
### Step 2: 组装内容
|
||||
|
||||
\`\`\`javascript
|
||||
const document = \`
|
||||
# \${config.name}
|
||||
|
||||
## 概述
|
||||
\${config.description}
|
||||
|
||||
## 详细内容
|
||||
\${sections.join('\\n\\n')}
|
||||
\`;
|
||||
\`\`\`
|
||||
|
||||
### Step 3: 写入文件
|
||||
|
||||
\`\`\`javascript
|
||||
Write(`${workDir}/${config.name}-output.md`, document);
|
||||
\`\`\`
|
||||
|
||||
## Output
|
||||
|
||||
- **File**: `{name}-output.md`
|
||||
- **Format**: Markdown
|
||||
```
|
||||
|
||||
### 5. 验证型 Phase (Validation)
|
||||
|
||||
```markdown
|
||||
# Phase 5: Validation
|
||||
|
||||
验证输出质量。
|
||||
|
||||
## Objective
|
||||
|
||||
- 检查输出完整性
|
||||
- 验证内容质量
|
||||
- 生成验证报告
|
||||
|
||||
## Execution Steps
|
||||
|
||||
### Step 1: 完整性检查
|
||||
|
||||
\`\`\`javascript
|
||||
const outputFile = `${workDir}/${config.name}-output.md`;
|
||||
const content = Read(outputFile);
|
||||
const completeness = {
|
||||
hasTitle: content.includes('# '),
|
||||
hasSections: content.match(/## /g)?.length >= 3,
|
||||
hasContent: content.length > 500
|
||||
};
|
||||
\`\`\`
|
||||
|
||||
### Step 2: 质量评估
|
||||
|
||||
\`\`\`javascript
|
||||
const quality = {
|
||||
completeness: Object.values(completeness).filter(v => v).length / 3 * 100,
|
||||
// 其他维度...
|
||||
};
|
||||
\`\`\`
|
||||
|
||||
### Step 3: 生成报告
|
||||
|
||||
\`\`\`javascript
|
||||
const report = {
|
||||
status: quality.completeness >= 80 ? 'PASS' : 'REVIEW',
|
||||
scores: quality,
|
||||
issues: []
|
||||
};
|
||||
|
||||
Write(`${workDir}/validation-report.json`, JSON.stringify(report, null, 2));
|
||||
\`\`\`
|
||||
|
||||
## Output
|
||||
|
||||
- **File**: `validation-report.json`
|
||||
- **Format**: JSON
|
||||
```
|
||||
|
||||
## 生成函数
|
||||
|
||||
```javascript
|
||||
function generateSequentialPhase(phaseConfig, index, phases, skillConfig) {
|
||||
const prevPhase = index > 0 ? phases[index - 1] : null;
|
||||
const nextPhase = index < phases.length - 1 ? phases[index + 1] : null;
|
||||
|
||||
return `# Phase ${index + 1}: ${phaseConfig.name}
|
||||
|
||||
${phaseConfig.description || `执行 ${phaseConfig.name}`}
|
||||
|
||||
## Objective
|
||||
|
||||
- ${phaseConfig.objectives?.join('\n- ') || 'TODO: 定义目标'}
|
||||
|
||||
## Input
|
||||
|
||||
- 依赖: \`${prevPhase ? prevPhase.output : 'user input'}\`
|
||||
- 配置: \`{workDir}/skill-config.json\`
|
||||
|
||||
## Execution Steps
|
||||
|
||||
### Step 1: 准备
|
||||
|
||||
\`\`\`javascript
|
||||
${prevPhase ?
|
||||
`const prevOutput = JSON.parse(Read(\`\${workDir}/${prevPhase.output}\`));` :
|
||||
'// 首阶段,从配置开始'}
|
||||
\`\`\`
|
||||
|
||||
### Step 2: 处理
|
||||
|
||||
\`\`\`javascript
|
||||
// TODO: 实现核心逻辑
|
||||
\`\`\`
|
||||
|
||||
### Step 3: 输出
|
||||
|
||||
\`\`\`javascript
|
||||
Write(\`\${workDir}/${phaseConfig.output}\`, JSON.stringify(result, null, 2));
|
||||
\`\`\`
|
||||
|
||||
## Output
|
||||
|
||||
- **File**: \`${phaseConfig.output}\`
|
||||
- **Format**: ${phaseConfig.output.endsWith('.json') ? 'JSON' : 'Markdown'}
|
||||
|
||||
## Quality Checklist
|
||||
|
||||
- [ ] 输入验证通过
|
||||
- [ ] 核心逻辑执行成功
|
||||
- [ ] 输出格式正确
|
||||
|
||||
${nextPhase ?
|
||||
`## Next Phase\n\n→ [Phase ${index + 2}: ${nextPhase.name}](${nextPhase.id}.md)` :
|
||||
'## Completion\n\n此为最后阶段。'}
|
||||
`;
|
||||
}
|
||||
```
|
||||
144
.claude/skills/skill-generator/templates/skill-md.md
Normal file
144
.claude/skills/skill-generator/templates/skill-md.md
Normal file
@@ -0,0 +1,144 @@
|
||||
# SKILL.md Template
|
||||
|
||||
用于生成新 Skill 入口文件的模板。
|
||||
|
||||
## 模板结构
|
||||
|
||||
```markdown
|
||||
---
|
||||
name: {{skill_name}}
|
||||
description: {{description}}. Triggers on {{triggers}}.
|
||||
allowed-tools: {{allowed_tools}}
|
||||
---
|
||||
|
||||
# {{display_name}}
|
||||
|
||||
{{description}}
|
||||
|
||||
## Architecture Overview
|
||||
|
||||
\`\`\`
|
||||
{{architecture_diagram}}
|
||||
\`\`\`
|
||||
|
||||
## Key Design Principles
|
||||
|
||||
{{design_principles}}
|
||||
|
||||
## Execution Flow
|
||||
|
||||
{{execution_flow}}
|
||||
|
||||
## Directory Setup
|
||||
|
||||
\`\`\`javascript
|
||||
const timestamp = new Date().toISOString().slice(0,19).replace(/[-:T]/g, '');
|
||||
const workDir = `{{output_location}}`;
|
||||
|
||||
Bash(`mkdir -p "${workDir}"`);
|
||||
{{additional_dirs}}
|
||||
\`\`\`
|
||||
|
||||
## Output Structure
|
||||
|
||||
\`\`\`
|
||||
{{output_structure}}
|
||||
\`\`\`
|
||||
|
||||
## Reference Documents
|
||||
|
||||
{{reference_table}}
|
||||
```
|
||||
|
||||
## 变量说明
|
||||
|
||||
| 变量 | 类型 | 来源 |
|
||||
|------|------|------|
|
||||
| `{{skill_name}}` | string | config.skill_name |
|
||||
| `{{display_name}}` | string | config.display_name |
|
||||
| `{{description}}` | string | config.description |
|
||||
| `{{triggers}}` | string | config.triggers.join(", ") |
|
||||
| `{{allowed_tools}}` | string | config.allowed_tools.join(", ") |
|
||||
| `{{architecture_diagram}}` | string | 根据 execution_mode 生成 |
|
||||
| `{{design_principles}}` | string | 根据 execution_mode 生成 |
|
||||
| `{{execution_flow}}` | string | 根据 phases/actions 生成 |
|
||||
| `{{output_location}}` | string | config.output.location |
|
||||
| `{{additional_dirs}}` | string | 根据 execution_mode 生成 |
|
||||
| `{{output_structure}}` | string | 根据配置生成 |
|
||||
| `{{reference_table}}` | string | 根据文件列表生成 |
|
||||
|
||||
## 生成函数
|
||||
|
||||
```javascript
|
||||
function generateSkillMd(config) {
|
||||
const template = Read('templates/skill-md.md');
|
||||
|
||||
return template
|
||||
.replace(/\{\{skill_name\}\}/g, config.skill_name)
|
||||
.replace(/\{\{display_name\}\}/g, config.display_name)
|
||||
.replace(/\{\{description\}\}/g, config.description)
|
||||
.replace(/\{\{triggers\}\}/g, config.triggers.map(t => `"${t}"`).join(", "))
|
||||
.replace(/\{\{allowed_tools\}\}/g, config.allowed_tools.join(", "))
|
||||
.replace(/\{\{architecture_diagram\}\}/g, generateArchitecture(config))
|
||||
.replace(/\{\{design_principles\}\}/g, generatePrinciples(config))
|
||||
.replace(/\{\{execution_flow\}\}/g, generateFlow(config))
|
||||
.replace(/\{\{output_location\}\}/g, config.output.location)
|
||||
.replace(/\{\{additional_dirs\}\}/g, generateAdditionalDirs(config))
|
||||
.replace(/\{\{output_structure\}\}/g, generateOutputStructure(config))
|
||||
.replace(/\{\{reference_table\}\}/g, generateReferenceTable(config));
|
||||
}
|
||||
```
|
||||
|
||||
## Sequential 模式示例
|
||||
|
||||
```markdown
|
||||
---
|
||||
name: api-docs-generator
|
||||
description: Generate API documentation from source code. Triggers on "generate api docs", "api documentation".
|
||||
allowed-tools: Task, Read, Write, Glob, Grep, Bash
|
||||
---
|
||||
|
||||
# API Docs Generator
|
||||
|
||||
Generate API documentation from source code.
|
||||
|
||||
## Architecture Overview
|
||||
|
||||
\`\`\`
|
||||
┌─────────────────────────────────────────────────────────────────┐
|
||||
│ Phase 1: Scanning → endpoints.json │
|
||||
│ ↓ │
|
||||
│ Phase 2: Parsing → schemas.json │
|
||||
│ ↓ │
|
||||
│ Phase 3: Generation → api-docs.md │
|
||||
└─────────────────────────────────────────────────────────────────┘
|
||||
\`\`\`
|
||||
```
|
||||
|
||||
## Autonomous 模式示例
|
||||
|
||||
```markdown
|
||||
---
|
||||
name: task-manager
|
||||
description: Interactive task management with CRUD operations. Triggers on "manage tasks", "task list".
|
||||
allowed-tools: Task, AskUserQuestion, Read, Write
|
||||
---
|
||||
|
||||
# Task Manager
|
||||
|
||||
Interactive task management with CRUD operations.
|
||||
|
||||
## Architecture Overview
|
||||
|
||||
\`\`\`
|
||||
┌─────────────────────────────────────────────────────────────────┐
|
||||
│ Orchestrator (状态驱动决策) │
|
||||
└───────────────┬─────────────────────────────────────────────────┘
|
||||
│
|
||||
┌───────────┼───────────┬───────────┐
|
||||
↓ ↓ ↓ ↓
|
||||
┌───────┐ ┌───────┐ ┌───────┐ ┌───────┐
|
||||
│ List │ │Create │ │ Edit │ │Delete │
|
||||
└───────┘ └───────┘ └───────┘ └───────┘
|
||||
\`\`\`
|
||||
```
|
||||
Reference in New Issue
Block a user