bail
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseBail-out protocol: always reflect FIRST, then clean up.
退出协议:始终先进行复盘,再执行清理。
Inputs
输入参数
- Optional reason string (if not provided, ask for one)
- 可选的原因字符串(如果未提供,需要向用户询问原因)
Steps
执行步骤
-
Detect current step by examining what exists:
What exists Estimated step Just an issue, no branch Step 0 (Capture) .branch-context.md, no worktree Step 1 (Orient) Worktree exists, no code changes Step 2 (Isolate) Plan file on branch Step 3-4 (Design/Review) Code changes committed Step 5-7 (Build/Verify/Archive) PR open on GitHub Step 8 (Ship) -
Prompt for reason if not provided.
-
Write learnings to .branch-context.md:
- What was attempted
- Why bailing (the reason)
- What was learned
- Any partial work worth preserving
-
Consolidate learnings: Readand append relevant items to
.branch-context.mdon main:ai-workspace/MEMORY.mdbashgit stash git checkout main # Append learnings to MEMORY.md git add ai-workspace/MEMORY.md git commit -m "docs: consolidate learnings from abandoned <branch>" git checkout <branch> git stash pop -
Update GitHub Issue (if accessible):bash
# Find issue number from branch name or PR gh issue comment <number> --body "Bailing: <reason>. Learnings captured in MEMORY.md." gh issue edit <number> --add-label "deferred" --remove-label "triage" -
Close PR if open:bash
PR_NUM=$(gh pr list --head "<branch>" --json number -q '.[0].number') if [ -n "$PR_NUM" ]; then gh pr close "$PR_NUM" fi -
Ask about branch preservation:
- Default: preserve the branch (user can resume later)
- If user says delete:
bash
git worktree remove .worktrees/<name> 2>/dev/null git branch -D <branch> 2>/dev/null git push origin --delete <branch> 2>/dev/null
-
Return to main:bash
git checkout main
-
检测当前步骤,通过检查现有内容判断:
现有内容 预估步骤 只有Issue,没有分支 步骤0(捕获阶段) 存在.branch-context.md,没有工作树 步骤1(定向阶段) 存在工作树,没有代码变更 步骤2(隔离阶段) 分支上存在计划文件 步骤3-4(设计/评审阶段) 代码变更已提交 步骤5-7(构建/验证/归档阶段) GitHub上有已开启的PR 步骤8(发布阶段) -
如果未提供原因,提示用户输入原因。
-
将经验教训写入.branch-context.md:
- 尝试过哪些操作
- 退出原因
- 收获的经验
- 任何值得保留的部分工作成果
-
整合经验教训:读取的内容,将相关条目追加到main分支的
.branch-context.md中:ai-workspace/MEMORY.mdbashgit stash git checkout main # Append learnings to MEMORY.md git add ai-workspace/MEMORY.md git commit -m "docs: consolidate learnings from abandoned <branch>" git checkout <branch> git stash pop -
更新GitHub Issue(如果有权限访问):bash
# Find issue number from branch name or PR gh issue comment <number> --body "Bailing: <reason>. Learnings captured in MEMORY.md." gh issue edit <number> --add-label "deferred" --remove-label "triage" -
如果有开启的PR则关闭:bash
PR_NUM=$(gh pr list --head "<branch>" --json number -q '.[0].number') if [ -n "$PR_NUM" ]; then gh pr close "$PR_NUM" fi -
询问是否保留分支:
- 默认:保留分支(用户后续可以恢复工作)
- 如果用户选择删除:
bash
git worktree remove .worktrees/<name> 2>/dev/null git branch -D <branch> 2>/dev/null git push origin --delete <branch> 2>/dev/null
-
切回main分支:bash
git checkout main
Edge Cases
边界情况
- No worktree exists (bailing at Step 0-1) → skip worktree cleanup, just update issue
- No GitHub access → skip issue update, still do local cleanup + memory consolidation
- PR already merged → don't close, just note it in the output
- No .branch-context.md → create one with just the bail reason before consolidating
Output: Summary of what was cleaned up and where learnings were saved.
- 不存在工作树(在步骤0-1阶段退出)→ 跳过工作树清理,仅更新Issue
- 没有GitHub访问权限→ 跳过Issue更新,仍然执行本地清理+经验整合
- PR已合并→ 不要关闭,仅在输出中说明
- 不存在.branch-context.md→ 在整合经验前先创建该文件,仅写入退出原因
输出:清理内容的摘要,以及经验教训的保存位置。