docs: 添加 v0.5 动态编排设计
- 创建 Main + Sub Agent 动态编排方案 - Main Agent 作为编排者,根据任务需要动态安排 Sub Agents - Sub Agents 分为 Execute、Review、Test 专业角色 - 不是固化工作流,而是 Main 根据需求灵活调整 - 添加上下文隔离原则 - 创建工作流脚本模板 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,174 @@
|
||||
/**
|
||||
* Feature Development Workflow
|
||||
*
|
||||
* 使用 Main + Sub Agent 架构完成功能开发
|
||||
*
|
||||
* 用法: Agent({ scriptPath: ".claude/workflows/feature-development.js", args: "实现用户认证功能" })
|
||||
*/
|
||||
|
||||
export const meta = {
|
||||
name: 'feature-development',
|
||||
description: 'Main Agent 协调 Sub Agent 完成功能开发',
|
||||
phases: [
|
||||
{ title: '分析需求', detail: 'Main Agent 分析并拆分任务' },
|
||||
{ title: '执行开发', detail: 'Executor Sub Agent 编写代码和测试' },
|
||||
{ title: '代码审查', detail: 'Reviewer Sub Agent 审查代码质量' },
|
||||
{ title: '整合验收', detail: 'Main Agent 整合结果并验收' }
|
||||
]
|
||||
}
|
||||
|
||||
// 工作流主逻辑
|
||||
export default async function (feature) {
|
||||
phase('分析需求')
|
||||
|
||||
log(`📋 功能需求: ${feature}`)
|
||||
|
||||
// Main Agent 分析需求
|
||||
const analysis = await agent(`
|
||||
作为架构师,分析以下功能需求:
|
||||
|
||||
"${feature}"
|
||||
|
||||
请提供:
|
||||
1. 技术方案概述
|
||||
2. 需要的文件列表
|
||||
3. Executor 任务描述
|
||||
4. Reviewer 审查点
|
||||
|
||||
返回结构化 JSON:
|
||||
{
|
||||
"approach": "技术方案概述",
|
||||
"files": ["预计需要的文件"],
|
||||
"executorTask": "详细任务描述",
|
||||
"reviewPoints": ["审查要点"]
|
||||
}
|
||||
`, { schema: AnalysisSchema })
|
||||
|
||||
log(`✅ 分析完成: ${analysis.approach}`)
|
||||
|
||||
phase('执行开发')
|
||||
|
||||
// 指派 Executor Sub Agent
|
||||
const executorResult = await agent(`
|
||||
作为后端开发专家,执行以下任务:
|
||||
|
||||
${analysis.executorTask}
|
||||
|
||||
技术要求:
|
||||
- 使用项目现有代码风格
|
||||
- 编写完整的单元测试
|
||||
- 测试覆盖率 > 80%
|
||||
|
||||
完成后返回结构化 JSON:
|
||||
{
|
||||
"files": ["修改的文件列表"],
|
||||
"tests": "测试结果",
|
||||
"changes": "主要改动说明",
|
||||
"status": "完成|部分完成|失败"
|
||||
}
|
||||
`, {
|
||||
label: 'Executor',
|
||||
schema: ExecutorResultSchema
|
||||
})
|
||||
|
||||
log(`✅ Executor 完成: ${executorResult.status}`)
|
||||
log(`📁 修改文件: ${executorResult.files.join(', ')}`)
|
||||
|
||||
phase('代码审查')
|
||||
|
||||
// 指派 Reviewer Sub Agent
|
||||
const reviewResult = await agent(`
|
||||
作为代码审查专家,审查以下改动:
|
||||
|
||||
文件: ${executorResult.files.join(', ')}
|
||||
改动: ${executorResult.changes}
|
||||
|
||||
审查要点:
|
||||
${analysis.reviewPoints.map(p => `- ${p}`).join('\n')}
|
||||
|
||||
检查项目:
|
||||
1. 代码质量和可读性
|
||||
2. 测试覆盖是否充分
|
||||
3. 是否有潜在的 bug
|
||||
4. 安全性考虑
|
||||
5. 性能影响
|
||||
|
||||
返回结构化 JSON:
|
||||
{
|
||||
"findings": ["发现的问题"],
|
||||
"severity": "low|medium|high|critical",
|
||||
"approval": true|false,
|
||||
"suggestions": ["改进建议"]
|
||||
}
|
||||
`, {
|
||||
label: 'Reviewer',
|
||||
schema: ReviewResultSchema
|
||||
})
|
||||
|
||||
log(`📊 审查结果: ${reviewResult.approval ? '✅ 通过' : '❌ 需修改'}`)
|
||||
|
||||
if (reviewResult.findings.length > 0) {
|
||||
log(`⚠️ 发现 ${reviewResult.findings.length} 个问题:`)
|
||||
reviewResult.findings.forEach(f => log(` - ${f}`))
|
||||
}
|
||||
|
||||
phase('整合验收')
|
||||
|
||||
// Main Agent 整合结果
|
||||
const final = {
|
||||
feature,
|
||||
approach: analysis.approach,
|
||||
files: executorResult.files,
|
||||
tests: executorResult.tests,
|
||||
review: reviewResult,
|
||||
status: reviewResult.approval ? '完成' : '需修改'
|
||||
}
|
||||
|
||||
log(`🎯 最终状态: ${final.status}`)
|
||||
|
||||
return final
|
||||
}
|
||||
|
||||
// JSON Schema 定义
|
||||
const AnalysisSchema = {
|
||||
type: "object",
|
||||
properties: {
|
||||
approach: { type: "string", description: "技术方案概述" },
|
||||
files: { type: "array", items: { type: "string" }, description: "预计需要的文件" },
|
||||
executorTask: { type: "string", description: "详细任务描述" },
|
||||
reviewPoints: { type: "array", items: { type: "string" }, description: "审查要点" }
|
||||
},
|
||||
required: ["approach", "files", "executorTask", "reviewPoints"]
|
||||
}
|
||||
|
||||
const ExecutorResultSchema = {
|
||||
type: "object",
|
||||
properties: {
|
||||
files: { type: "array", items: { type: "string" }, description: "修改的文件列表" },
|
||||
tests: { type: "string", description: "测试结果" },
|
||||
changes: { type: "string", description: "主要改动说明" },
|
||||
status: { type: "string", enum: ["完成", "部分完成", "失败"], description: "执行状态" }
|
||||
},
|
||||
required: ["files", "tests", "changes", "status"]
|
||||
}
|
||||
|
||||
const ReviewResultSchema = {
|
||||
type: "object",
|
||||
properties: {
|
||||
findings: { type: "array", items: { type: "string" }, description: "发现的问题" },
|
||||
severity: { type: "string", enum: ["low", "medium", "high", "critical"], description: "严重程度" },
|
||||
approval: { type: "boolean", description: "是否通过审查" },
|
||||
suggestions: { type: "array", items: { type: "string" }, description: "改进建议" }
|
||||
},
|
||||
required: ["findings", "severity", "approval", "suggestions"]
|
||||
}
|
||||
|
||||
// 导出 phase 函数供脚本使用
|
||||
function phase(title) {
|
||||
// 在实际使用中,这会被 Workflow 工具的 phase() 替换
|
||||
console.log(`\n=== ${title} ===`)
|
||||
}
|
||||
|
||||
function log(message) {
|
||||
console.log(message)
|
||||
}
|
||||
Reference in New Issue
Block a user