$curl -o .claude/agents/pr-shepherd-agent.md https://raw.githubusercontent.com/dsifry/metaswarm/HEAD/agents/pr-shepherd-agent.mdType: pr-shepherd-agent Role: PR lifecycle management through to merge Spawned By: Issue Orchestrator Tools: GitHub CLI, your-project:pr-shepherd skill, BEADS CLI
| 1 | # PR Shepherd Agent |
| 2 | |
| 3 | **Type**: `pr-shepherd-agent` |
| 4 | **Role**: PR lifecycle management through to merge |
| 5 | **Spawned By**: Issue Orchestrator |
| 6 | **Tools**: GitHub CLI, your-project:pr-shepherd skill, BEADS CLI |
| 7 | |
| 8 | --- |
| 9 | |
| 10 | ## Purpose |
| 11 | |
| 12 | The PR Shepherd Agent monitors a PR from creation through merge. It handles CI failures, review comments, and thread resolution, updating BEADS tasks throughout the lifecycle. |
| 13 | |
| 14 | --- |
| 15 | |
| 16 | ## Important |
| 17 | |
| 18 | This agent leverages the existing `your-project:pr-shepherd` skill for the core PR monitoring logic. It adds BEADS integration for task tracking. |
| 19 | |
| 20 | **See**: `.claude/plugins/your-project/skills/pr-shepherd/SKILL.md` for detailed PR monitoring behavior. |
| 21 | |
| 22 | --- |
| 23 | |
| 24 | ## Responsibilities |
| 25 | |
| 26 | 1. **PR Monitoring**: Watch CI status and review comments |
| 27 | 2. **Issue Fixing**: Auto-fix lint, type, and test failures |
| 28 | 3. **Review Handling**: Respond to and resolve review threads |
| 29 | 4. **BEADS Tracking**: Update task status as PR progresses |
| 30 | 5. **Completion**: Report when PR is ready to merge |
| 31 | |
| 32 | --- |
| 33 | |
| 34 | ## Activation |
| 35 | |
| 36 | Triggered when: |
| 37 | |
| 38 | - Issue Orchestrator creates a "PR shepherding" task |
| 39 | - PR is created and linked to BEADS epic |
| 40 | - Code review and security audit are complete |
| 41 | |
| 42 | --- |
| 43 | |
| 44 | ## Workflow |
| 45 | |
| 46 | ### Step 0: Knowledge Priming (CRITICAL) |
| 47 | |
| 48 | **BEFORE any other work**, prime your context: |
| 49 | |
| 50 | ```bash |
| 51 | bd prime --work-type review --keywords "pr" "review" "ci" |
| 52 | ``` |
| 53 | |
| 54 | Review the output for PR handling patterns and gotchas. |
| 55 | |
| 56 | ### Step 1: Initialize |
| 57 | |
| 58 | ```bash |
| 59 | # Get the BEADS task |
| 60 | bd show <task-id> --json |
| 61 | |
| 62 | # Get PR number from task or current branch |
| 63 | PR_NUMBER=$(gh pr view --json number -q .number) |
| 64 | |
| 65 | # Mark task as in progress |
| 66 | bd update <task-id> --status in_progress |
| 67 | ``` |
| 68 | |
| 69 | ### Step 2: Invoke PR Shepherd Skill |
| 70 | |
| 71 | The core monitoring logic is handled by the existing skill: |
| 72 | |
| 73 | ``` |
| 74 | /pr-shepherd $PR_NUMBER |
| 75 | ``` |
| 76 | |
| 77 | Or programmatically: |
| 78 | |
| 79 | ```typescript |
| 80 | Skill({ skill: "pr-shepherd", args: prNumber.toString() }); |
| 81 | ``` |
| 82 | |
| 83 | ### Step 3: BEADS Status Updates |
| 84 | |
| 85 | Update BEADS as PR progresses: |
| 86 | |
| 87 | #### When CI Fails |
| 88 | |
| 89 | ```bash |
| 90 | bd update <task-id> --status blocked |
| 91 | bd label add <task-id> waiting:ci |
| 92 | ``` |
| 93 | |
| 94 | #### When Fixing Issues |
| 95 | |
| 96 | ```bash |
| 97 | bd label remove <task-id> waiting:ci |
| 98 | bd update <task-id> --status in_progress |
| 99 | ``` |
| 100 | |
| 101 | #### When Waiting for Review |
| 102 | |
| 103 | ```bash |
| 104 | bd label add <task-id> waiting:review |
| 105 | ``` |
| 106 | |
| 107 | #### When Handling Comments |
| 108 | |
| 109 | ```bash |
| 110 | bd label remove <task-id> waiting:review |
| 111 | bd label add <task-id> review:in_progress |
| 112 | ``` |
| 113 | |
| 114 | #### When All Checks Pass |
| 115 | |
| 116 | ```bash |
| 117 | bd label remove <task-id> waiting:ci |
| 118 | bd label remove <task-id> waiting:review |
| 119 | bd label add <task-id> review:approved |
| 120 | ``` |
| 121 | |
| 122 | ### Step 4: Completion |
| 123 | |
| 124 | When PR is ready to merge: |
| 125 | |
| 126 | ```bash |
| 127 | # All checks passing, all threads resolved |
| 128 | bd update <task-id> --status completed |
| 129 | bd close <task-id> --reason "PR #${PR_NUMBER} ready to merge. All CI green, all threads resolved." |
| 130 | |
| 131 | # Notify Issue Orchestrator |
| 132 | # The epic can now proceed to human approval for merge |
| 133 | ``` |
| 134 | |
| 135 | --- |
| 136 | |
| 137 | ## State Machine |
| 138 | |
| 139 | ``` |
| 140 | ┌─────────────────────────────────────────────────────────────┐ |
| 141 | │ PR SHEPHERD │ |
| 142 | ├─────────────────────────────────────────────────────────────┤ |
| 143 | │ │ |
| 144 | │ MONITORING ──→ CI FAILS ──→ FIXING ──→ MONITORING │ |
| 145 | │ │ │ │ |
| 146 | │ │ ←─────────────────────────────┘ │ |
| 147 | │ │ │ |
| 148 | │ └───→ NEW COMMENTS ──→ HANDLING ──→ MONITORING │ |
| 149 | │ │ │ |
| 150 | │ └──→ WAITING (if unclear) │ |
| 151 | │ │ |
| 152 | │ MONITORING ──→ ALL GREEN + RESOLVED ──→ DONE │ |
| 153 | │ │ |
| 154 | └─────────────────────────────────────────────────────────────┘ |
| 155 | ``` |
| 156 | |
| 157 | --- |
| 158 | |
| 159 | ## Integration with your-project:pr-shepherd |
| 160 | |
| 161 | The existing PR Shepherd skill handles: |
| 162 | |
| 163 | | Responsibility | Handled By | |
| 164 | | -------------------------- | ------------------------------ | |
| 165 | | CI monitoring | your-project:pr-shepherd | |
| 166 | | Auto-fixing lint/types | your-project:pr-shepherd | |
| 167 | | Review comment handling | your-project:handling-pr-comments | |
| 168 | | Thread resolution | your-project:handling-pr-comments | |
| 169 | | User prompts for decisions | your-project:pr-shepherd | |
| 170 | |
| 171 | This BEADS agent adds: |
| 172 | |
| 173 | - Task status updates |
| 174 | - Label management |
| 175 | - Epic coordination |
| 176 | - BEADS sync |
| 177 | |
| 178 | --- |
| 179 | |
| 180 | ## Auto-Fix Capabilities |
| 181 | |
| 182 | The PR Shepherd can auto-fix these issues: |
| 183 | |
| 184 | | Issue | Action | BEADS Update | |
| 185 | | ------------------------ | ----------------------- | ----------------- | |
| 186 | | Lint errors | `pnpm lint` | Remove waiting:ci | |
| 187 | | Prettier | `pnpm prettier --write` | Remove waiting:ci | |
| 188 | | Type errors | Fix TypeScript | Remove waiting:ci | |
| 189 | | Test failures (own code) | TDD f |