Parent: #204 | Phase 2: Multi-Agent Orchestration
Revised: The Refinery is now a Kilo CLI process inside the Town Container instead of a cloud-agent-next session. Dispatched by the Rig DO alarm when review queue entries are ready.
Goal
Automated merge review with quality gates. The Refinery is an AI agent (Kilo CLI process) that can reason about test failures and send actionable rework requests.
Flow
When a review queue entry is ready:
- Rig DO alarm fires,
processReviewQueue() detects pending entry
- DO signals container:
POST /agents/start with refinery role config
- Container spawns a Kilo CLI process (the "Refinery") that:
- Gets a git worktree with the polecat's branch
- Runs quality gates (configurable:
npm test, npm run build, lint, etc.)
- If passing → merge to default branch, push, update review queue entry via
gt_done
- If failing → reason about failures, create
REWORK_REQUEST mail to the polecat via gt_mail_send, set entry to failed
- Refinery process exits after the review completes
Quality Gate Configuration
Stored in rig config:
{
"refinery": {
"gates": ["npm test", "npm run build"],
"auto_merge": true,
"require_clean_merge": true
}
}
Refinery System Prompt
The Refinery agent needs a system prompt that:
- Explains its role (review code, run quality gates, decide merge/rework)
- Instructs on how to interpret test failures
- Instructs on writing actionable rework requests (specific, with file/line references)
- Explains merge mechanics (git merge in the worktree, push to remote)
- Uses
gt_mail_send to communicate rework requests to the polecat
Dependencies
- PR 1 (Rig DO — review queue)
- PR 4 (Town Container — process spawning)
- PR 5 (Rig DO Alarm —
processReviewQueue)
- PR 3 (Tool Plugin —
gt_done, gt_mail_send)
- PR 8 (Manual Merge Flow — review queue entries)
Acceptance Criteria
Parent: #204 | Phase 2: Multi-Agent Orchestration
Goal
Automated merge review with quality gates. The Refinery is an AI agent (Kilo CLI process) that can reason about test failures and send actionable rework requests.
Flow
When a review queue entry is ready:
processReviewQueue()detects pending entryPOST /agents/startwith refinery role confignpm test,npm run build, lint, etc.)gt_doneREWORK_REQUESTmail to the polecat viagt_mail_send, set entry tofailedQuality Gate Configuration
Stored in rig config:
{ "refinery": { "gates": ["npm test", "npm run build"], "auto_merge": true, "require_clean_merge": true } }Refinery System Prompt
The Refinery agent needs a system prompt that:
gt_mail_sendto communicate rework requests to the polecatDependencies
processReviewQueue)gt_done,gt_mail_send)Acceptance Criteria
REWORK_REQUESTmail with specific failure details on failure