Skip to content

目标

实现 flow_pr create 的幂等逻辑,消费 C2 的 committed-head regression evidence,完成 Task runningreviewing 状态转换。

实现要点

  1. PR 创建逻辑 (src/flowrun/pr.ts)

    typescript
    createOrReusePR(params: CreatePRParams): CreatePRResult
    • Preflight 检查(无副作用):
      • Task 状态为 running
      • Evidence 中 regression.status === "pass"
      • Evidence 中 verification.status === "pass"
      • Evidence headSha 与当前 remote head 一致
    • 副作用执行:
      • gh pr create --head <branch> --base <base> --title <title> --body <body>
      • 捕获 PR number 和 URL
    • 幂等逻辑:
      • 以 repo + head branch 查询已有 open PR
      • 已存在 → 复用 PR number,写入 prNumber,初始化 checkpoints
      • 不存在 → 创建新 PR
    • 补偿逻辑:
      • GitHub 创建成功但 FlowRun 写入失败 → 重试时通过 head branch 找回同一 PR
      • 不创建重复 PR
  2. Flow PR tool (src/plugin/flow-pr-tool.ts)

    • 新增 handleFlowPrCreate(req: FlowControlRequest): FlowControlResponse
    • 调用 pr.ts 的 createOrReusePR
    • 写入 prNumber、初始化 checkpoints → Task reviewing
  3. Gate 更新 (src/flowrun/gate.ts)

    • canCompleteTask() 扩展:检查 TDD evaluator + committed-head regression + verification
    • 为后续 D2/E1 的 PR create/merge gate 打好基础

验收标准

  • [ ] 幂等创建测试:重复调用不创建重复 PR
  • [ ] Preflight 失败测试:regression 未完成、verification 未完成、Task 非 running → 均拒绝
  • [ ] 补偿测试:PR 创建成功但写 FlowRun 失败 → 重试找回原 PR
  • [ ] 状态转换测试:running→reviewing

Worktree

  • 路径: .worktree/tdd-d2-pr-create/
  • 分支: feat/tdd-d2-pr-create