diff --git a/agents/issue-worker/agent.md b/agents/issue-worker/agent.md index a250013..c0ffc79 100644 --- a/agents/issue-worker/agent.md +++ b/agents/issue-worker/agent.md @@ -1,13 +1,13 @@ --- name: issue-worker -description: Autonomous agent that works on a single issue in an isolated git worktree -tools: Bash, Read, Write, Edit, Glob, Grep, TodoWrite, Task +description: Autonomous agent that implements a single issue in an isolated git worktree +tools: Bash, Read, Write, Edit, Glob, Grep, TodoWrite skills: gitea, issue-writing --- # Issue Worker Agent -Autonomously implements a single issue in an isolated git worktree. +Autonomously implements a single issue in an isolated git worktree. Creates a PR and returns - the orchestrator handles review. ## Input @@ -86,26 +86,7 @@ Closes #" Capture the PR number from the output (e.g., "Pull Request #42 created"). -### 6. Review Loop - -Spawn the `code-reviewer` agent **synchronously** to review the PR in the current worktree: - -``` -Task tool with: - - subagent_type: "code-reviewer" - - run_in_background: false - - prompt: "Review PR #. Working directory: " -``` - -Based on review feedback: -- **If approved**: Proceed to cleanup -- **If needs work**: - 1. Address the review feedback - 2. Commit and push the fixes - 3. Trigger another review - 4. Repeat until approved (max 3 iterations to avoid infinite loops) - -### 7. Cleanup Worktree +### 6. Cleanup Worktree Always clean up, even if earlier steps failed: @@ -114,20 +95,21 @@ cd git worktree remove ../-issue- --force ``` -### 8. Final Summary +### 7. Final Summary -**IMPORTANT**: Your final output must be a concise summary (5-10 lines max) for the spawning process: +**IMPORTANT**: Your final output must be a concise summary for the orchestrator: ``` -Issue #: -Status: <completed|partial|blocked> -PR: #<PR_NUMBER> (<url>) -Changes: <1-2 sentence summary> -Review: <approved|needs-work|skipped> -Notes: <any blockers or important details> +ISSUE_WORKER_RESULT +issue: <ISSUE_NUMBER> +pr: <PR_NUMBER> +branch: <branch-name> +status: <success|partial|failed> +title: <issue title> +summary: <1-2 sentence description of changes> ``` -Do NOT include verbose logs or intermediate output - only this final summary. +This format is parsed by the orchestrator. Do NOT include verbose logs - only this summary. ## Important Guidelines @@ -144,3 +126,4 @@ If you encounter an error: 1. Try to recover if possible 2. If unrecoverable, create a PR with partial work and explain the blocker 3. Always run the cleanup step +4. Report status as "partial" or "failed" in summary diff --git a/commands/spawn-issues.md b/commands/spawn-issues.md index 9e3b812..ca5ff7a 100644 --- a/commands/spawn-issues.md +++ b/commands/spawn-issues.md @@ -1,11 +1,12 @@ --- -allowed-tools: Bash, Task, Read -description: Spawn parallel background agents to work on multiple issues simultaneously +allowed-tools: Bash, Task, Read, TaskOutput +description: Orchestrate parallel issue implementation with review cycles +argument-hint: <issue-number> [<issue-number>...] --- -# Spawn Issues +# Spawn Issues (Orchestrator) -Spawn background agents to work on multiple issues in parallel. Each agent works in an isolated git worktree. +Orchestrate parallel issue implementation: spawn workers, review PRs, fix feedback, until all approved. ## Arguments @@ -13,13 +14,29 @@ One or more issue numbers separated by spaces: `$ARGUMENTS` Example: `/spawn-issues 42 43 44` -## Process +## Orchestration Flow -1. **Validate arguments**: Ensure at least one issue number is provided -2. **Get repo info**: Determine repository path and name -3. **Fetch issue titles**: Get title for each issue (for display) -4. **Spawn agents**: For each issue, spawn a background `issue-worker` agent -5. **Report**: Display summary table with agent IDs +``` +┌─────────────────────────────────────────────────────────────┐ +│ spawn-issues │ +│ (orchestrator) │ +├─────────────────────────────────────────────────────────────┤ +│ Phase 1: Implementation │ +│ ├── Spawn issue-worker agents (background, parallel) │ +│ ├── Wait for all workers to complete │ +│ └── Collect PR numbers from results │ +├─────────────────────────────────────────────────────────────┤ +│ Phase 2: Review Loop (for each PR) │ +│ ├── Spawn code-reviewer (background) │ +│ ├── Wait for review │ +│ ├── If needs work → spawn pr-fixer (background) │ +│ ├── Wait for fix │ +│ └── Repeat until approved (max 3 iterations per PR) │ +├─────────────────────────────────────────────────────────────┤ +│ Phase 3: Report │ +│ └── Display final status table │ +└─────────────────────────────────────────────────────────────┘ +``` ## Implementation @@ -38,93 +55,189 @@ REPO_PATH=$(pwd) REPO_NAME=$(basename $REPO_PATH) ``` -### Step 3: For Each Issue +### Step 3: Phase 1 - Spawn Issue Workers -For each issue number in the arguments: - -1. Fetch issue title using `tea issues <number>` (just to verify it exists and get the title) - -2. Spawn background agent using Task tool: - ``` - Task tool with: - - subagent_type: "general-purpose" - - run_in_background: true - - prompt: See agent prompt below - ``` - -### Agent Prompt - -For each issue, use this prompt: +For each issue number, spawn a background issue-worker agent: ``` -You are an issue-worker agent. Work on issue #<NUMBER> autonomously. +Task tool with: + - subagent_type: "general-purpose" + - run_in_background: true + - prompt: <issue-worker prompt below> +``` + +**Issue Worker Prompt:** +``` +You are an issue-worker agent. Implement issue #<NUMBER> autonomously. Context: - Repository path: <REPO_PATH> - Repository name: <REPO_NAME> - Issue number: <NUMBER> -Instructions from @agents/issue-worker/agent.md: - +Process: 1. Setup worktree: - cd <REPO_PATH> - git fetch origin + cd <REPO_PATH> && git fetch origin git worktree add ../<REPO_NAME>-issue-<NUMBER> -b issue-<NUMBER>-<short-title> origin/main cd ../<REPO_NAME>-issue-<NUMBER> -2. Get issue details: - tea issues <NUMBER> --comments +2. Get issue: tea issues <NUMBER> --comments -3. Plan with TodoWrite, then implement the changes +3. Plan with TodoWrite, implement the changes -4. Commit: - git add -A && git commit with message "...\n\nCloses #<NUMBER>\n\nCo-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>" +4. Commit: git add -A && git commit -m "...\n\nCloses #<NUMBER>\n\nCo-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>" -5. Push: - git push -u origin <branch-name> +5. Push: git push -u origin <branch-name> -6. Create PR: - tea pulls create --title "[Issue #<NUMBER>] <title>" --description "Closes #<NUMBER>\n\n<summary of changes>" - Capture the PR number from the output. +6. Create PR: tea pulls create --title "[Issue #<NUMBER>] <title>" --description "Closes #<NUMBER>\n\n..." + Capture the PR number. -7. Review loop: - Spawn code-reviewer agent SYNCHRONOUSLY (run_in_background: false) to review the PR: - Task tool with subagent_type: "code-reviewer", prompt: "Review PR #<PR_NUMBER>. Working directory: <WORKTREE_PATH>" +7. Cleanup: cd <REPO_PATH> && git worktree remove ../<REPO_NAME>-issue-<NUMBER> --force - If review says "needs work": - - Address the feedback - - Commit and push fixes - - Re-run the review - - Repeat until approved (max 3 iterations) +8. Output EXACTLY this format (orchestrator parses it): + ISSUE_WORKER_RESULT + issue: <NUMBER> + pr: <PR_NUMBER> + branch: <branch-name> + status: <success|partial|failed> + title: <issue title> + summary: <1-2 sentence description> -8. Cleanup (ALWAYS do this, even if earlier steps failed): - cd <REPO_PATH> && git worktree remove ../<REPO_NAME>-issue-<NUMBER> --force - -9. Final output - ONLY output this concise summary (5-10 lines max): - Issue #<NUMBER>: <title> - Status: <completed|partial|blocked> - PR: #<PR_NUMBER> - Changes: <1-2 sentence summary> - Review: <approved|needs-work|skipped> - Notes: <any blockers or important details> - -Work autonomously. Make judgment calls on ambiguous requirements. If blocked, note it in the PR description. +Work autonomously. If blocked, note it in PR description and report status as partial/failed. ``` -### Step 4: Report +Display progress: +``` +Phase 1: Implementation +Spawning issue-worker agents... + - Issue #42: spawned (task_id: xxx) + - Issue #43: spawned (task_id: xxx) + - Issue #44: spawned (task_id: xxx) +``` -After spawning all agents, display: +### Step 4: Wait for Workers + +Use TaskOutput to wait for each worker to complete. Parse the ISSUE_WORKER_RESULT from each output to extract: +- issue number +- pr number +- status + +Build a tracking table: +``` +| Issue | PR | Status | +|-------|-----|---------| +| #42 | #55 | success | +| #43 | #56 | success | +| #44 | - | failed | +``` + +### Step 5: Phase 2 - Review Loop + +For each PR that was created successfully, run a review loop (max 3 iterations): ``` -Spawned <N> issue-worker agents: +for each PR: + iteration = 0 + while iteration < 3: + # Spawn code-reviewer in background + Task tool with: + - subagent_type: "code-reviewer" + - run_in_background: true + - prompt: "Review PR #<PR_NUMBER> in <REPO_PATH>. Output EXACTLY: + REVIEW_RESULT + pr: <PR_NUMBER> + verdict: <approved|needs-work> + summary: <1-2 sentences>" -| Issue | Title | Status | -|-------|--------------------------|------------| -| #42 | Add /commit command | spawned | -| #43 | Add /pr command | spawned | -| #44 | Add CI status | spawned | + # Wait for review + Use TaskOutput to get result, parse verdict -Agents working in background. Monitor with: -- Check PR list: tea pulls -- Check worktrees: git worktree list + if verdict == "approved": + mark PR as approved, break + + if verdict == "needs-work": + # Spawn pr-fixer in background + Task tool with: + - subagent_type: "general-purpose" + - run_in_background: true + - prompt: <pr-fixer prompt - address feedback, commit, push> + + # Wait for fix + Use TaskOutput to get result + + iteration++ ``` + +Display progress: +``` +Phase 2: Review + PR #55: reviewing... + PR #55: needs work → fixing... + PR #55: re-reviewing... + PR #55: approved ✓ + PR #56: reviewing... + PR #56: approved ✓ +``` + +### Step 6: Phase 3 - Final Report + +Display final status: + +``` +Completed: 3 issues processed + +| Issue | PR | Implementation | Review | +|-------|-----|----------------|----------| +| #42 | #55 | success | approved | +| #43 | #56 | success | approved | +| #44 | - | failed | - | + +Summary: +- 2 PRs created and approved +- 1 issue failed (see PR description for details) +``` + +## PR Fixer Prompt + +When spawning pr-fixer for a PR that needs work: + +``` +You are a pr-fixer agent. Address review feedback on PR #<NUMBER>. + +Context: +- Repository path: <REPO_PATH> +- Repository name: <REPO_NAME> +- PR number: <NUMBER> + +Process: +1. Get feedback: tea pulls <NUMBER> --comments + +2. Setup worktree from PR branch: + cd <REPO_PATH> && git fetch origin + git worktree add ../<REPO_NAME>-pr-<NUMBER> origin/<branch-name> + cd ../<REPO_NAME>-pr-<NUMBER> + git checkout <branch-name> + +3. Address each piece of feedback + +4. Commit and push: + git add -A && git commit -m "Address review feedback\n\nCo-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>" + git push + +5. Cleanup: cd <REPO_PATH> && git worktree remove ../<REPO_NAME>-pr-<NUMBER> --force + +6. Output EXACTLY: + PR_FIXER_RESULT + pr: <NUMBER> + status: <fixed|partial|failed> + changes: <summary of fixes> + +Work autonomously. If feedback is unclear, make reasonable judgment calls. +``` + +## Error Handling + +- If an issue-worker fails, continue with others +- If a review fails, mark as "review-failed" and continue +- If pr-fixer fails after 3 iterations, mark as "needs-manual-review" +- Always report final status even if some items failed