$npx -y skills add Codagent-AI/agent-skills --skill finalize-prOrchestrates the full post-implementation loop: push PR → wait for CI → fix failures → repeat until CI passes or termination rules trigger a pause. This skill should be used when the user says "ship it", "finalize pr", "push and fix CI", "push pr and wait for CI", or invokes "cod
| 1 | # codagent:finalize-pr |
| 2 | |
| 3 | Push the PR, wait for CI, fix any failures or review comments, and repeat until the PR is green — or pause when termination rules require human input. |
| 4 | |
| 5 | ## Procedure |
| 6 | |
| 7 | ### Step 1 — Push the PR |
| 8 | |
| 9 | Invoke `codagent:push-pr` to commit, push, and create or update the pull request. |
| 10 | |
| 11 | If push-pr fails (e.g. no remote, auth error), report the error and stop. |
| 12 | |
| 13 | ### Step 2 — Wait for CI |
| 14 | |
| 15 | Invoke `codagent:wait-ci` to poll CI status and gather review comments. |
| 16 | |
| 17 | The wait-ci skill returns one of four statuses: |
| 18 | - `passed` — CI green, no blocking reviews, no PR comments |
| 19 | - `failed` — CI failures or `CHANGES_REQUESTED` reviews |
| 20 | - `comments` — CI green but PR comments need addressing |
| 21 | - `pending` — checks still running after timeout |
| 22 | |
| 23 | ### Step 3 — Evaluate result |
| 24 | |
| 25 | **On `passed`:** Workflow is complete. Report success with the PR URL. Stop. |
| 26 | |
| 27 | **On `pending`:** Report which checks are still running. Use the appropriate tool for asking the user a question or requesting input to ask whether to wait longer or proceed. |
| 28 | |
| 29 | **On `failed` or `comments`:** Record the failure signature (the set of failing CI check names, or `comments-only` if CI passed but comments exist), then proceed to Step 4. |
| 30 | |
| 31 | ### Step 4 — Fix and retry |
| 32 | |
| 33 | Check termination rules before attempting a fix: |
| 34 | |
| 35 | 1. **Max 3 fix cycles.** If this would be the 4th fix attempt, pause immediately — show current CI status and use the appropriate tool for asking the user a question or requesting input to ask how to proceed. Do NOT attempt a 4th cycle. |
| 36 | |
| 37 | 2. **Same failure persists after 2 fix attempts.** If the failure signature from Step 3 matches the previous cycle's failure signature AND this is the 2nd consecutive attempt at the same failure, pause immediately — explain the persistent failure in detail and use the appropriate tool for asking the user a question or requesting input to ask for guidance. "Same failure" means the identical CI check name(s) appear as failing across two consecutive wait-ci results after fix attempts. |
| 38 | |
| 39 | If neither termination rule applies: |
| 40 | |
| 41 | - Invoke `codagent:fix-pr` to address CI failures and/or review comments |
| 42 | - Return to Step 2 |
| 43 | |
| 44 | ### Failure tracking |
| 45 | |
| 46 | Maintain a running count and history across cycles: |
| 47 | |
| 48 | | Cycle | Failure signature | Action | |
| 49 | |-------|------------------------------------------|-----------------| |
| 50 | | 1 | `["lint", "test-unit"]` | fix-pr → retry | |
| 51 | | 2 | `["test-unit"]` | fix-pr → retry | |
| 52 | | 3 | `["test-unit"]` | PAUSE (same failure persisted 2 attempts) | |
| 53 | |
| 54 | Another example: |
| 55 | |
| 56 | | Cycle | Failure signature | Action | |
| 57 | |-------|--------------------|-----------------| |
| 58 | | 1 | `["lint"]` | fix-pr → retry | |
| 59 | | 2 | `["test-e2e"]` | fix-pr → retry | |
| 60 | | 3 | `["test-e2e"]` | PAUSE (same failure persisted 2 attempts, AND max 3 cycles) | |
| 61 | |
| 62 | ## Notes |
| 63 | |
| 64 | - Can be invoked standalone at any point — gathers its own state from the current branch's PR |
| 65 | - Does NOT archive the change — archiving is a separate step that happens before this skill |
| 66 | - Each sub-skill (`push-pr`, `wait-ci`, `fix-pr`) is independently invocable for ad-hoc use |