|
| 1 | +--- |
| 2 | +name: meta-power |
| 3 | +description: Use when you want to batch-resolve all open [Model] and [Rule] GitHub issues autonomously — plans, implements, reviews, fixes, and merges each one in dependency order |
| 4 | +--- |
| 5 | + |
| 6 | +# Meta-Power |
| 7 | + |
| 8 | +Batch-process open `[Model]` and `[Rule]` issues end-to-end: plan, implement, review, fix CI, and merge — fully autonomous. |
| 9 | + |
| 10 | +## Overview |
| 11 | + |
| 12 | +You are the **outer orchestrator**. For each issue you invoke existing skills and shell out to subprocesses. You never implement code directly — `make run-plan` does the heavy lifting in a separate Claude session. |
| 13 | + |
| 14 | +## Step 0: Discover and Order Issues |
| 15 | + |
| 16 | +```bash |
| 17 | +# Fetch all open issues |
| 18 | +gh issue list --state open --limit 50 --json number,title |
| 19 | +``` |
| 20 | + |
| 21 | +Filter to issues whose title contains `[Model]` or `[Rule]`. Partition into two buckets, sort each by issue number ascending. Final order: **all Models first, then all Rules**. |
| 22 | + |
| 23 | +Present the ordered list to the user for confirmation before starting: |
| 24 | + |
| 25 | +``` |
| 26 | +Batch plan: |
| 27 | + Models: |
| 28 | + #108 [Model] LongestCommonSubsequence |
| 29 | + #103 [Model] SubsetSum |
| 30 | + Rules: |
| 31 | + #109 [Rule] LCS → MIS |
| 32 | + #110 [Rule] LCS → ILP |
| 33 | + #97 [Rule] BinPacking → ILP |
| 34 | + #91 [Rule] CVP → QUBO |
| 35 | +
|
| 36 | +Proceed? (user confirms) |
| 37 | +``` |
| 38 | + |
| 39 | +Initialize a results table to track status for each issue. |
| 40 | + |
| 41 | +## Step 1: Plan (issue-to-pr) |
| 42 | + |
| 43 | +For the current issue: |
| 44 | + |
| 45 | +```bash |
| 46 | +git checkout main && git pull origin main |
| 47 | +``` |
| 48 | + |
| 49 | +Invoke the `issue-to-pr` skill with the issue number. This creates a branch, writes a plan to `docs/plans/`, and opens a PR. |
| 50 | + |
| 51 | +**If `issue-to-pr` fails** (e.g., incomplete issue template): record status as `skipped (plan failed)`, move to next issue. |
| 52 | + |
| 53 | +Capture the PR number for later steps: |
| 54 | +```bash |
| 55 | +PR=$(gh pr view --json number --jq .number) |
| 56 | +``` |
| 57 | + |
| 58 | +## Step 2: Execute (make run-plan) |
| 59 | + |
| 60 | +Run the plan in a separate Claude subprocess: |
| 61 | + |
| 62 | +```bash |
| 63 | +make run-plan |
| 64 | +``` |
| 65 | + |
| 66 | +This spawns a new Claude session (up to 500 turns) that reads the plan and implements it using `add-model` or `add-rule`. |
| 67 | + |
| 68 | +**If the subprocess exits non-zero:** record status as `skipped (execution failed)`, move to next issue. |
| 69 | + |
| 70 | +## Step 3: Review |
| 71 | + |
| 72 | +After execution completes, ensure changes are committed and pushed: |
| 73 | + |
| 74 | +```bash |
| 75 | +# Check for uncommitted changes |
| 76 | +git add -A && git diff --cached --quiet || git commit -m "Implement #<number>: <title> |
| 77 | +
|
| 78 | +Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>" |
| 79 | +git push |
| 80 | +``` |
| 81 | + |
| 82 | +Request Copilot review: |
| 83 | +```bash |
| 84 | +make copilot-review |
| 85 | +``` |
| 86 | + |
| 87 | +## Step 4: Fix Loop (max 3 retries) |
| 88 | + |
| 89 | +```dot |
| 90 | +digraph fix_loop { |
| 91 | + "Wait 5 min" [shape=box]; |
| 92 | + "Run fix-pr" [shape=box]; |
| 93 | + "Push changes" [shape=box]; |
| 94 | + "Wait 5 min for CI" [shape=box]; |
| 95 | + "CI green?" [shape=diamond]; |
| 96 | + "Retries < 3?" [shape=diamond]; |
| 97 | + "Proceed to merge" [shape=doublecircle]; |
| 98 | + "Give up" [shape=doublecircle]; |
| 99 | +
|
| 100 | + "Wait 5 min" -> "Run fix-pr"; |
| 101 | + "Run fix-pr" -> "Push changes"; |
| 102 | + "Push changes" -> "Wait 5 min for CI"; |
| 103 | + "Wait 5 min for CI" -> "CI green?"; |
| 104 | + "CI green?" -> "Proceed to merge" [label="yes"]; |
| 105 | + "CI green?" -> "Retries < 3?" [label="no"]; |
| 106 | + "Retries < 3?" -> "Wait 5 min" [label="yes"]; |
| 107 | + "Retries < 3?" -> "Give up" [label="no"]; |
| 108 | +} |
| 109 | +``` |
| 110 | + |
| 111 | +For each retry: |
| 112 | + |
| 113 | +1. **Wait 5 minutes** for Copilot review and CI to arrive: |
| 114 | + ```bash |
| 115 | + sleep 300 |
| 116 | + ``` |
| 117 | + |
| 118 | +2. **Invoke `/fix-pr`** to address review comments, CI failures, and coverage gaps. |
| 119 | + |
| 120 | +3. **Push fixes:** |
| 121 | + ```bash |
| 122 | + git push |
| 123 | + ``` |
| 124 | + |
| 125 | +4. **Wait 5 minutes** for CI to re-run: |
| 126 | + ```bash |
| 127 | + sleep 300 |
| 128 | + ``` |
| 129 | + |
| 130 | +5. **Check CI status:** |
| 131 | + ```bash |
| 132 | + REPO=$(gh repo view --json nameWithOwner --jq .nameWithOwner) |
| 133 | + HEAD_SHA=$(gh api repos/$REPO/pulls/$PR | python3 -c "import sys,json; print(json.load(sys.stdin)['head']['sha'])") |
| 134 | + gh api repos/$REPO/commits/$HEAD_SHA/check-runs | python3 -c " |
| 135 | + import sys,json |
| 136 | + runs = json.load(sys.stdin)['check_runs'] |
| 137 | + failed = [r['name'] for r in runs if r.get('conclusion') not in ('success', 'skipped', None)] |
| 138 | + pending = [r['name'] for r in runs if r.get('conclusion') is None and r['status'] != 'completed'] |
| 139 | + if pending: |
| 140 | + print('PENDING: ' + ', '.join(pending)) |
| 141 | + elif failed: |
| 142 | + print('FAILED: ' + ', '.join(failed)) |
| 143 | + else: |
| 144 | + print('GREEN') |
| 145 | + " |
| 146 | + ``` |
| 147 | + |
| 148 | + - If `GREEN`: break out of loop, proceed to merge. |
| 149 | + - If `PENDING`: wait another 2 minutes, re-check once. |
| 150 | + - If `FAILED`: increment retry counter, continue loop. |
| 151 | + |
| 152 | +**After 3 failed retries:** record status as `fix-pr failed (3 retries)`, leave PR open, move to next issue. |
| 153 | + |
| 154 | +## Step 5: Merge |
| 155 | + |
| 156 | +```bash |
| 157 | +gh pr merge $PR --squash --delete-branch |
| 158 | +``` |
| 159 | + |
| 160 | +**If merge fails** (e.g., conflict): record status as `merge failed`, leave PR open, move to next issue. |
| 161 | + |
| 162 | +## Step 6: Sync |
| 163 | + |
| 164 | +Return to main for the next issue: |
| 165 | + |
| 166 | +```bash |
| 167 | +git checkout main && git pull origin main |
| 168 | +``` |
| 169 | + |
| 170 | +This ensures the next issue (especially a Rule that depends on a just-merged Model) sees all prior work. |
| 171 | + |
| 172 | +## Step 7: Report |
| 173 | + |
| 174 | +After all issues are processed, print the summary table: |
| 175 | + |
| 176 | +``` |
| 177 | +=== Meta-Power Batch Report === |
| 178 | +
|
| 179 | +| Issue | Title | Status | |
| 180 | +|-------|------------------------------------|---------------------------| |
| 181 | +| #108 | [Model] LCS | merged | |
| 182 | +| #103 | [Model] SubsetSum | merged | |
| 183 | +| #109 | [Rule] LCS → MIS | merged | |
| 184 | +| #110 | [Rule] LCS → ILP | fix-pr failed (3 retries) | |
| 185 | +| #97 | [Rule] BinPacking → ILP | merged | |
| 186 | +| #91 | [Rule] CVP → QUBO | skipped (plan failed) | |
| 187 | +
|
| 188 | +Completed: 4/6 | Skipped: 1 | Failed: 1 |
| 189 | +``` |
| 190 | + |
| 191 | +## Constants |
| 192 | + |
| 193 | +| Name | Value | Rationale | |
| 194 | +|------|-------|-----------| |
| 195 | +| `MAX_RETRIES` | 3 | Most issues fix in 1-2 rounds | |
| 196 | +| `CI_WAIT` | 5 min | GitHub Actions typical completion time | |
| 197 | +| `PENDING_EXTRA_WAIT` | 2 min | One grace period for slow CI | |
| 198 | + |
| 199 | +## Common Failure Modes |
| 200 | + |
| 201 | +| Symptom | Cause | Mitigation | |
| 202 | +|---------|-------|------------| |
| 203 | +| `issue-to-pr` comments and stops | Issue template incomplete | Skip; user must fix the issue | |
| 204 | +| `make run-plan` exits non-zero | Implementation too complex for 500 turns | Skip; needs manual work | |
| 205 | +| CI red after 3 retries | Deep bug or flaky test | Leave PR open for human review | |
| 206 | +| Merge conflict | Concurrent push to main | Leave PR open; manual rebase needed | |
| 207 | +| Rule fails because model missing | Model issue was skipped earlier | Expected; skip rule too | |
0 commit comments