Watch pr

From ayutaz/piper-plus · View interactive version

Watch pr is an AI agent skill from the GitHub repository ayutaz/piper-plus. PR push 直後 / 既存 PR の CI 監視 (`/create-pr` はフェーズ 5 で同等の監視を inline 実行し本 skill を chain しない。 本 skill はその standalone 版) / レビュー対応 / merge 前確認 の文脈で発動。`gh pr checks` を一度 polling し green / red / pending を集計、 red なら失敗 job のログを fetch して「format drift / test fail / build error / flake / contract drift」に分類。 同時に un

How to use this skill

Skill file

PR CI Status Watcher

PR の CI checks を 1 回ポーリングして状態を集計する skill。継続監視は /loop と組み合わせる:

/loop /watch-pr 489       # 5 分間隔で polling、red/green/timeout で通知
/watch-pr                 # 引数省略時は現在ブランチに紐づく PR を自動検出

引数

実行前の確認

手順

フェーズ 1: PR 番号の確定

引数 $1 がない場合、現在ブランチに紐づく PR を取得:

PR_NUM=$(gh pr view --json number --jq '.number' 2>/dev/null)

該当 PR がない場合 (= まだ push していない / PR 未作成) は、その旨をユーザーに報告して停止。

フェーズ 1.5: フォーク PR の確認

gh pr view "$PR_NUM" --json isCrossRepository,headRepositoryOwner,headRefName,headRefOid \
  --jq '{fork: .isCrossRepository, owner: .headRepositoryOwner.login, branch: .headRefName, head: .headRefOid}'

