SuperAPI AI 工具集

finishing-a-development-branch

编程与开发

查看项目

更新于 10-16 07:45

技能介绍

用途

该技能用于在开发工作完成、所有测试通过后,引导用户决定如何整合代码。核心原则是:验证测试 → 呈现选项 → 执行选择 → 清理。开始时应声明:“I'm using the finishing-a-development-branch skill to complete this work.”

主要能力

  • 在呈现选项前验证测试是否通过。
  • 确定基础分支(如 main 或 master)。
  • 向用户呈现四个固定选项:本地合并回基础分支、推送并创建 Pull Request、保持分支现状、丢弃工作。
  • 根据用户选择执行对应 Git 操作,包括合并、推送、创建 PR、删除分支等。
  • 对本地合并和丢弃选项清理工作树(worktree)。

使用方式

步骤 1:验证测试

运行项目测试套件,例如:

npm test / cargo test / pytest / go test ./...

如果测试失败,必须停止,不能进入步骤 2。如果测试通过,继续。

步骤 2:确定基础分支

尝试常见基础分支:

git merge-base HEAD main 2>/dev/null || git merge-base HEAD master 2>/dev/null

或询问用户:“This branch split from main - is that correct?”

步骤 3:呈现选项

呈现以下四个选项:

Implementation complete. What would you like to do?

1. Merge back to <base-branch> locally
2. Push and create a Pull Request
3. Keep the branch as-is (I'll handle it later)
4. Discard this work

Which option?

不要添加解释,保持选项简洁。

步骤 4:执行选择

选项 1:本地合并

git checkout <base-branch>
git pull
git merge <feature-branch>
<test command>
git branch -d <feature-branch>

然后执行步骤 5 清理工作树。

选项 2:推送并创建 PR

git push -u origin <feature-branch>
gh pr create --title "<title>" --body "$(cat <<'EOF'
## Summary
<2-3 bullets of what changed>

## Test Plan
- [ ] <verification steps>
EOF
)"

报告:“PR created. Branch and worktree preserved.” 不要清理工作树。

选项 3:保持现状

报告:“Keeping branch . Worktree preserved at .” 不要清理工作树。

选项 4:丢弃

先确认:

This will permanently delete:
- Branch <name>
- All commits: <commit-list>
- Worktree at <path>

Type 'discard' to confirm.

等待用户输入确切的“discard”。确认后:

git checkout <base-branch>
git branch -D <feature-branch>

然后执行步骤 5 清理工作树。

步骤 5:清理工作树

对于选项 1 和 4:

检查是否在工作树中:

git worktree list | grep $(git branch --show-current)

如果是,则:

git worktree remove <worktree-path>

对于选项 3:保留工作树。

适用场景

  • 实现已完成,所有测试通过,需要决定如何整合代码时。
  • 被 subagent-driven-development(步骤 7)在所有任务完成后调用。
  • 被 executing-plans(步骤 5)在所有批次完成后调用。
  • 与 using-git-worktrees 配合使用,清理该技能创建的工作树。

限制与注意事项

  • 绝不在测试失败时继续。
  • 绝不在未验证合并结果测试的情况下合并。
  • 绝不在未确认的情况下删除工作。
  • 绝不在未明确请求时强制推送。
  • 始终在提供选项前验证测试。
  • 始终呈现恰好四个选项。
  • 始终为选项 4 获取输入确认。
  • 仅对选项 1 和 4 清理工作树。

常见错误包括:跳过测试验证、使用开放式问题、自动清理工作树、丢弃时无确认。