Skip to content

Commit 2cfb1b7

Browse files
GiggleLiuclaude
andcommitted
Add meta-power skill for batch issue resolution
Orchestrates end-to-end pipeline: issue-to-pr -> make run-plan -> copilot-review -> fix-pr loop (3 retries) -> merge. Processes all open [Model] issues first, then [Rule] issues. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7875f2b commit 2cfb1b7

3 files changed

Lines changed: 262 additions & 0 deletions

File tree

.claude/CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Rust library for NP-hard problem reductions. Implements computational problems w
1212
- [write-model-in-paper](skills/write-model-in-paper/SKILL.md) -- Write or improve a problem-def entry in the Typst paper. Covers formal definition, background, example with visualization, and algorithm list.
1313
- [write-rule-in-paper](skills/write-rule-in-paper/SKILL.md) -- Write or improve a reduction-rule entry in the Typst paper. Covers complexity citation, self-contained proof, detailed example, and verification.
1414
- [release](skills/release/SKILL.md) -- Create a new crate release. Determines version bump from diff, verifies tests/clippy, then runs `make release`.
15+
- [meta-power](skills/meta-power/SKILL.md) -- Batch-resolve all open `[Model]` and `[Rule]` issues autonomously: plan, implement, review, fix CI, merge — in dependency order (models first).
1516

1617
## Commands
1718
```bash

.claude/skills/meta-power/SKILL.md

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
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 |
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Design: meta-power skill
2+
3+
## Purpose
4+
5+
Batch-resolve open `[Model]` and `[Rule]` GitHub issues end-to-end with full autonomy: plan, implement, review, fix, merge.
6+
7+
## Architecture
8+
9+
**Outer orchestrator** pattern: meta-power runs in the main Claude session and shells out to `make run-plan` for each issue's implementation. This keeps the orchestrator's context clean while delegating heavy work to subprocess sessions.
10+
11+
## Pipeline per Issue
12+
13+
```
14+
Phase 1: Plan /issue-to-pr <number> → branch + PR with plan
15+
Phase 2: Execute make run-plan → subprocess implements the plan
16+
Phase 3: Review push, make copilot-review
17+
Phase 4: Fix loop (up to 3 retries)
18+
sleep 5m → /fix-pr → push → sleep 5m → check CI
19+
if CI green → break
20+
Phase 5: Merge gh pr merge --squash
21+
Phase 6: Sync git checkout main && git pull
22+
```
23+
24+
## Ordering
25+
26+
1. All `[Model]` issues first (ascending issue number)
27+
2. All `[Rule]` issues second (ascending issue number)
28+
29+
No DAG — models-first is sufficient since rules depend on models.
30+
31+
## Error Handling
32+
33+
Every failure → log + skip to next issue. Never block the batch.
34+
35+
| Phase | Failure | Action |
36+
|-------|---------|--------|
37+
| Plan | Validation fails | Skip |
38+
| Execute | Subprocess exits non-zero | Skip |
39+
| Fix loop | 3 retries exhausted | Leave PR open, skip |
40+
| Merge | Conflict | Leave PR open, skip |
41+
42+
## Parameters
43+
44+
- `MAX_RETRIES = 3`
45+
- `CI_WAIT = 5 minutes`
46+
- Auto-merge: yes (squash)
47+
- Summary table printed at end
48+
49+
## Design Decisions
50+
51+
- **Why outer orchestrator?** Each `make run-plan` gets a fresh 500-turn context. The outer session just monitors and coordinates.
52+
- **Why models-first only?** Rules rarely depend on each other. If a rule's source model is missing, `issue-to-pr` validation catches it and skips.
53+
- **Why 3 retries?** Most fixable issues resolve in 1-2 rounds. More retries burn tokens on genuinely hard problems.
54+
- **Why auto-merge?** Full CI + Copilot review provides sufficient quality gate. The point of the skill is batch autonomy.

0 commit comments

Comments
 (0)