fork が true (フォークからの PR) なら、 次の 4 点がこのリポジトリのブランチの PR と違う (#934, 2026-11):

```bash

gh api --paginate "repos/ayutaz/piper-plus/actions/runs?head_sha=<head>&status=action_required&per_page=100" \

--jq '.workflow_runs[] | "\(.id) \(.name)"'

```

承認は差分を確認してからユーザーに聞き、 了承を得て 1 件ずつ gh api -X POST repos/ayutaz/piper-plus/actions/runs/<id>/approve。 外部の人のコードを CI で走らせる操作なので、 自分で判断して承認しない。

フェーズ 2: CI checks の一括取得

gh pr checks "$PR_NUM" --json name,state,bucket,link,workflow --jq '.[]'

gh pr checks --json に conclusion フィールドはない (指定すると Unknown JSON field エラー)。 使えるフィールドは bucket / completedAt / description / event / link / name / startedAt / state / workflow (gh pr checks --help の JSON FIELDS)。 集計は bucket で行う:

pending があると gh pr checks は exit code 8 で終わる (失敗ではない)。

フェーズ 3: 集計とサマリ

以下のテーブルでサマリを表示 (件数は実際の集計値):

## PR #<N> CI Status (<HH:MM:SS>)

| State        | Count |
|--------------|-------|
| ✅ Success   | <n>   |
| ❌ Failure   | <n>   |
| 🔁 Pending   | <n>   |
| ⏭️ Skipped   | <n>   |
| ⚠️ Cancelled | <n>   |

Total: <total> checks

判定ルール:

フェーズ 4: 失敗 job の分析 (failure ≥ 1 時のみ)

各失敗 job について:

  1. job 名と link を表示
  2. gh run view <run-id> --log-failed で失敗 step のログを fetch (最大 100 行)
  3. ログを以下の pattern で分類:
  1. 分類別に推奨アクションを提示

フェーズ 5: Unresolved review thread の集計

CI status とは独立で、 review コメント / Copilot 指摘が未解決のまま残っていないか

を毎回チェック。 /check-review-backlog --pr <PR> 相当の GraphQL を呼ぶ:

gh api graphql -f query='
query($owner: String!, $name: String!, $number: Int!) {
  repository(owner: $owner, name: $name) {
    pullRequest(number: $number) {
      reviewThreads(first: 50) {
        nodes {
          isResolved
          isOutdated
          comments(first: 1) {
            nodes {
              author { login }
              path
              body
              createdAt
            }
          }
        }
      }
    }
  }
}' -F owner=ayutaz -F name=piper-plus -F number="$PR_NUM" --jq \
'.data.repository.pullRequest.reviewThreads.nodes
 | map(select(.isResolved == false))
 | length, map(select(.isResolved == false))[]'

集計:

```text

## Unresolved Review Threads (#<PR>)

| # | Reviewer | Path | Stale? | 提案 |

|---|----------|------|--------|------|

| 1 | Copilot | src/foo.py:42 | ✓ stale (b7e71c8 以降に更新済) | dismiss / reply |

| 2 | yousan | src/bar.rs:88 | new | 修正 → /reply-review <PR> |

```

フェーズ 5.5: 安全カテゴリの自動 reply + resolve (auto-chain)

Unresolved review thread が 1 件以上ある場合、 必ず/reply-review <PR> --auto-safe

を Skill tool で chain 起動する。 これにより以下が自動処理される (フェーズ 1.9

参照、 SAFE-stale / SAFE-copilot-style の 2 カテゴリ):

--auto-safe は SAFE 系のみ実行、 REVIEW-human / REVIEW-copilot-blocker は

内部で dry-run 扱いとなり提示のみ。 これにより:

skill 呼び出し:

Skill({skill: "reply-review", args: "<PR_NUM> --auto-safe"})

戻り値の reply / resolve カウントを次フェーズの判定材料にする。

フェーズ 6: 次のアクション提案

| 状態 | 推奨アクション |

|------|-------------|

| All green + Unresolved 0 (自動 resolve 後含む) | /check-pr-ready で最終確認、 user 確認後に merge (gh pr merge --auto 禁止) |

| All green + REVIEW 残 ≥ 1 (自動処理外) | user に judge を促し、 修正コミット後再度 /loop /watch-pr <PR> |

| Red (format drift) | pre-commit run --all-files をローカル実行、修正後 /commit |

| Red (test fail) | 該当テストファイル名を提示、/run-tests <scope> で再現 |

| Red (build error) | エラーログを示してユーザーに方針確認 |

| Red (flake) | gh run rerun <run-id> --failed を提示 (ユーザー確認後実行) |

| Red (contract drift) | /check-pua /check-loanword 等の該当 skill を提示 |

| Pending | /loop /watch-pr <PR> で継続監視 (auto-safe は次回 iteration でも走る) |

継続監視モード

ユーザーが「green になるまで監視して」と希望する場合:

/loop /watch-pr <PR>

/loop skill が /watch-pr <PR> を再帰的に呼び出す。 各 iteration で本 skill が

CI + review thread を両方確認。 終了条件:

| iteration の結果 | アクション |

|------------------|-----------|

| All green + Unresolved 0 | ユーザーに完了通知して /loop を終了 |

| All green + Unresolved ≥ 1 | フェーズ 5.5 で /reply-review --auto-safe を chain 起動。 SAFE 系は自動 reply + resolve、 残った REVIEW 系を user に提示して /loop を終了 |

| Red (本物) | 失敗分析を表示して /loop を終了 (人間判断が必要) |

| Red (flake のみ) | gh run rerun --failed を提案 (確認後実行)、 ループは継続 |

| Pending | 次の polling 間隔まで sleep (自動 pace は CI 状況で 4-20 分、 cache TTL の都合で IN_PROGRESS 多い時は delaySeconds=270、 落ち着いた状態なら 1200+)。 各 iteration でも review thread の auto-safe chain は走る |

SAFE 系 review thread の自動 reply + resolve は本 skill のフェーズ 5.5 で行う。

REVIEW-human / REVIEW-copilot-blocker は memory feedback_pr_body_over_comments /

feedback_merge_caution 遵守のため user 判断に委ね、 修正後にユーザが明示的に

/reply-review <PR> を起動する形。

注意事項

使用例

# 現在ブランチの PR を 1 回チェック
/watch-pr

# PR #489 を 1 回チェック
/watch-pr 489

# 5 分間隔で継続監視 (loop skill が pace 決定)
/loop /watch-pr 489

# 固定 5 分間隔
/loop 5m /watch-pr 489

期待効果

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.