Skip to content

Commit 896732d

Browse files
authored
feat: add workflow skills (#15)
* feat: add workflow skills (review-and-fix, dispatch-worktree-task, review-with-research) - review-and-fix: review a branch with a domain skill, document findings, dispatch parallel worktree agents to fix each, cherry-pick and verify - dispatch-worktree-task: dispatch a planned task to a background worktree subagent (moved from diecut, generalized) - review-with-research: review a branch with parallel code-review and research subagents (moved from diecut, generalized) * fix: address audit findings across workflow skills - Sharpen review-and-fix trigger to avoid overlap with review-with-research - Cross-reference between review-and-fix and dispatch-worktree-task explaining why each uses a different worktree strategy - Specify subagent types in review-with-research (Explore for review, general-purpose with sonnet for research) * fix: clarify cherry-pick mechanics and .worktrees gitignore prerequisite - Simplify review-and-fix step 6: Task tool result provides the branch name directly, no separate lookup needed - Add .gitignore reminder for .worktrees/ in dispatch-worktree-task and review-with-research * fix: address audit findings across workflow skills Fix 3 bugs, 6 design issues, and 2 minor issues found during audit of dispatch-worktree-task, review-and-fix, and review-with-research skills. Key fixes: - Add explicit cwd instruction for subagents in manual worktrees - Handle already-checked-out branch with --detach in review-with-research - Add clean working tree prerequisite before cherry-pick - Replace "smoke test" with "reproduction command" for consistency - Add Task tool parameter tables for review-with-research subagents - Add wave sizing guidance for parallel agent dispatch - Clarify domain skill invocation (read reference files, don't invoke Skill tool) - Clarify file access patterns (git show for baseline, direct read for branch) - Make .gitignore check actionable (check and add, not just "ensure") - Add worktree cleanup step to dispatch-worktree-task * fix: address workflow-level issues across 3 skills - dispatch-worktree-task: move push out of subagent to main session, add plan completeness gate, subagent failure instructions, stale worktree handling, reproduction escape hatch for refactorings - review-and-fix: fix same-file sequencing (cherry-pick before second worktree), add zero-findings early exit, wave strategy, per-cherry-pick validation, simplify findings file handling, integrate task list as dispatch manifest, add user checkpoint before push - review-with-research: add research topic derivation step, merge synthesis+verdict with reconciliation guidance, add edge case handling (empty diff, inconclusive research, contradictions), add handoff to review-and-fix * feat: add iterative-review-fix skill Serial review-fix loop that dispatches a reviewer agent, then a fixer agent, commits, and repeats until findings converge to zero, plateau, or hit an iteration cap.
1 parent 7c35edb commit 896732d

4 files changed

Lines changed: 646 additions & 0 deletions

File tree

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
---
2+
name: dispatch-worktree-task
3+
description: "Use when a task has a clear implementation plan and should be executed by a subagent in an isolated git worktree. Triggers on phrases like: dispatch this, send to a subagent, work on this in a worktree, dispatch to worktree, background task, isolated execution."
4+
---
5+
6+
# Dispatch Worktree Task
7+
8+
## Overview
9+
10+
Packages a task with a clear plan, creates an isolated git worktree, and dispatches a subagent to implement, validate, verify, and commit in the background. The main session reviews, pushes, and creates the PR.
11+
12+
**Core principle:** Plan in the main session, execute in isolation, verify before pushing.
13+
14+
## When to Use
15+
16+
- Implementation plan is written and approved
17+
- Task is self-contained (no back-and-forth needed)
18+
- You want background execution while continuing other work
19+
20+
**When NOT to use:**
21+
- Task requires interactive clarification mid-implementation
22+
- Changes span multiple repos or need coordination with other branches
23+
- Quick single-file fix (just do it inline)
24+
25+
## Workflow
26+
27+
```dot
28+
digraph dispatch {
29+
rankdir=TB;
30+
node [shape=box];
31+
32+
plan [label="1. Prepare implementation plan"];
33+
worktree [label="2. Create git worktree\non new branch"];
34+
dispatch [label="3. Dispatch subagent\n(implement, verify, commit)"];
35+
review [label="4. Review diff,\npush + PR"];
36+
cleanup [label="5. Remove worktree"];
37+
38+
plan -> worktree -> dispatch -> review -> cleanup;
39+
}
40+
```
41+
42+
### 1. Prepare the implementation plan
43+
44+
Write a detailed plan that includes:
45+
- **Context** — why this change, what was tried/rejected
46+
- **Step-by-step plan** — numbered, specific files and code patterns
47+
- **Pre-commit validation** — exact commands to run (read from project's CLAUDE.md)
48+
- **Reproduction command** — a command that exercises the original scenario (bug or feature). Adapt paths, use temp dirs, etc., but exercise the same behavior. The subagent must run it after implementing and confirm the fix works.
49+
- **What NOT to do** — anti-patterns to avoid
50+
51+
### 1b. Verify plan completeness
52+
53+
Before proceeding, confirm the plan includes all required sections:
54+
55+
- [ ] **Context** — why this change, what was tried/rejected
56+
- [ ] **Step-by-step plan** — numbered, specific files and code patterns
57+
- [ ] **Pre-commit validation** — exact commands from project's CLAUDE.md
58+
- [ ] **Reproduction command** — a command that exercises the original scenario. For refactorings or structural changes where there's no behavioral scenario, reproduction = "existing tests pass and restructured code compiles" — state this explicitly rather than omitting reproduction.
59+
- [ ] **Anti-patterns** — what NOT to do
60+
61+
If any section is missing or vague, fill it in before creating the worktree.
62+
63+
### 2. Create worktree
64+
65+
```bash
66+
git worktree add .worktrees/<branch-name> -b <branch-name> main
67+
```
68+
69+
Use `.worktrees/` directory. Check that `.worktrees/` is in `.gitignore`. If not, add it before creating the worktree. Branch name should match the work (e.g., `fix/cache-lock-fs4`).
70+
71+
> **Stale worktree/branch:** If the branch or worktree already exists from a previous attempt, remove them first (`git worktree remove .worktrees/<branch-name>` and `git branch -D <branch-name>`) or reuse after verifying the worktree state is clean (`git status` in the worktree).
72+
73+
> **Why manual worktrees instead of `isolation: "worktree"`?** The branch is the deliverable — it gets pushed and PR'd. You need a named branch you control. For fan-out/fan-in where you cherry-pick temporary commits back, see `review-and-fix`.
74+
75+
### 3. Dispatch subagent
76+
77+
Use the Task tool with these settings:
78+
79+
| Parameter | Value |
80+
|-----------|-------|
81+
| `subagent_type` | `general-purpose` |
82+
| `mode` | `bypassPermissions` |
83+
| `run_in_background` | `true` |
84+
85+
**Prompt must include:**
86+
- Worktree path and branch name
87+
- **Explicit `cd <worktree-absolute-path>` as the subagent's first action.** The Task tool starts subagents in the parent's working directory, not the worktree.
88+
- Full implementation plan
89+
- Pre-commit validation commands (from project CLAUDE.md)
90+
- **Reproduction command** — a command that exercises the same scenario as the original report. Adapt for the worktree context (temp output dirs, etc.) but verify the same behavior.
91+
- Commit message to use (conventional commits)
92+
- Project conventions (no co-authored-by lines, etc.)
93+
94+
**Subagent execution order:**
95+
1. Implement the change
96+
2. Run pre-commit validation (from project CLAUDE.md)
97+
3. **Reproduce the original scenario** — build and run a command that exercises the same behavior from the original report. Adapt for safety (temp dirs, non-destructive variants) but verify the same scenario.
98+
4. Commit (do NOT push — the main session handles push after review)
99+
100+
**On failure:** If the implementation is incomplete, the plan doesn't match reality, or validation/reproduction fails — the subagent must NOT commit. Instead, report what happened: what was attempted, what failed, and what state the worktree is in. The main session will decide next steps.
101+
102+
If reproduction fails but the fix is otherwise correct, the subagent should fix the issue and re-verify. If it cannot fix it, do not commit — report the failure.
103+
104+
### 4. Review, push, and create PR
105+
106+
When the agent reports back:
107+
- Show `git log main..<branch> --oneline` and `git diff --stat main..<branch>`
108+
- Read the actual diff for the files listed in the implementation plan
109+
- Confirm the reproduction command passed in the agent's output
110+
- Push the branch: `git push -u origin <branch>`
111+
- Create the PR (or remind the user)
112+
113+
### 5. Clean up worktree
114+
115+
After the PR is created, remove the worktree:
116+
117+
```bash
118+
git worktree remove .worktrees/<branch-name>
119+
```
120+
121+
## Common Mistakes
122+
123+
| Mistake | Fix |
124+
|---------|-----|
125+
| No reproduction command in prompt | Always include a command that exercises the original scenario |
126+
| Reproduction command is just "run tests" | Tests verify correctness; reproduction verifies the original complaint is resolved |
127+
| Reproduction command is destructive | Adapt for safety — use temp dirs, non-destructive variants — but verify the same behavior |
128+
| Vague subagent prompt | Paste the full plan — subagents have no prior context |
129+
| Not verifying the diff | Always read the key file diffs before creating the PR |
130+
| Skipping pre-commit in prompt | Agent won't know to run validation unless told |
131+
| Forgetting the PR | Always create or remind about PR after reviewing |
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
---
2+
name: iterative-review-fix
3+
description: "Use when code needs repeated review-fix cycles until clean. Dispatches a reviewer agent, then a fixer agent, commits, and repeats until findings converge to zero or a cap is reached. Triggers on: iterate until clean, review fix loop, converge, repeated review, keep fixing until done, iterative review."
4+
---
5+
6+
# Iterative Review-Fix Loop
7+
8+
## Overview
9+
10+
Serial review-fix loop: dispatch a read-only reviewer, then a fixer, commit, repeat until findings hit zero, plateau, or an iteration cap. Designed for convergence, not throughput.
11+
12+
**Core principle:** One reviewer, one fixer, per iteration. Each pass commits directly on the current branch. Commits are revert points.
13+
14+
## When to Use
15+
16+
- Code needs multiple rounds of review to converge on clean
17+
- User says "iterate until clean", "keep fixing", or "review fix loop"
18+
- A single review-and-fix pass is insufficient (findings cascade)
19+
20+
**When NOT to use:**
21+
- Single-pass review with parallel dispatch — use `review-and-fix`
22+
- Research-backed review — use `review-with-research`
23+
- One specific bug fix — just fix it inline
24+
25+
## Workflow
26+
27+
### 1. Capture Inputs
28+
29+
Determine three things before starting the loop:
30+
31+
**Review focus** — what to look for. The user provides criteria inline or as a file path. Read the file if a path is given.
32+
33+
**Scope** — what to review. Default: branch diff vs main.
34+
```bash
35+
git diff main --stat
36+
git log main..HEAD --oneline
37+
```
38+
If the user specifies a directory or file list, use that instead.
39+
40+
**Iteration cap** — default 5. The user can override.
41+
42+
Read the project's `CLAUDE.md` for pre-commit validation commands — the fixer needs these.
43+
44+
### 2. Loop (iterations 1..cap)
45+
46+
#### 2a. Dispatch reviewer
47+
48+
Launch a read-only subagent:
49+
50+
| Parameter | Value |
51+
|-----------|-------|
52+
| `subagent_type` | `Explore` |
53+
| `run_in_background` | `true` |
54+
55+
**Reviewer prompt:**
56+
57+
```
58+
You are performing review pass {N} of an iterative review-fix cycle.
59+
60+
## Review Focus
61+
{criteria — inline text or file contents}
62+
63+
## Scope
64+
{branch diff output, directory listing, or file list}
65+
66+
## Output Format
67+
For each issue found, produce:
68+
69+
### Finding: [stable title — same title if same issue persists across passes]
70+
**Severity:** high | medium | low
71+
**File:** `path/to/file:line`
72+
**Description:** [what's wrong and why]
73+
**Fix approach:** [specific steps to fix]
74+
75+
If no issues found, respond with exactly: NO_FINDINGS
76+
```
77+
78+
**Stable titles are critical.** The main session compares findings across passes to detect plateaus. If the reviewer uses a different title for the same issue, plateau detection breaks. Instruct the reviewer to title findings by the problem, not the pass number.
79+
80+
#### 2b. Parse findings
81+
82+
Three outcomes:
83+
84+
1. **Zero findings** (`NO_FINDINGS`) — break the loop, report clean.
85+
2. **Same findings as previous pass** — plateau detected. The fixer is stuck on these issues. Break the loop, report the stuck findings.
86+
3. **New or different findings** — proceed to fixer.
87+
88+
**Plateau detection:** Compare finding titles (not full descriptions) between consecutive passes. If the set of titles is identical, it's a plateau. If a subset overlaps but new findings appeared, it's not a plateau — the fixer made partial progress.
89+
90+
#### 2c. Dispatch fixer
91+
92+
Launch a general-purpose subagent:
93+
94+
| Parameter | Value |
95+
|-----------|-------|
96+
| `subagent_type` | `general-purpose` |
97+
| `mode` | `bypassPermissions` |
98+
| `run_in_background` | `true` |
99+
100+
**Fixer prompt:**
101+
102+
```
103+
You are fixing issues found during review pass {N}.
104+
105+
## Findings
106+
{paste all findings from reviewer — full text, not just titles}
107+
108+
## Validation
109+
After making all fixes, run these commands and confirm they pass:
110+
{pre-commit validation commands from project CLAUDE.md}
111+
112+
## Commit
113+
If all fixes are made and validation passes, create a single commit:
114+
fix: address review findings (pass {N})
115+
116+
Do NOT add co-authored-by lines.
117+
Do NOT modify files beyond what the findings require.
118+
Do NOT commit if validation fails — report the failure instead.
119+
```
120+
121+
**If the fixer reports validation failure:** stop the loop immediately. Report the failure to the user with the fixer's output. Do not continue to the next pass — a broken build state will cascade.
122+
123+
#### 2d. Increment and continue
124+
125+
After a successful fixer pass, increment the counter and loop back to 2a.
126+
127+
### 3. Report
128+
129+
When the loop exits (clean, plateau, or cap), produce a summary:
130+
131+
**Clean exit:**
132+
```
133+
Review-fix loop completed in {N} passes.
134+
Pass 1: {count} findings — fixed and committed
135+
Pass 2: {count} findings — fixed and committed
136+
Pass 3: clean — no findings
137+
```
138+
139+
**Plateau exit:**
140+
```
141+
Review-fix loop plateaued after {N} passes.
142+
Pass 1: {count} findings — fixed and committed
143+
Pass 2: {count} findings — fixed and committed (partial overlap with pass 1)
144+
Pass 3: {count} findings — same as pass 2 (plateau)
145+
146+
Stuck findings:
147+
- [Finding title]: [brief description]
148+
- [Finding title]: [brief description]
149+
150+
These issues may require manual intervention or a different approach.
151+
```
152+
153+
**Cap exit:**
154+
```
155+
Review-fix loop hit iteration cap ({cap}) with {count} findings remaining.
156+
[Per-pass summary as above]
157+
158+
Remaining findings:
159+
[List findings from the last pass]
160+
```
161+
162+
## Key Conventions
163+
164+
- **Serial, not parallel.** One reviewer, one fixer per iteration. Simplicity over throughput.
165+
- **Direct on branch.** No worktrees. Each iteration commits directly. Commits are revert points.
166+
- **Fully autonomous.** No user gate between iterations. Runs until a stopping condition.
167+
- **Fixer gets full findings each pass.** Not deltas. The fixer doesn't know what previous passes did.
168+
- **One commit per pass.** Keeps history clean and gives one revert point per iteration.
169+
- **Pre-commit validation is the fixer's job.** If validation fails, the fixer does NOT commit.
170+
- **No co-authored-by lines.** Encode this in every fixer prompt.
171+
172+
## Stopping Conditions
173+
174+
| Condition | Action |
175+
|-----------|--------|
176+
| Reviewer returns `NO_FINDINGS` | Break — report clean |
177+
| Finding titles identical to previous pass | Break — report plateau with stuck findings |
178+
| Iteration counter reaches cap | Break — report cap hit with remaining findings |
179+
| Fixer reports validation failure | Break — report failure with fixer output |
180+
181+
## Common Mistakes
182+
183+
| Mistake | Fix |
184+
|---------|-----|
185+
| Reviewer uses different titles for same issue across passes | Prompt reviewer to use stable titles based on the problem |
186+
| Fixer modifies unrelated code | Prompt explicitly: only fix what's in the findings |
187+
| Skipping plateau detection | Always compare finding titles between consecutive passes |
188+
| Continuing after validation failure | Stop immediately — broken builds cascade |
189+
| Not reading project CLAUDE.md first | Pre-commit commands vary per project |
190+
| Running in parallel with other work | This skill commits directly on the branch — no concurrent modifications |

0 commit comments

Comments
 (0)