fix-ci
Fix failing CI on a PR
This skill owns what happens when a check goes red on a PR, whether the PR is the user's own, a teammate's, or one file-pr just opened. A red check is a finding about the change. The goal is a green run that still checks what it checked before.
The stop-and-ask conditions in the global rules' "Commit and PR autonomy" section still apply on every round.
1. Bind the PR
Take the PR from the URL or number the user gave, or from the current branch with gh pr view. Record:
gh pr view <pr> --json url,number,author,baseRefName,headRefName,headRefOid,headRepository,headRepositoryOwner,isCrossRepository,maintainerCanModify,state,isDraft
gh api user -q .login
gh api repos/<head-owner>/<head-repo> -q .permissions.push
When state is not OPEN, stop and report it; there is no PR to fix. The branch owner is the PR author. The head is writable when the last command prints true, or when the PR is cross-repository and maintainerCanModify is true. The expected remote SHA starts as headRefOid; step 7 updates it after each push. Resolve <head-remote>, the configured remote whose URL points at headRepository; on a fork PR it differs from the base's remote. When no remote points there, stop and ask.
Check out the head branch in a clean worktree and require local HEAD to equal headRefOid. On a mismatch, stop, show both SHAs, and ask. Someone may have pushed since, or the local branch carries unpublished work.