bail

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
Bail-out protocol: always reflect FIRST, then clean up.
退出协议:始终先进行复盘,再执行清理。

Inputs

输入参数

  • Optional reason string (if not provided, ask for one)
  • 可选的原因字符串(如果未提供,需要向用户询问原因)

Steps

执行步骤

  1. Detect current step by examining what exists:
    What existsEstimated step
    Just an issue, no branchStep 0 (Capture)
    .branch-context.md, no worktreeStep 1 (Orient)
    Worktree exists, no code changesStep 2 (Isolate)
    Plan file on branchStep 3-4 (Design/Review)
    Code changes committedStep 5-7 (Build/Verify/Archive)
    PR open on GitHubStep 8 (Ship)
  2. Prompt for reason if not provided.
  3. Write learnings to .branch-context.md:
    • What was attempted
    • Why bailing (the reason)
    • What was learned
    • Any partial work worth preserving
  4. Consolidate learnings: Read
    .branch-context.md
    and append relevant items to
    ai-workspace/MEMORY.md
    on main:
    bash
    git 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
  5. 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"
  6. 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
  7. 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
  8. Return to main:
    bash
    git checkout main
  1. 检测当前步骤,通过检查现有内容判断:
    现有内容预估步骤
    只有Issue,没有分支步骤0(捕获阶段)
    存在.branch-context.md,没有工作树步骤1(定向阶段)
    存在工作树,没有代码变更步骤2(隔离阶段)
    分支上存在计划文件步骤3-4(设计/评审阶段)
    代码变更已提交步骤5-7(构建/验证/归档阶段)
    GitHub上有已开启的PR步骤8(发布阶段)
  2. 如果未提供原因,提示用户输入原因
  3. 将经验教训写入.branch-context.md
    • 尝试过哪些操作
    • 退出原因
    • 收获的经验
    • 任何值得保留的部分工作成果
  4. 整合经验教训:读取
    .branch-context.md
    的内容,将相关条目追加到main分支的
    ai-workspace/MEMORY.md
    中:
    bash
    git 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
  5. 更新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"
  6. 如果有开启的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
  7. 询问是否保留分支
    • 默认:保留分支(用户后续可以恢复工作)
    • 如果用户选择删除:
      bash
      git worktree remove .worktrees/<name> 2>/dev/null
      git branch -D <branch> 2>/dev/null
      git push origin --delete <branch> 2>/dev/null
  8. 切回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→ 在整合经验前先创建该文件,仅写入退出原因
输出:清理内容的摘要,以及经验教训的保存位置。