diff --git a/framework/commands/claude/pilot-watch-pr.md b/framework/commands/claude/pilot-watch-pr.md index d35298a..51c758c 100644 --- a/framework/commands/claude/pilot-watch-pr.md +++ b/framework/commands/claude/pilot-watch-pr.md @@ -1,10 +1,21 @@ -You are a lightweight PR monitoring daemon. **Automatically start monitoring on launch** using Claude Code's native scheduling. No need to ask the user. +You are a PR monitoring daemon with auto-fix capabilities. **Automatically start monitoring on launch** using Claude Code's native scheduling. No need to ask the user. ## Context - **Repos**: Read `~/.claude/pilot.yaml` → use the full `repos` list. Monitor PRs across ALL configured repos. - **Scope**: Only my own PRs (`--author @me`). +## Configuration + +Read `~/.claude/pilot.yaml` for auto-fix settings: +```yaml +watch_pr: + auto_fix_ci: true # default: true — auto-fix CI failures + auto_fix_comments: false # default: false — auto-fix review comments +``` + +If `watch_pr` section is missing, use defaults above. + ## Workspace Read `~/.claude/pilot.yaml` and extract: @@ -32,13 +43,14 @@ Use the correct CLI based on `$PLATFORM`. GraphQL review thread checks only work ``` CronCreate( cron="*/10 * * * *", - prompt="Run PR monitoring check cycle: fetch my open PRs from all repos in ~/.claude/pilot.yaml, detect new unresolved comments or ready-to-merge status, and report changes. See /pilot-watch-pr for full instructions.", + prompt="Run PR monitoring check cycle: fetch my open PRs from all repos in ~/.claude/pilot.yaml, detect CI failures, unresolved comments, or ready-to-merge status, auto-fix where enabled, and report changes. See /pilot-watch-pr for full instructions.", recurring=true ) ``` 3. **Report to user**: ``` PR Monitor started. Checking every 10 minutes (auto-expires after 7 days). +Auto-fix CI: | Auto-fix comments: Cron job ID: — cancel anytime with CronDelete. ``` @@ -48,7 +60,9 @@ Cron job ID: — cancel anytime with CronDelete. ### Step 1: Fetch my open PRs from ALL repos -For each repo in `$REPOS`: +For each repo in `$REPOS`, use the platform-appropriate CLI: + +#### GitHub (`$PLATFORM == github`): ```bash gh pr list --repo $REPO_SLUG \ --author @me \ @@ -57,7 +71,26 @@ gh pr list --repo $REPO_SLUG \ --limit 20 ``` -For each PR with `reviewDecision` of `CHANGES_REQUESTED` or `REVIEW_REQUIRED`, also fetch unresolved review threads: +#### GitLab (`$PLATFORM == gitlab`): +```bash +glab mr list --repo $REPO_SLUG \ + --author @me \ + --state opened \ + --output json +``` + +#### Azure DevOps (`$PLATFORM == azdevops`): +```bash +az repos pr list \ + --repository $REPO_SLUG \ + --creator @me \ + --status active \ + --output json +``` + +#### Fetch unresolved review threads (GitHub only): + +For each PR with `reviewDecision` of `CHANGES_REQUESTED` or `REVIEW_REQUIRED`: ```bash gh api graphql -f query=' query($owner:String!,$repo:String!,$number:Int!) { @@ -76,18 +109,22 @@ query($owner:String!,$repo:String!,$number:Int!) { }' -f owner="$OWNER" -f repo="$REPO_NAME" -F number=$PR_NUMBER ``` -### Step 2: Detect only TWO conditions +**Note**: GitLab and Azure DevOps do not support GraphQL review thread queries. On those platforms, skip the "unresolved comments" condition — only detect CI failure and ready-to-merge. + +### Step 2: Detect THREE conditions | Condition | How to detect | |-----------|---------------| +| **CI failure** | `statusCheckRollup` contains any check with `conclusion` of `FAILURE`, `ERROR`, `TIMED_OUT`, or `STARTUP_FAILURE` | | **New unresolved comments** | PR has unresolved review threads (`isResolved: false`) | | **Ready to merge** | `reviewDecision === "APPROVED"` AND all status checks pass AND not a draft | ### Step 3: Compare with last check — only act on NEW changes -Track state from the previous cycle. Only report when something **changed**: +Track state from the previous cycle. Only report/act when something **changed**: -- **New unresolved comments appeared** (count increased) → report +- **CI just failed** (was passing or pending before) → report + auto-fix if enabled +- **New unresolved comments appeared** (count increased) → report + auto-fix if enabled - **PR just became ready to merge** (wasn't ready before) → report If nothing changed: @@ -102,16 +139,33 @@ When a condition is detected and it's **NEW** (changed since last cycle): #### Terminal output (one line per PR): ``` PR Monitor —