关于 bad
BAD 是用于协调 BMad 自主开发流程的 Agent 技能,通过子 Agent 推进依赖分析、故事开发、评审及 PR 流程。它按故事状态和阶段顺序安排工作,并支持并行处理故事。
主要功能
- 01通过子 Agent 协调开发步骤
- 02构建并更新故事依赖图
- 03按阶段顺序推进故事流程
- 04在允许时并行处理多个故事
- 05跟踪 PR、CI 与合并状态
适用场景
- 01协调多个故事的开发与审查
- 02依据依赖关系选择可启动的故事
- 03为新 Epic 安排测试设计
- 04跟踪批次的 PR、CI 和后续处理
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ stephenleo/ bmad-autonomous-development --skill bad安装后在 Claude Code 中输入/bad确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
assets/bad-statusline.shmodule-help.csvmodule-setup.mdmodule.yamlreferences/coordinator/gate-pre-continuation.mdpattern-gh-curl-fallback.mdpattern-monitor.mdpattern-notify.mdpattern-timer.mdpattern-watchdog.mdsetup-statusline-hook.mdreferences/subagents/phase0-graph.mdphase0-prompt.mdphase3-cleanup.mdphase3-merge.mdphase4-assessment.mdstep6-ci-fallback.mdscripts/merge-config.pymerge-help-csv.pysetup-activity-hook.py详细介绍
BAD — BMad 自主开发
激活时
检查 {project-root}/_bmad/config.yaml 是否包含 bad 部分。如果没有,或者用户将 setup 或 configure 作为参数传入,则加载 ./assets/module-setup.md,并在继续之前完成注册。
即使模块已注册,setup/configure 参数也始终会触发加载 ./assets/module-setup.md(用于重新配置)。
完成设置后(或配置已存在时),加载 bad 配置,然后继续执行下方的启动流程。
你是协调器。你要通过 Agent 工具将每一步委派给子 Agent。你绝不会亲自读取文件、运行 git/gh 命令或写入磁盘。
协调器专属职责:
- 根据子 Agent 报告的数据选择故事
- 调用 Agent 工具以生成子 Agent(在允许时并行调用——在同一条消息中多次调用 Agent 工具)
- 管理计时器(CronCreate / CronDelete)
- 执行继续前检查(需要会话 stdin JSON——仅限协调器执行)
- 处理用户输入、输出摘要并发送频道通知
其他所有事项——读取文件、执行 git 操作、运行 gh 命令、写入磁盘——都由拥有全新上下文窗口的 Agent 工具子 Agent 完成。
启动:捕获频道上下文
在进行任何其他操作之前,确定如何发送通知:
-
检查是否连接了频道——查看当前对话上下文:
- 如果看到
<channel source="telegram" chat_id="..." ...>标签,则保存NOTIFY_CHAT_ID和NOTIFY_SOURCE="telegram"。 - 如果连接了其他类型的频道,则保存其对应的标识符。
- 如果未连接频道,则设置
NOTIFY_SOURCE="terminal"。
- 如果看到
-
发送 BAD 已启动通知,使用通知模式:
🤖 BAD started — building dependency graph...
然后继续执行阶段 0。
Configuration
启动时从 _bmad/config.yaml 的 bad 部分加载基础值。然后解析传递给 /bad 的参数中的任意 KEY=VALUE 覆盖项——参数优先于配置。对于未在配置或参数中设置的变量,使用下表中的默认值。
| 变量 | 配置键 | 默认值 | 说明 |
|---|---|---|---|
MAX_PARALLEL_STORIES | max_parallel_stories | 3 | 单个批次中运行的最大故事数 |
WORKTREE_BASE_PATH | worktree_base_path | .worktrees | Git worktree 的根目录 |
MODEL_STANDARD | model_standard | sonnet | 除步骤 5(代码审查)外,所有子 Agent 使用的模型:阶段 0、阶段 1 Epic-Start、步骤 1–4 和 6–7、阶段 3(合并 + 清理)、阶段 4(评估 + 回顾) |
MODEL_QUALITY | model_quality | opus | 步骤 5(代码审查)使用的模型 |
RETRO_TIMER_SECONDS | retro_timer_seconds | 600 | Epic 完成后的自动回顾倒计时(10 分钟) |
WAIT_TIMER_SECONDS | wait_timer_seconds | 3600 | 批次完成后等待一段时间,再重新检查 PR 状态(1 小时) |
CONTEXT_COMPACTION_THRESHOLD | context_compaction_threshold | 80 | 压缩/总结上下文时所对应的上下文窗口占用百分比 |
STALE_TIMEOUT_MINUTES | stale_timeout_minutes | 60 | 子 Agent 不活动多少分钟后由 watchdog 发出提醒(0 = 禁用) |
TIMER_SUPPORT | timer_support | true | 为 true 时使用平台原生计时器;为 false 时使用基于提示词的续接方式 |
MONITOR_SUPPORT | monitor_support | true | 为 true 时使用 Monitor 工具轮询 CI 和 PR 合并状态;为 false 时回退到手动轮询循环(Bedrock/Vertex/Foundry 必需) |
API_FIVE_HOUR_THRESHOLD | api_five_hour_threshold | 80 | (Claude Code)触发暂停的 5 小时速率限制百分比 |
API_SEVEN_DAY_THRESHOLD | api_seven_day_threshold | 95 | (Claude Code)触发暂停的 7 天速率限制百分比 |
API_USAGE_THRESHOLD | api_usage_threshold | 80 | (其他工具环境)触发暂停的通用 API 使用率百分比 |
RUN_CI_LOCALLY | run_ci_locally | false | 为 true 时,跳过 GitHub Actions,始终运行本地 CI 回退方案 |
AUTO_PR_MERGE | auto_pr_merge | false | 为 true 时,在阶段 4 之前按顺序自动合并批次 PR(从最低到最高) |
解析完所有值后,打印当前生效的配置,以便用户在阶段 0 开始前确认:
⚙️ BAD config: MAX_PARALLEL_STORIES=3, RUN_CI_LOCALLY=false, AUTO_PR_MERGE=false, MODEL_STANDARD=sonnet, MODEL_QUALITY=opus, TIMER_SUPPORT=true, ...
Pipeline
Phase 0: Build (or update) dependency graph [subagent]
└─ bmad-help maps story dependencies
└─ GitHub updates PR merge status per story
└─ git pull origin main
└─ Reports: ready stories, epic completion status
│
Phase 1: Discover stories [coordinator logic]
└─ Pick up to MAX_PARALLEL_STORIES from Phase 0 report
└─ If new epic → Epic-Start Test Design [subagent, blocking]
└─ If none ready → skip to Phase 4
│
Phase 2: Run the pipeline [subagents — stories parallel, steps sequential]
├─► Story A ──► Step 1 → Step 2 → Step 3 → Step 4 → Step 5 → Step 6 → Step 7
├─► Story B ──► Step 1 → Step 2 → Step 3 → Step 4 → Step 5 → Step 6 → Step 7
└─► Story C ──► Step 1 → Step 2 → Step 3 → Step 4 → Step 5 → Step 6 → Step 7
│
Phase 3: Auto-Merge Batch PRs [subagents — sequential]
└─ One subagent per story (lowest → highest story number)
└─ Cleanup subagent for branch safety + git pull
│
Phase 4: Batch Completion & Continuation
└─ Print batch summary [coordinator]
└─ Epic completion check [subagent]
└─ Optional retrospective [subagent]
└─ Gate & Continue (WAIT_TIMER timer) → Phase 0 → Phase 1
阶段 0:构建或更新依赖关系图
启动子 Agent 前,使用 TaskCreate 创建完整的初始任务列表,让用户一目了然地看到整个工作流。将阶段 0 标记为 in_progress;其他任务均以 [ ] 开始。在创建时应用阶段 3 规则:
[in_progress] Phase 0: Dependency graph
[ ] Phase 1: Story selection
[ ] Phase 2: Step 1 — Create story
[ ] Phase 2: Step 2 — ATDD
[ ] Phase 2: Step 3 — Develop
[ ] Phase 2: Step 4 — Test review
[ ] Phase 2: Step 5 — Code review
[ ] Phase 2: Step 6 — PR + CI
[ ] Phase 2: Step 7 — PR review
[ ] Phase 3: Auto-merge ← if AUTO_PR_MERGE=true
[completed] Phase 3: Auto-merge — skipped (AUTO_PR_MERGE=false) ← if AUTO_PR_MERGE=false
[ ] Phase 4: Batch summary + continuation
使用 model: MODEL_STANDARD、description: "Phase 0: dependency graph" 调用 Agent 工具,并提供以下提示词。协调器等待报告。
Read `references/subagents/phase0-prompt.md` and follow its instructions exactly.
协调器根据报告推进阶段 1。协调器不在本地读取文件。
📣 通知(阶段 0 完成后):
📊 Phase 0 complete
Ready: {N} stories — {comma-separated story numbers}
Blocked: {N} stories (if any)
阶段 0 完成后,按正确的执行顺序重建任务列表——任务按创建顺序显示,因此请删除并重新添加任务,以确保阶段 2 的故事任务显示在阶段 3 和阶段 4 之前:
- 将
Phase 0: Dependency graph标记为completed - 将
Phase 1: Story selection标记为completed(已完成) - 删除所有九个通用启动任务:七个
Phase 2: Step N任务、Phase 3: Auto-merge和Phase 4: Batch summary + continuation - 使用 TaskCreate 按执行顺序重新添加:
[ ] Phase 1: Epic-Start Test Design ← add once if new epic, before all story tasks
[ ] Phase 2 | Story {N}: Step 1 — Create story ← one set per selected story, all stories first
[ ] Phase 2 | Story {N}: Step 2 — ATDD
[ ] Phase 2 | Story {N}: Step 3 — Develop
[ ] Phase 2 | Story {N}: Step 4 — Test review
[ ] Phase 2 | Story {N}: Step 5 — Code review
[ ] Phase 2 | Story {N}: Step 6 — PR + CI
[ ] Phase 2 | Story {N}: Step 7 — PR review
← repeat for each story in the batch
[ ] Phase 3: Auto-merge ← if AUTO_PR_MERGE=true
[completed] Phase 3: Auto-merge — skipped (AUTO_PR_MERGE=false) ← if AUTO_PR_MERGE=false
[ ] Phase 4: Batch summary + continuation
启动子 Agent 时,将每个故事步骤任务更新为 in_progress;子 Agent 返回报告后,将其更新为 completed(或 failed)。阶段 3 和阶段 4 的任务也应在执行过程中相应更新。
阶段 1:发现故事
纯协调器逻辑 — 不读取文件,不调用工具。
- 从阶段 0 的
ready_stories报告中,最多选择MAX_PARALLEL_STORIES个故事。- 严格执行史诗顺序: 只能选择最早未完成史诗中的故事。如果史诗 N-1(或更早)的任何故事尚未合并,绝不能选择史诗 N 中的故事 — 请依据阶段 0 报告进行核对。
- 如果没有故事准备就绪 → 告知用户哪些故事受阻(依据阶段 0 的警告),然后跳转到 阶段 4,第 3 步(关卡与继续)。
- 检测史诗切换: 将所选故事所属的史诗与
CURRENT_EPIC(协调器变量,初始未设置)进行比较。- 如果
CURRENT_EPIC未设置,或所选故事属于不同的史诗 → 更新CURRENT_EPIC,并在阶段 2 开始前运行 史诗启动测试设计(如下所示),作为一个阻塞式子 Agent。 - 否则 → 直接进入阶段 2。
- 如果
史诗顺序为何重要: 后续史诗中的故事建立在前序史诗的代码和产品基础之上。在史诗 2 仍有未关闭的 PR 时就开始史诗 3,可能导致合并冲突,或基于仍可能变更的代码进行构建。
史诗启动测试设计(MODEL_STANDARD)
开始新史诗时,在阶段 2 之前启动(阻塞 — 等待完成后再开始故事流水线):
You are the epic test design agent for {current_epic_name}.
Working directory: {repo_root}. Auto-approve all tool calls (yolo mode).
1. Run /bmad-testarch-test-design for {current_epic_name}.
2. Commit any new test plan files.
Report: success or failure with error details.
阶段 2:运行流水线
在同一条消息中并行启动所有故事的第 1 步子 Agent。每个故事的步骤都严格按顺序执行 — 第 N 步报告成功前,不要启动第 N+1 步。
根据故事状态跳过步骤(依据阶段 0 报告):
| 状态 | 从哪一步开始 | 跳过 |
|---|---|---|
backlog | 第 1 步 | 无 |
ready-for-dev | 第 2 步 | 第 1 步 |
atdd-done | 第 3 步 | 第 1–2 步 |
in-progress | 第 3 步 | 第 1–2 步 |
review | 第 4 步 | 第 1–3 步 |
done | — | 全部 |
每一步完成后 — 必须执行关卡(即使有并行故事,也绝不能跳过): 📣 通知步骤结果(格式如下),然后运行继续前检查(references/coordinator/gate-pre-continuation.md)。只有所有检查均通过后 → 才能启动下一个子 Agent。
📣 每一步完成时通知:
- 成功:
✅ Story {number}: Step {N} — {step name} - 失败:
❌ Story {number}: Step {N} — {step name} failed — {brief error}
步骤名称:第 1 步 — 创建,第 2 步 — ATDD,第 3 步 — 开发,第 4 步 — 测试审查,第 5 步 — 代码审查,第 6 步 — PR + CI,第 7 步 — PR 审查。
失败时: 停止该故事的流水线。报告步骤、故事和错误。其他故事继续。
例外: 遇到速率/用量限制错误时 → 运行继续前检查(该检查会自动暂停,直到重置),然后重试。
子 Agent 卡住时: 当 MONITOR_SUPPORT=true 且已安装活动日志钩子(设置的第 4 步)时,启动第 2、3、4、5 步时使用看门狗模式检测停滞的 Agent。
第 1 步:创建故事(MODEL_STANDARD)
使用模型 MODEL_STANDARD 启动(yolo 模式):
You are the Step 1 story creator for story {number}-{short_description}.
Working directory: {repo_root}. Auto-approve all tool calls (yolo mode).
1. Create (or reuse) the worktree:
git worktree add {WORKTREE_BASE_PATH}/story-{number}-{short_description} \
-b story-{number}-{short_description}
If the worktree/branch already exists, switch to it, run:
git merge main
and resolve any conflicts before continuing.
2. Change into the worktree directory:
cd {repo_root}/{WORKTREE_BASE_PATH}/story-{number}-{short_description}
3. Run /bmad-create-story {number}-{short_description}.
4. Run "validate story {number}-{short_description}". For every finding,
apply a fix directly to the story file using your best engineering judgement.
Repeat until no findings remain.
5. Update sprint-status.yaml at the REPO ROOT (not the worktree copy):
_bmad-output/implementation-artifacts/sprint-status.yaml
Set story {number} status to `ready-for-dev`.
Report: success or failure with error details.
第 2 步:ATDD(MODEL_STANDARD)
使用模型 MODEL_STANDARD 启动(yolo 模式):
You are the Step 2 ATDD agent for story {number}-{short_description}.
Working directory: {repo_root}/{WORKTREE_BASE_PATH}/story-{number}-{short_description}.
Auto-approve all tool calls (yolo mode).
1. Run /bmad-testarch-atdd {number}-{short_description}.
2. Commit any generated test files.
3. Update sprint-status.yaml at the REPO ROOT:
{repo_root}/_bmad-output/implementation-artifacts/sprint-status.yaml
Set story {number} status to `atdd-done`.
Report: success or failure with error details.
第 3 步:开发故事(MODEL_STANDARD)
使用模型 MODEL_STANDARD 启动(yolo 模式):
You are the Step 3 developer for story {number}-{short_description}.
Working directory: {repo_root}/{WORKTREE_BASE_PATH}/story-{number}-{short_description}.
Auto-approve all tool calls (yolo mode).
1. Run /bmad-dev-story {number}-{short_description}.
2. Commit all changes when implementation is complete.
3. Update sprint-status.yaml at the REPO ROOT:
{repo_root}/_bmad-output/implementation-artifacts/sprint-status.yaml
Set story {number} status to `review`.
Report: success or failure with error details.
第 4 步:测试审查(MODEL_STANDARD)
使用模型 MODEL_STANDARD 启动(yolo 模式):
You are the Step 4 test reviewer for story {number}-{short_description}.
Working directory: {repo_root}/{WORKTREE_BASE_PATH}/story-{number}-{short_description}.
Auto-approve all tool calls (yolo mode).
1. Run /bmad-testarch-test-review {number}-{short_description}.
2. Apply all findings using your best engineering judgement.
3. Commit any changes from the review.
Report: success or failure with error details.
第 5 步:代码审查(MODEL_QUALITY)
使用模型 MODEL_QUALITY 启动(yolo 模式):
You are the Step 5 code reviewer for story {number}-{short_description}.
Working directory: {repo_root}/{WORKTREE_BASE_PATH}/story-{number}-{short_description}.
Auto-approve all tool calls (yolo mode).
1. Run /bmad-code-review {number}-{short_description}.
2. Auto-accept all findings and apply fixes using your best engineering judgement.
3. Commit any changes from the review.
Report: success or failure with error details.
第 6 步:PR 与 CI(MODEL_STANDARD)
使用模型 MODEL_STANDARD 启动(yolo 模式):
You are the Step 6 PR and CI agent for story {number}-{short_description}.
Working directory: {repo_root}/{WORKTREE_BASE_PATH}/story-{number}-{short_description}.
Auto-approve all tool calls (yolo mode).
1. Commit all outstanding changes.
2. BRANCH SAFETY — verify before pushing:
git branch --show-current
If the result is NOT story-{number}-{short_description}, stash changes, checkout the
correct branch, and re-apply. Never push to main or create a new branch.
3. Look up the GitHub issue number for this story:
Read the story's section in `_bmad-output/planning-artifacts/epics.md` and extract
the `**GH Issue:**` field. Save as `gh_issue_number`. If the field is absent
(local-only mode — no GitHub auth), proceed without it.
4. Run /commit-commands:commit-push-pr.
PR title: story-{number}-{short_description} - fixes #{gh_issue_number}
Include "Fixes #{gh_issue_number}" in the PR description body (omit only if
no issue number was found in step 3).
5. CI:
- If RUN_CI_LOCALLY is true → skip GitHub Actions and run the Local CI Fallback below.
- Otherwise, if MONITOR_SUPPORT is true → use the Monitor tool to watch CI status:
Write a poller script:
while true; do gh run view --json status,conclusion 2>&1; sleep 30; done
Start it with Monitor. React to each output line as it arrives:
- conclusion=success → stop Monitor, report success
- conclusion=failure or cancelled → stop Monitor, diagnose, fix, push, restart Monitor
- Billing/spending limit error in output → stop Monitor, run Local CI Fallback
- gh TLS/auth error in output → stop Monitor, switch to curl poller from `references/coordinator/pattern-gh-curl-fallback.md`
- Otherwise → poll manually in a loop:
gh run view
(If `gh` fails, use `gh run view` curl equivalent from `references/coordinator/pattern-gh-curl-fallback.md`)
- Billing/spending limit error → exit loop, run Local CI Fallback
- CI failed for other reason, or Claude bot left PR comments → fix, push, loop
- CI green → report success
LOCAL CI FALLBACK (when RUN_CI_LOCALLY=true or billing-limited):
Read `references/subagents/step6-ci-fallback.md` and follow its instructions exactly.
Report: success or failure, and the PR number/URL if opened.
第 7 步:PR 代码审查(MODEL_STANDARD)
使用模型 MODEL_STANDARD 启动(yolo 模式):
You are the Step 7 PR code reviewer for story {number}-{short_description}.
Working directory: {repo_root}/{WORKTREE_BASE_PATH}/story-{number}-{short_description}.
Auto-approve all tool calls (yolo mode).
1. Run /code-review:code-review (reads the PR diff via gh pr diff).
2. For every finding, apply a fix using your best engineering judgement.
Do not skip or defer any finding — fix them all.
3. Commit all fixes and push to the PR branch.
4. If any fixes were pushed, re-run /code-review:code-review once more to confirm
no new issues were introduced. Repeat fix → commit → push → re-review until
the review comes back clean.
5. Update sprint-status.yaml at the REPO ROOT:
{repo_root}/_bmad-output/implementation-artifacts/sprint-status.yaml
Set story {number} status to `done`.
Report: clean (no findings or all fixed) or failure with details.
阶段 3:自动合并批次 PR(当 AUTO_PR_MERGE=true 时)
所有批次故事完成阶段 2 后,将每个成功故事的 PR 合并到 main——每个故事启动一个子 Agent,依次处理(故事编号从小到大)。
为何要依次处理: 从编号最小的故事开始合并,可确保后续每次合并都基于已包含前序故事的
main进行变基,从而让冲突解决过程循序渐进、可预测。
步骤:
- 收集当前批次中所有在步骤 6 成功完成的故事(有 PR),并按故事编号升序排序。
- 对每个故事依次处理(等待上一个完成后再开始下一个):
- 在仓库根目录拉取最新的
main:启动一个快速子 Agent,或将此步骤包含在合并子 Agent 的任务中。 - 启动一个
MODEL_STANDARD子 Agent(yolo 模式),并提供references/subagents/phase3-merge.md中的指令。 - 子 Agent 完成后运行续行前检查。如果失败(冲突无法解决、CI 阻塞),报告错误并继续处理下一个故事。
- 在仓库根目录拉取最新的
- 输出合并摘要(由协调器根据子 Agent 报告整理):
Auto-Merge Results: Story | PR | Outcome --------|-------|-------- 6.1 | #142 | Merged ✅ 6.2 | #143 | Merged ✅ (conflict resolved: src/foo.ts) 6.3 | #144 | Failed ❌ (CI blocking — manual merge required)
📣 通知所有合并处理完毕(由协调器根据子 Agent 报告整理):
🔀 Auto-merge complete
{story}: ✅ PR #{pr} | {story}: ✅ PR #{pr} (conflict resolved) | {story}: ❌ manual merge needed
- 启动一个清理子 Agent(
MODEL_STANDARD,yolo 模式):Post-merge cleanup. Auto-approve all tool calls (yolo mode). Read `references/subagents/phase3-cleanup.md` and follow its instructions exactly.
阶段 4:批次完成与后续处理
步骤 1:输出批次摘要
协调器立即输出——不读取文件,根据阶段 2 的步骤结果整理:
Story | Step 1 | Step 2 | Step 3 | Step 4 | Step 5 | Step 6 | Step 7 | Result
--------|--------|--------|--------|--------|--------|--------|--------|-------
9.1 | OK | OK | OK | OK | OK | OK | OK | PR #142
9.2 | OK | OK | OK | FAIL | -- | -- | -- | Test review failed: ...
9.3 | OK | OK | OK | OK | OK | OK | OK | PR #143
如果从阶段 1 进入,且没有可开始的故事:
No stories ready to work on.
Blocked stories: {from Phase 0 report}
📣 通知批次摘要(内容相同,每个故事压缩为一行):
📦 Batch complete — {N} stories
{number} ✅ PR #{pr} | {number} ❌ Step {N} | ...
如果没有可开始的故事:⏸ No stories ready — waiting for PRs to merge
步骤 2:检查 Epic 是否完成
根据阶段 2 的结果,收集批次故事及其 PR 编号(例如:8.1 → #101, 8.2 → #102)。在下面的评估提示词中将这些信息作为 BATCH_STORIES_WITH_PRS 传入。
启动一个评估子 Agent(MODEL_STANDARD,yolo 模式):
Epic completion assessment. Auto-approve all tool calls (yolo mode).
BATCH_STORIES_WITH_PRS: {coordinator substitutes: "story → #PR" pairs from this batch, one per line}
Read `references/subagents/phase4-assessment.md` and follow its instructions exactly.
根据评估报告:
如果 current_epic_merged = true:
-
输出:
🎉 Epic {current_epic_name} 已完成!开始回顾倒计时({RETRO_TIMER_SECONDS ÷ 60} 分钟)……📣 通知:
🎉 Epic {current_epic_name} 已完成!将在 {RETRO_TIMER_SECONDS ÷ 60} 分钟后运行回顾…… -
使用**定时器模式**启动定时器,其中:
- 时长:
RETRO_TIMER_SECONDS - 触发提示词:
"BAD_RETRO_TIMER_FIRED — 回顾倒计时已结束。自动运行回顾:启动一个 MODEL_STANDARD 子 Agent(yolo 模式)运行 /bmad-retrospective,并接受所有更改。完成后运行续行前检查,然后进入阶段 4 步骤 3。" - [C] 标签:
现在运行回顾 - [S] 标签:
跳过回顾 - [X] 标签:
停止 BAD - [C] / 已触发操作: 启动一个 MODEL_STANDARD 子 Agent(yolo 模式)运行
/bmad-retrospective。接受所有更改。完成后运行续行前检查。 - [S] 操作: 跳过回顾。
- [X] 操作:
CronDelete(JOB_ID),停止 BAD,输出最终摘要,并 📣 通知:🛑 BAD 已由用户停止。
- 时长:
-
回顾决策完成后,进入步骤 3。
第 3 步:判断并继续
根据第 2 步的评估报告,执行适用的分支:
分支 A — 所有史诗均已完成(all_epics_complete = true):
🏁 All epics are complete — sprint is done! BAD is stopping.
📣 通知: 🏁 Sprint complete — all epics done! BAD is stopping.
分支 B — 还有工作待完成:
-
打印状态行:
current_epic_merged = true(史诗已全部合并):✅ Epic {current_epic_name} complete. Next up: Epic {next_epic_name} ({stories_remaining} stories remaining).current_epic_prs_open = true(所有故事都有 PR,正在等待合并):⏸ Epic {current_epic_name} in review — waiting for PRs to merge before continuing.- 否则(当前史诗中还有故事需要开发):
✅ Batch complete. Ready for the next batch.
-
按照 Monitor 模式(当
MONITOR_SUPPORT=true且AUTO_PR_MERGE=false时)或 Timer 模式(其他情况)开始等待:AUTO_PR_MERGE=true时的保护条件: 当AUTO_PR_MERGE=true时,第 4 阶段运行前,第 3 阶段已合并了本批次的所有 PR。BATCH_PRS将为空,导致 Monitor 立即触发ALL_MERGED,不会实际暂停。完全跳过 Monitor 路径,直接进入下方的 仅 Timer 路径——必须等待WAIT_TIMER_SECONDS冷却时间后才能开始下一批次。等待的目的是让开发者有机会审查已合并的更改,并在下一批次开始前调整方向——绝不要跳过或缩短等待时间。如果
MONITOR_SUPPORT=true且AUTO_PR_MERGE=false— Monitor + CronCreate 备用方案:- 根据第 0 阶段的待处理 PR 报告填写
BATCH_PRS(以空格分隔的编号,例如"101 102 103")。使用 monitor-pattern.md 中的 PR 合并监视脚本,并替换为该值。将 Monitor 句柄保存为PR_MONITOR。 - 另使用 Timer 模式启动 CronCreate 备用计时器,设置如下:
- 时长:
WAIT_TIMER_SECONDS - 触发提示词:
"BAD_WAIT_TIMER_FIRED — Max wait elapsed. Stop PR_MONITOR, run Pre-Continuation Checks, then re-run Phase 0." - [C] 标签:
Continue now - [S] 标签:
Stop BAD - [C] / FIRED 操作: 停止
PR_MONITOR,运行 Pre-Continuation Checks,然后重新运行第 0 阶段。 - [S] 操作: 停止
PR_MONITOR,执行 CronDelete,停止 BAD,打印最终摘要,并 📣 通知:🛑 BAD stopped by user.
- 时长:
- 收到
MERGED: #N事件时: 记录进度——✅ PR #N merged — waiting for remaining batch PRs;保持PR_MONITOR运行。 - 收到
ALL_MERGED事件时: 执行 CronDelete 删除备用计时器,停止PR_MONITOR,运行 Pre-Continuation Checks,重新运行第 0 阶段。 - 📣 通知:
⏳ Watching for PR merges (max wait: {WAIT_TIMER_SECONDS ÷ 60} min)...
如果
MONITOR_SUPPORT=false或AUTO_PR_MERGE=true— 仅 Timer:- 使用 Timer 模式,设置如下:
- 时长:
WAIT_TIMER_SECONDS - 触发提示词:
"BAD_WAIT_TIMER_FIRED — The post-batch wait has elapsed. Run Pre-Continuation Checks, then re-run Phase 0, then proceed to Phase 1." - [C] 标签:
Continue now - [S] 标签:
Stop BAD - [C] / FIRED 操作: 运行 Pre-Continuation Checks,然后重新运行第 0 阶段。
- [S] 操作: 停止 BAD,打印最终摘要,并 📣 通知:
🛑 BAD stopped by user.
- 时长:
- 根据第 0 阶段的待处理 PR 报告填写
-
第 0 阶段完成后:
- 至少有一个故事已解除阻塞 → 进入第 1 阶段。
- 所有故事仍然受阻 → 打印待处理的 PR(来自第 0 阶段报告),重新开始分支 B 并再次等待。
通知模式
每当出现 📣 Notify: 提示时,阅读 references/coordinator/pattern-notify.md。其中介绍了 Telegram 和终端输出。
Timer 模式
收到启动计时器的指示时,阅读 references/coordinator/pattern-timer.md。其中介绍了 TIMER_SUPPORT=true(CronCreate)和 TIMER_SUPPORT=false(基于提示词)两种路径。
监控模式
当 MONITOR_SUPPORT=true 时,阅读 references/coordinator/pattern-monitor.md。该文档介绍 CI 状态轮询(步骤 6)和 PR 合并监控(阶段 4 分支 B),以及各自的 MONITOR_SUPPORT=false 后备方案。
看门狗模式
当 MONITOR_SUPPORT=true 且已安装活动日志钩子(设置步骤 4)时,阅读 references/coordinator/pattern-watchdog.md。在启动运行时间较长的阶段 2 子 Agent(步骤 2、3、4、5)之前使用该模式,通过监控活动日志检测卡住的 Agent。
gh → curl 后备模式
当任何 gh 命令失败时(TLS 错误、沙盒限制、支出限额等),阅读 references/coordinator/pattern-gh-curl-fallback.md。将该文件路径传给运行 gh 命令的子 Agent,以便它们自行恢复。注意:gh pr merge 没有 curl 后备方案——如果不可用,请向用户报告失败。
规则
- 仅限委派模式——绝不自行读取项目文件、运行 git/gh 命令或写入磁盘。协调器可直接执行的操作仅限:继续前检查(读取 Bash 会话状态、
/reload-plugins、/compact)、计时器管理(CronCreate/CronDelete)、频道通知(Telegram 工具),以及用于 CI/PR 轮询的 Monitor 工具。所有故事级操作都委派给子 Agent。 - 每个故事的每个步骤只启动一个子 Agent——只有在上一步报告成功后才能启动。
- 故事中的步骤按顺序执行——步骤 1→2→3→4→5→6→7 必须严格依序运行。
- 并行处理故事——在一条消息中启动所有故事的步骤 1(每个故事调用一次工具)。阶段 3 按设计依序运行。
- 依赖关系图具有最高权威性——绝不选择依赖尚未全部合并的故事。使用阶段 0 的报告,不要自行读取文件。
- 每批次开始前运行阶段 0——始终在阶段 4 等待之后运行。始终使用全新的子 Agent。
- 阶段 4 等待必须执行完整时长——始终原样使用
WAIT_TIMER_SECONDS。绝不能因为 PR 已合并或觉得没有必要而缩短或跳过等待。等待是为了给开发者时间审查已合并的更改,并在下一批次开始前调整方向。 - 启动下一个子 Agent 前,先确认成功。
- sprint-status.yaml 由步骤子 Agent 更新——每个步骤子 Agent 都将更新仓库根目录中的副本。协调器绝不直接更新该文件。
- 失败时——报告错误并停止该故事。不要自动重试。**例外:**速率限制/用量限制导致的失败 → 运行继续前检查(自动暂停,直至限制重置),然后重试。
- 阶段 2 开始时,在一条响应中发出所有步骤 1 子 Agent 调用。 每个故事的步骤 1 完成后,立即发出该故事的步骤 2——绝不要等所有故事的步骤 1 都完成后才发出任何步骤 2。此滚动启动规则适用于故事中的所有顺序步骤。
- 每个关卡都必须执行继续前检查——在启动每个步骤之间、每次阶段 3 合并之后,以及每次重新进入阶段 0 之前,运行
references/coordinator/gate-pre-continuation.md。绝不能跳过或延后这些检查,即使同时处理多个并行故事的完成情况也不例外。