# Workflow Init - Initialize BMM Project

<critical>The workflow execution engine is governed by: {project-root}/_bmad/core/tasks/workflow.xml</critical>
<critical>You MUST have already loaded and processed: {project-root}/_bmad/bmm/workflows/workflow-status/init/workflow.yaml</critical>
<critical>This workflow initializes a BMM project by determining project level, type, and creating the workflow path configuration.</critical>

<workflow>

<step n="1" goal="Check if project is already initialized">
  <action>Check if {workflow_path} exists</action>
  <check if="file exists">
    <output>项目已初始化！工作流路径配置文件已存在于: {workflow_path}</output>
    <ask>是否要重新初始化项目？(y/n)</ask>
    <check if="user response == 'n'">
      <action>Exit workflow</action>
    </check>
  </check>
</step>

<step n="2" goal="Determine project level">
  <output>
## 确定项目级别 (Project Level)

BMM 框架支持以下项目级别：

**Level 1 - Analysis (分析阶段)**
- 市场研究、技术调研、领域分析
- 产出：Product Brief、Research Reports

**Level 2 - Planning (规划阶段)**
- PRD、UX Design
- 产出：PRD Document、UX Design Specification

**Level 3 - Solutioning (解决方案阶段)**
- Architecture、Epics & Stories
- 产出：Architecture Document、Epics & Stories

**Level 4 - Implementation (实施阶段)**
- Sprint Planning、Development、Code Review
- 产出：Sprint Status、Story Files、Code Changes

  </output>
  <ask>请输入项目级别 (1-4):</ask>
  <action>Validate input is 1, 2, 3, or 4</action>
  <check if="invalid">
    <output>无效的级别，请输入 1-4 之间的数字</output>
    <goto step="2"/>
  </check>
  <action>Set {{level}} to user input</action>
</step>

<step n="3" goal="Determine project type">
  <output>
## 确定项目类型 (Project Type)

请选择项目类型：

**1 - Greenfield (全新项目)**
- 从零开始的新项目
- 无遗留代码约束

**2 - Brownfield (现有项目)**
- 在现有代码库基础上开发
- 需要考虑现有架构和模式

**3 - Migration (迁移项目)**
- 从其他框架/平台迁移
- 需要保持功能等价

**4 - Enhancement (增强项目)**
- 对现有项目进行功能增强
- 基于现有架构扩展

  </output>
  <ask>请输入项目类型 (1-4):</ask>
  <action>Validate input is 1, 2, 3, or 4</action>
  <check if="invalid">
    <output>无效的类型，请输入 1-4 之间的数字</output>
    <goto step="3"/>
  </check>
  <action>Set {{type}} to user input</action>
</step>

<step n="4" goal="Map level and type to workflow path">
  <action>Determine workflow path based on level and type</action>

  <output>
## 工作流路径配置

根据项目级别和类型，推荐的工作流路径：

  </output>

  <check if="{{level}} == 1">
    <output>
**Level 1 - Analysis Phase**
推荐工作流：
1. create-product-brief - 创建产品简介
2. research - 进行市场/技术/领域调研
    </output>
    <action>Set workflow_mode = "analysis"</action>
  </check>

  <check if="{{level}} == 2">
    <output>
**Level 2 - Planning Phase**
推荐工作流：
1. create-prd - 创建产品需求文档
2. create-ux-design - 设计 UX 模式
    </output>
    <action>Set workflow_mode = "planning"</action>
  </check>

  <check if="{{level}} == 3">
    <output>
**Level 3 - Solutioning Phase**
推荐工作流：
1. create-architecture - 创建架构文档
2. create-epics-and-stories - 分解 Epic 和 Story
3. check-implementation-readiness - 检查实施准备情况
    </output>
    <action>Set workflow_mode = "solutioning"</action>
  </check>

  <check if="{{level}} == 4">
    <output>
**Level 4 - Implementation Phase**
推荐工作流：
1. sprint-planning - Sprint 规划
2. create-story - 创建 Story
3. dev-story - 开发 Story
4. code-review - 代码审查
5. sprint-status - Sprint 状态查询
    </output>
    <action>Set workflow_mode = "implementation"</action>
  </check>

  <ask>确认此工作流路径？(y/n/edit)</ask>
  <check if="user response == 'edit'">
    <goto step="2"/>
  </check>
</step>

<step n="5" goal="Generate workflow path configuration">
  <template-output>
# BMM Workflow Path Configuration
# Generated: {{date}}
# Project: {project-root}

project_level: {{level}}
project_type: {{type}}
workflow_mode: {{workflow_mode}}

# Recommended workflows for this project level
recommended_workflows:
  </template-output>

  <check if="{{level}} == 1">
    <template-output>
  - create-product-brief
  - research
    </template-output>
  </check>

  <check if="{{level}} == 2">
    <template-output>
  - create-prd
  - create-ux-design
    </template-output>
  </check>

  <check if="{{level}} == 3">
    <template-output>
  - create-architecture
  - create-epics-and-stories
  - check-implementation-readiness
    </template-output>
  </check>

  <check if="{{level}} == 4">
    <template-output>
  - sprint-planning
  - create-story
  - dev-story
  - code-review
  - sprint-status
  - retrospective
  - correct-course
    </template-output>
  </check>

  <template-output>
# Level descriptions:
# Level 1 (analysis): Market research, technical research, domain analysis
# Level 2 (planning): PRD, UX Design
# Level 3 (solutioning): Architecture, Epics & Stories
# Level 4 (implementation): Sprint Planning, Development, Code Review

# Type descriptions:
# 1 (greenfield): New project from scratch
# 2 (brownfield): Existing codebase, consider existing patterns
# 3 (migration): Migrating from another framework/platform
# 4 (enhancement): Extending existing functionality
  </template-output>
</step>

<step n="6" goal="Save workflow path configuration">
  <action>Write template output to: {workflow_path}</action>
  <output>
## 初始化完成

工作流路径配置已保存到: {workflow_path}

项目级别: Level {{level}}
项目类型: Type {{type}} ({{project_type}})
工作流模式: {{workflow_mode}}

下一步建议：
  </output>

  <check if="{{level}} == 1">
    <output>
- 运行 `/bmad:bmm:workflows:create-product-brief` 创建产品简介
- 运行 `/bmad:bmm:workflows:research` 进行调研
    </output>
  </check>

  <check if="{{level}} == 2">
    <output>
- 运行 `/bmad:bmm:workflows:create-prd` 创建产品需求文档
- 运行 `/bmad:bmm:workflows:create-ux-design` 设计 UX
    </output>
  </check>

  <check if="{{level}} == 3">
    <output>
- 运行 `/bmad:bmm:workflows:create-architecture` 创建架构文档
- 运行 `/bmad:bmm:workflows:create-epics-and-stories` 分解 Epic 和 Story
    </output>
  </check>

  <check if="{{level}} == 4">
    <output>
- 运行 `/bmad:bmm:workflows:sprint-planning` 进行 Sprint 规划
- 运行 `/bmad:bmm:workflows:sprint-status` 查看当前状态
    </output>
  </check>

  <action>Report workflow completion</action>
</step>

</workflow>
