--- name: issue-controller description: > Issue Agent OS controller loop. Pulls issues from a GitHub issue queue (priority + dependency resolved), fans out triage to parallel triager agents, dispatches coder / reviewer / splitter / planner / debugger workers based on verdicts, drives review loops, merges approved PRs, and repeats until the queue is empty. Use when the user asks to "process issues", "run the issue controller", "work through the queue", or similar. Do NOT use for single-issue ad-hoc work — this is the full automated loop. invocation_posture: manual version: 0.1.0 --- # Issue Controller Automated controller loop for the Issue Agent OS. You (the main session) become the thin dispatcher. You never read issue content yourself — all judgment lives in the sub-agents you spawn. ## Invocation The user provides a repository and optionally a max_workers count: - "Process the issue queue for owner/repo" - "Run the issue controller for owner/repo, max_workers=3" Default max_workers is 6. Default max_review_rounds is 3. ## Prerequisites Before starting the loop, ensure agent labels exist on the repo. Run once: ```bash gh label create "agent:queued" --color "0e8a16" --description "Queued for Issue Agent OS" --repo 2>/dev/null || true gh label create "agent:triaging" --color "1d76db" --description "Being triaged" --repo 2>/dev/null || true gh label create "agent:in-progress" --color "fbca04" --description "Worker actively implementing" --repo 2>/dev/null || true gh label create "agent:splitting" --color "5319e7" --description "Being decomposed" --repo 2>/dev/null || true gh label create "agent:planning" --color "c5def5" --description "Design in progress" --repo 2>/dev/null || true gh label create "agent:review" --color "fbca04" --description "PR waiting for merge" --repo 2>/dev/null || true gh label create "agent:done" --color "0e8a16" --description "Completed" --repo 2>/dev/null || true gh label create "agent:blocked" --color "d73a4a" --description "Blocked, needs intervention" --repo 2>/dev/null || true gh label create "agent:deferred" --color "e4e669" --description "Deferred, needs clarification" --repo 2>/dev/null || true gh label create "agent:rejected" --color "cfd3d7" --description "Rejected by triage" --repo 2>/dev/null || true gh label create "agent:needs-human" --color "d876e3" --description "Escalated to human" --repo 2>/dev/null || true ``` ## Main Loop ``` loop: TRIAGE PHASE → DISPATCH PHASE → COMPLETION PHASE → repeat ``` ### Triage Phase 1. Count available slots: `max_workers - active_workers`. 2. If slots > 0, pull eligible issues: ```bash node scripts/lib/issue-driven-os-queue.js next --repo --limit ``` 3. For each returned issue, label it `agent:triaging` and spawn a **triager** agent in the background: ``` Agent(type="triager", prompt="Triage issue # in repo ", run_in_background=true) ``` On Codex: `spawn_agent("triager", "Triage issue # in repo ")` 4. Spawn all triagers in parallel (one message, multiple Agent calls). ### Dispatch Phase As triager agents complete, read their verdict and dispatch: - **execute**: Create worktree, label `agent:in-progress`, spawn **coder** in background with the triager's brief and worktree path. - **split**: Label `agent:splitting`, spawn **splitter** in background. - **plan_then_execute**: Label `agent:planning`, spawn **planner** in background. - **investigate**: Create worktree, label `agent:in-progress`, spawn **debugger** in background with the triager's brief and worktree path. - **defer / reject / escalate**: Triager already posted a GitHub comment and (for reject) closed the issue. Update labels. No worker needed. Slot stays free. ### Completion Phase As worker agents complete, handle their results: - **Coder done**: The coder already created a Draft PR and pushed. Spawn **reviewer** in background with the PR number and issue brief. The reviewer posts its review directly on the PR via `gh pr review`. - **Reviewer approved**: Merge the PR and close the issue: 1. Mark PR ready: `gh pr ready ` 2. Wait for CI to pass: poll `gh pr checks --json name,state,conclusion` until all checks show `conclusion: "SUCCESS"`. Do NOT use `--watch`. 3. Merge: `gh pr merge --squash --delete-branch`. If GitHub reports "still checking mergeable status", retry after 5 seconds. 4. The issue auto-closes via "Closes #N" in the PR body. 5. Label issue `agent:done`, release lease, clean up worktree, free slot. - **Reviewer needs changes**: The reviewer already posted REQUEST_CHANGES on the PR. If review rounds < max, re-spawn **coder** with the PR number (coder reads review comments, fixes, pushes). Otherwise, label `agent:blocked`, post comment on both issue and PR, free slot. - **Splitter done**: Label parent `agent:blocked` (waiting for children). Children are already `agent:queued`. Free slot. - **Planner done**: Create worktree, spawn **coder** with the plan as brief. - **Debugger done with fix**: Spawn **reviewer** with the diff. - **Debugger done without fix**: Post findings as comment on issue, label `agent:blocked`, free slot. ## Worktree Management Create worktrees before spawning coders or debuggers: ```bash node -e " const ws = require('./scripts/lib/issue-driven-os-workspace'); const paths = require('./scripts/lib/issue-driven-os-state-store').buildRuntimePaths({repo: ''}); ws.createIssueWorktree({issueNumber: , runtimePaths: paths}).then(r => console.log(JSON.stringify(r))); " ``` ## Lease Management Acquire leases before dispatching, release after completion or blocking: ```bash node -e " const ss = require('./scripts/lib/issue-driven-os-state-store'); const paths = ss.buildRuntimePaths({repo: ''}); ss.acquireIssueLease({issueNumber: , runtimePaths: paths}).then(r => console.log(JSON.stringify(r))); " ``` ## Label Transitions Use `gh issue edit --add-label