BMAD-METHOD/icsc/report/04-工作流程.md

888 lines
24 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 04 - BMAD-METHOD 工作流程详解
## 1. 工作流引擎设计
### 1.1 什么是工作流
**定义**: 工作流是一个结构化的、多步骤的引导过程,帮助用户完成特定任务。
**组成部分**:
```
Workflow (工作流)
├── workflow.yaml (配置)
├── instructions.md (步骤指令)
├── templates/ (输出模板)
├── data/ (参考数据 CSV)
└── sub-workflows/ (子工作流)
```
### 1.2 工作流 YAML 结构
**完整示例** (PRD 工作流):
```yaml
# 元数据
name: prd
description: "创建产品需求文档"
author: "BMad"
# 配置源和变量
config_source: "{project-root}/bmad/bmm/config.yaml"
project_name: "{config_source}:project_name"
output_folder: "{config_source}:output_folder"
user_name: "{config_source}:user_name"
communication_language: "{config_source}:communication_language"
document_output_language: "{config_source}:document_output_language"
date: system-generated
# 工作流组件路径
installed_path: "{project-root}/bmad/bmm/workflows/2-plan-workflows/prd"
instructions: "{installed_path}/instructions.md"
prd_template: "{installed_path}/prd-template.md"
# 输出文件
status_file: "{output_folder}/bmm-workflow-status.yaml"
default_output_file: "{output_folder}/PRD.md"
# 智能输入发现
input_file_patterns:
product_brief:
whole: "{output_folder}/*brief*.md"
sharded: "{output_folder}/*brief*/index.md"
research:
whole: "{output_folder}/*research*.md"
sharded: "{output_folder}/*research*/index.md"
# Web 打包配置
web_bundle:
name: "prd"
instructions: "bmad/bmm/workflows/2-plan-workflows/prd/instructions.md"
web_bundle_files:
- "bmad/bmm/workflows/2-plan-workflows/prd/instructions.md"
- "bmad/bmm/workflows/2-plan-workflows/prd/prd-template.md"
- "bmad/core/tasks/workflow.xml"
- "bmad/core/tasks/adv-elicit.xml"
child_workflows:
- create-epics-and-stories
```
### 1.3 路径占位符解析
**解析时机**: 工作流加载时
**占位符类型**:
```yaml
# 1. 项目路径
{project-root} → /home/user/my-project
{installed_path} → {project-root}/bmad/bmm/workflows/prd
# 2. 配置值
{config_source} → 配置文件路径
{config_source}:key → 从配置读取特定键值
{user_name} → "Alice" (从配置)
{output_folder} → "/home/user/my-project/docs"
# 3. 系统生成
{date} → "2025-11-09"
{timestamp} → "2025-11-09T10:30:00Z"
```
### 1.4 智能输入文档发现
**问题**: 如何处理文档可能完整或分片?
**解决方案**: 双层查找
```yaml
input_file_patterns:
product_brief:
whole: "{output_folder}/*brief*.md" # 优先
sharded: "{output_folder}/*brief*/index.md" # 降级
```
**查找逻辑**:
1. 尝试匹配 `whole` 模式(完整文档)
2. 如果没找到,尝试 `sharded` 模式(分片)
3. 如果都没有,提示用户或跳过
**好处**:
- 自动适应文档格式
- 无需用户手动指定
- 节省 token分片模式
---
## 2. 代理Agents工作原理
### 2.1 代理结构
**YAML 定义** (PM 代理示例):
```yaml
agent:
metadata:
id: "bmad/bmm/agents/pm.md"
name: "John"
title: "Product Manager"
icon: "📋"
module: "bmm"
persona:
role: "Investigative Product Strategist"
identity: "产品管理资深专家8+ 年经验..."
communication_style: "直接分析,善于提问..."
principles:
- "调查性思维..."
- "数据驱动决策..."
- "精确沟通..."
critical_actions:
- "加载配置 {project-root}/bmad/bmm/config.yaml"
- "记住用户名是 {user_name}"
- "始终使用 {communication_language} 沟通"
menu:
- trigger: "workflow-init"
workflow: "{project-root}/bmad/bmm/workflows/workflow-status/init/workflow.yaml"
description: "开始新的工作流路径"
- trigger: "create-prd"
workflow: "{project-root}/bmad/bmm/workflows/2-plan-workflows/prd/workflow.yaml"
description: "创建产品需求文档"
- trigger: "validate-prd"
validate-workflow: "{project-root}/bmad/bmm/workflows/2-plan-workflows/prd/workflow.yaml"
checklist: "{project-root}/bmad/bmm/workflows/2-plan-workflows/prd/checklist.md"
document: "{output_folder}/PRD.md"
description: "验证 PRD 完整性和质量"
```
### 2.2 代理编译过程
**从 YAML 到 Markdown**:
```
1. 读取 YAML 文件
└── src/modules/bmm/agents/pm.agent.yaml
2. 解析结构
├── 提取 metadata
├── 提取 persona
└── 提取 menu
3. 注入激活步骤
└── 从 utility/models/fragments/activation-steps.xml
4. 应用 IDE 处理器
├── Claude Code 处理器
├── Cursor 处理器
└── 其他 13 个 IDE
5. 生成 Markdown
└── bmad/bmm/agents/pm.md
6. 生成 IDE 工件
├── .claude/commands/bmad-bmm-agents-pm.md
├── .cursor/rules/bmad-bmm-agents-pm.md
└── 其他 IDE 目录
```
### 2.3 代理激活流程
**用户加载代理时**:
```
1. IDE 读取代理文件
└── bmad/bmm/agents/pm.md
2. 执行激活步骤
├── 加载 bmad/bmm/config.yaml
├── 设置运行时变量
│ ├── project_name
│ ├── user_name
│ ├── output_folder
│ └── communication_language
└── 显示代理菜单
3. 代理呈现角色
├── "我是 John产品经理..."
└── 根据 persona 定义交互
4. 显示菜单
├── 1. workflow-init - 开始新工作流
├── 2. create-prd - 创建 PRD
├── 3. validate-prd - 验证 PRD
└── ...
5. 等待用户指令
```
### 2.4 菜单触发机制
**用户可以通过多种方式触发**:
```
方式 1: 快捷命令
用户: "*create-prd"
代理: 执行 create-prd 工作流
方式 2: 自然语言
用户: "Let's create a PRD"
代理: 模糊匹配到 create-prd
方式 3: 菜单编号
用户: "Run option 2"
代理: 执行菜单第 2 项
方式 4: 直接斜杠命令(绕过代理)
用户: "/bmad:bmm:workflows:prd"
IDE: 直接加载工作流
```
---
## 3. 工作流执行流程
### 3.1 完整执行周期
```
┌─────────────────────────────────────────┐
│ 1. 工作流触发 │
│ 用户: "*create-prd" │
└─────────────────────────────────────────┘
┌─────────────────────────────────────────┐
│ 2. 加载工作流配置 │
│ ├── 读取 workflow.yaml │
│ ├── 解析占位符 │
│ └── 加载配置文件 │
└─────────────────────────────────────────┘
┌─────────────────────────────────────────┐
│ 3. 发现输入文档 │
│ ├── 检查 product-brief.md │
│ ├── 检查 market-research.md │
│ └── 检查分片版本 │
└─────────────────────────────────────────┘
┌─────────────────────────────────────────┐
│ 4. 加载工作流组件 │
│ ├── instructions.md (步骤指令) │
│ ├── prd-template.md (输出模板) │
│ ├── data/*.csv (参考数据) │
│ └── 任务调用 (adv-elicit, workflow) │
└─────────────────────────────────────────┘
┌─────────────────────────────────────────┐
│ 5. AI 代理执行 │
│ ├── 读取 instructions.md │
│ ├── 应用引导方法 │
│ ├── 与用户互动 │
│ ├── 收集需求 │
│ └── 应用 template.md │
└─────────────────────────────────────────┘
┌─────────────────────────────────────────┐
│ 6. 生成输出 │
│ ├── 写入 docs/PRD.md │
│ ├── 更新 bmm-workflow-status.yaml │
│ └── 调用子工作流 (create-epics) │
└─────────────────────────────────────────┘
┌─────────────────────────────────────────┐
│ 7. 验证和完成 │
│ ├── 检查输出完整性 │
│ ├── 提示后续步骤 │
│ └── 返回控制给用户 │
└─────────────────────────────────────────┘
```
### 3.2 指令文档结构
**instructions.md 典型结构**:
```markdown
# PRD Workflow Instructions
## Activation Steps
1. Load configuration from {project-root}/bmad/bmm/config.yaml
2. Set project_name, user_name, output_folder
3. Load input documents (if available)
## Workflow Steps
### Step 1: Context Gathering
<invoke-task name="adv-elicit" method="Socratic Questioning">
Ask the user:
- What problem are we solving?
- Who are the target users?
- What are the key objectives?
</invoke-task>
### Step 2: Requirements Elicitation
<invoke-task name="adv-elicit" method="Five Whys">
For each requirement:
- Why is this important?
- What happens if we don't do it?
- How will we measure success?
</invoke-task>
### Step 3: Epic Breakdown
<invoke-task name="workflow">
Review all requirements and:
1. Group related features into Epics
2. Define Epic goals and scope
3. Estimate complexity (Story points)
</invoke-task>
### Step 4: Document Generation
Apply the PRD template:
- Load {prd_template}
- Fill in all sections
- Use {document_output_language}
- Save to {default_output_file}
### Step 5: Call Sub-Workflow
<invoke-task name="workflow" sub-workflow="create-epics-and-stories">
Break down Epics into implementable Stories
</invoke-task>
## Output Validation
- Check PRD completeness
- Verify Epic coverage
- Update workflow status
```
### 3.3 任务调用机制
**内置任务**:
#### `<invoke-task name="adv-elicit">`
**用途**: 高级引导提问
**方法** (36 种):
```
- Socratic Questioning (苏格拉底提问)
- Five Whys (5个为什么)
- SWOT Analysis (SWOT 分析)
- Lateral Thinking (横向思维)
- Devil's Advocate (魔鬼代言人)
...
```
**示例**:
```markdown
<invoke-task name="adv-elicit" method="Socratic Questioning">
Ask strategic questions to help the user discover:
- Root causes of the problem
- Hidden assumptions
- Alternative perspectives
</invoke-task>
```
#### `<invoke-task name="workflow">`
**用途**: 通用工作流任务
**功能**:
- 读取/写入文档
- 状态跟踪
- 子工作流调用
- 数据转换
**示例**:
```markdown
<invoke-task name="workflow" sub-workflow="create-epics-and-stories">
Break down the PRD into Epic and Story structure
</invoke-task>
```
---
## 4. 代理-工作流-模块关系
### 4.1 关系图
```
用户意图
代理菜单
├── PM 代理
│ ├── *workflow-init → workflow-status/init/
│ ├── *create-prd → 2-plan-workflows/prd/
│ ├── *tech-spec → 2-plan-workflows/tech-spec/
│ └── *validate-prd → 验证逻辑
├── Architect 代理
│ ├── *create-architecture → 3-solutioning/architecture/
│ └── *solutioning-gate-check → 3-solutioning/gate-check/
└── Developer 代理
├── *dev-story → 4-implementation/dev-story/
└── *story-review → 4-implementation/story-review/
工作流执行
├── 加载配置
├── 发现输入
├── 执行指令
└── 生成输出
模块数据
├── BMM 配置 (bmad/bmm/config.yaml)
├── 输出文档 (docs/)
└── 状态文件 (bmm-workflow-status.yaml)
```
### 4.2 跨代理工作流
**场景**: PRD → Architecture → Sprint Planning
```
阶段 1: PM 创建 PRD
├── 代理: PM (John)
├── 工作流: create-prd
├── 输出: docs/PRD.md, docs/Epics.md
└── 状态: Phase 2 完成
阶段 2: Architect 设计架构
├── 代理: Architect (Winston)
├── 工作流: create-architecture
├── 输入: docs/PRD.md (读取需求)
├── 输出: docs/architecture.md
└── 状态: Phase 3 完成
阶段 3: Architect 验证一致性
├── 代理: Architect (Winston)
├── 工作流: solutioning-gate-check
├── 输入: PRD.md + architecture.md + Epics.md
├── 验证: 所有文档对齐
└── 状态: 可以开始实现
阶段 4: SM 规划 Sprint
├── 代理: Scrum Master (Bob)
├── 工作流: sprint-planning
├── 输入: Epics.md (读取 Epic 列表)
├── 输出: sprint-status.yaml
└── 状态: Sprint 开始
阶段 5: SM 创建 Story
├── 代理: Scrum Master (Bob)
├── 工作流: create-story
├── 输入: Epics.md + architecture.md
├── 输出: Story-001.md
└── 状态: Story drafted
阶段 6: Developer 实现 Story
├── 代理: Developer (Amelia)
├── 工作流: dev-story
├── 输入: Story-001.md + Epic-context.md
├── 活动: 编码 + 测试
└── 状态: Story done
```
**关键点**:
- 工作流通过文件系统传递数据
- 每个代理专注自己的职责
- 状态文件跟踪整体进度
- Just-in-Time 加载减少 token
---
## 5. 实际使用场景
### 5.1 场景 1: Bug 修复 (Quick Flow)
**用户目标**: 修复登录页面的验证 Bug
**流程**:
```
1. 初始化 (Analyst)
用户: "*workflow-init"
代理: "这是一个 Bug 还是新功能?"
用户: "Bug 修复"
代理: "推荐 Quick Flow Track"
2. 技术规格 (PM)
用户: "*tech-spec"
代理: "描述 Bug 现象和期望行为"
用户: [描述详细]
输出: tech-spec.md (包含 3 个 Story)
3. Sprint 规划 (SM)
用户: "*sprint-planning"
代理: "选择本 Sprint 的 Story"
用户: [选择所有]
输出: sprint-status.yaml
4. 实现 Story (Developer)
用户: "*dev-story"
代理: "读取 Story-001开始实现..."
活动: 修复代码、测试
输出: 代码提交 + Story 标记为 done
5. 重复步骤 4 (剩余 2 个 Story)
6. 完成
总时间: 4-8 小时
```
### 5.2 场景 2: 新产品 (BMad Method)
**用户目标**: 构建一个 SaaS 项目管理工具
**流程**:
```
Phase 1: 分析 (可选但推荐)
├── 1.1 头脑风暴 (Analyst)
│ 用户: "*brainstorm-project"
│ 代理: 引导创意探索
│ 输出: 初步想法
│ 时间: 2 小时
├── 1.2 产品简报 (Analyst)
│ 用户: "*product-brief"
│ 代理: 定义产品愿景和范围
│ 输出: product-brief.md
│ 时间: 4 小时
└── 1.3 市场研究 (Analyst, 可选)
用户: "*market-research"
输出: market-research.md
时间: 8 小时
Phase 2: 规划 (必需)
├── 2.1 PRD (PM)
│ 用户: "*create-prd"
│ 代理: 引导需求定义
│ 输入: product-brief.md (自动发现)
│ 输出: PRD.md + Epics.md (15 个 Epic)
│ 时间: 12 小时
└── 2.2 UX 设计 (UX Designer, 可选)
用户: "*create-ux-design"
输出: ux-design.md
时间: 16 小时
Phase 3: 方案 (必需)
├── 3.1 架构设计 (Architect)
│ 用户: "*create-architecture"
│ 输入: PRD.md (自动读取)
│ 输出: architecture.md
│ 时间: 20 小时
└── 3.2 方案验证 (Architect)
用户: "*solutioning-gate-check"
验证: PRD ↔ Architecture ↔ Epics
时间: 2 小时
Phase 4: 实现 (迭代)
├── 4.1 Sprint 规划 (SM)
│ 用户: "*sprint-planning"
│ 输出: sprint-status.yaml
│ 时间: 2 小时
├── 4.2 Epic 上下文 (SM, 每个 Epic)
│ 用户: "*epic-tech-context"
│ 输入: architecture.md + Epic 定义
│ 输出: Epic-auth-context.md
│ 时间: 3 小时
├── 4.3 Story 循环 (每个 Story)
│ │
│ ├── 4.3.1 创建 Story (SM)
│ │ 用户: "*create-story"
│ │ 输出: Story-001.md (drafted)
│ │ 时间: 30 分钟
│ │
│ ├── 4.3.2 Story 就绪检查 (SM)
│ │ 用户: "*story-ready"
│ │ 状态: drafted → ready
│ │ 时间: 15 分钟
│ │
│ ├── 4.3.3 Story 上下文 (SM, 可选)
│ │ 用户: "*story-context"
│ │ 输出: Story-001-context.md
│ │ 时间: 1 小时
│ │
│ ├── 4.3.4 实现 Story (Developer)
│ │ 用户: "*dev-story"
│ │ 输入: Story-001.md + Epic-context.md
│ │ 活动: 编码、测试、文档
│ │ 状态: ready → in-progress → done
│ │ 时间: 4-8 小时
│ │
│ └── 4.3.5 Code Review (Developer, 可选)
│ 用户: "*story-review"
│ 验证: 代码质量、测试覆盖
│ 时间: 1 小时
└── 4.4 Sprint 回顾 (SM)
用户: "*sprint-retrospective"
输出: retrospective.md
时间: 2 小时
总时间:
- 规划: 2 周
- 实现: 12-24 周 (取决于规模)
```
### 5.3 场景 3: 游戏开发 (BMGD + BMM)
**用户目标**: 开发一个 2D 平台跳跃游戏
**流程**:
```
Preproduction (Game Designer)
├── *brainstorm-game
│ └── 使用 CIS brainstorming
├── *game-brief
│ └── 输出: game-brief.md
└── 时间: 1 周
Design (Game Designer)
├── *gdd (Game Design Document)
│ ├── 核心机制
│ ├── 关卡设计
│ └── 角色定义
├── *narrative
│ └── 故事和世界观
└── 时间: 2-3 周
Technical (Game Architect)
├── *game-architecture
│ ├── Unity 项目结构
│ ├── 状态机设计
│ └── 资源管线
└── 时间: 1 周
Production (使用 BMM Sprint)
├── Sprint 1: 核心移动系统
│ ├── Epic: Player Movement
│ ├── Story: 左右移动
│ ├── Story: 跳跃
│ └── Story: 碰撞检测
├── Sprint 2: 关卡系统
│ ├── Epic: Level Design
│ ├── Story: 关卡加载
│ ├── Story: 敌人生成
│ └── Story: 道具系统
└── ... (更多 Sprint)
总时间: 16-24 周
```
---
## 6. 高级特性
### 6.1 Document Sharding (文档分片)
**问题**: 大项目的 PRD 可能超过 50KB消耗大量 token
**解决方案**: 自动分片
```
docs/PRD.md (50KB, 原始)
↓ [使用 shard-doc 工具]
docs/PRD/
├── index.md (目录和总览)
├── 01-overview.md (5KB)
├── 02-requirements.md (10KB)
├── 03-epics.md (15KB)
└── 04-nfr.md (8KB)
```
**工作流自动处理**:
```yaml
input_file_patterns:
prd:
whole: "{output_folder}/PRD.md" # 优先
sharded: "{output_folder}/PRD/index.md" # 降级
```
**Phase 4 Story 实现时**:
- 只加载 PRD/03-epics.md 中相关 Epic
- 节省 90%+ token
- 更快的处理速度
### 6.2 Just-in-Time Context
**原则**: 只在需要时加载相关信息
**实现 Story 时加载的上下文**:
```
Story-001 实现时加载:
├── Story-001.md (Story 定义)
├── Epic-auth-context.md (Epic 技术指导)
├── Story-001-context.md (Story 实现细节)
└── architecture.md 的相关部分 (特定技术决策)
不加载:
├── PRD.md 全文 ❌
├── 其他 Epic 的信息 ❌
└── UX 设计全文 ❌
```
**好处**:
- Token 节省 90%+
- AI 更专注
- 处理更快
### 6.3 多代理 Party Mode
**触发**:
```
方式 1: BMad Master
用户: 加载 BMad Master
用户: "*party-mode"
方式 2: 直接斜杠命令
用户: /bmad:core:workflows:party-mode
```
**执行**:
```
1. Party Mode 工作流启动
2. 扫描所有已安装代理
├── BMM: PM, Analyst, Architect, SM, Dev, TEA
├── CIS: Carson, Maya, Dr. Quinn, Victor, Sophia
├── BMGD: Game Designer, Game Dev
└── BMB: BMad Builder
3. 所有代理加入对话
4. 用户提出问题或任务
5. 代理们协作讨论
├── PM: "从产品角度..."
├── Architect: "技术上我们需要..."
├── Carson: "让我们头脑风暴一下..."
└── Game Designer: "游戏机制应该..."
6. 综合输出多角度建议
```
**最佳使用场景**:
- 战略规划(需要多领域输入)
- 创意探索(需要发散思维)
- 架构评审(需要多角度审视)
- 复杂问题(没有明显答案)
---
## 7. 状态跟踪系统
### 7.1 bmm-workflow-status.yaml
**用途**: 跟踪整体工作流进度
**结构**:
```yaml
project:
name: "My SaaS Project"
track: "bmad-method" # quick-flow / bmad-method / enterprise
phases:
phase1_analysis:
status: "completed"
workflows:
- brainstorm-project: "completed"
- product-brief: "completed"
- market-research: "skipped"
phase2_planning:
status: "completed"
workflows:
- prd: "completed"
- create-epics-and-stories: "completed"
- create-ux-design: "completed"
phase3_solutioning:
status: "completed"
workflows:
- architecture: "completed"
- solutioning-gate-check: "completed"
phase4_implementation:
status: "in-progress"
current_sprint: 1
workflows:
- sprint-planning: "completed"
- epic-tech-context: "in-progress"
recommendations:
next_workflow: "epic-tech-context"
next_agent: "sm"
reason: "需要为第一个 Epic 创建技术上下文"
```
### 7.2 sprint-status.yaml
**用途**: 跟踪 Sprint 和 Story 状态
**结构**:
```yaml
project:
name: "My SaaS Project"
current_sprint: 1
sprint_start: "2025-11-01"
sprint_end: "2025-11-15"
epics:
- id: "epic-001"
name: "User Authentication"
status: "in-progress"
selected_for_sprint: true
stories:
- id: "story-001"
title: "User Login"
status: "done"
assigned: "2025-11-02"
completed: "2025-11-05"
- id: "story-002"
title: "User Registration"
status: "in-progress"
assigned: "2025-11-05"
- id: "story-003"
title: "Password Reset"
status: "ready"
- id: "epic-002"
name: "Dashboard"
status: "backlog"
selected_for_sprint: false
velocity:
current_sprint_points: 21
completed_points: 8
remaining_points: 13
```
**代理使用**:
- **SM**: 读取状态,决定下一个 Story
- **Developer**: 读取当前 Story 详情
- **所有代理**: 了解项目整体进度
---
## 8. 小结
BMAD 工作流系统的特点:
**配置驱动** - YAML 定义,灵活可扩展
**智能加载** - 自动发现输入,支持分片
**代理协同** - 清晰的职责分工
**状态跟踪** - 始终知道"下一步做什么"
**Token 优化** - Just-in-Time Context, Document Sharding
**多代理协作** - Party Mode 支持复杂决策
**下一步**: 阅读 [05-企业应用方案.md](./05-企业应用方案.md) 了解如何应用于企业