---
name: Server Drives Pipeline as State Machine
---

# Story 67: Server Drives Pipeline as State Machine

## User Story

As a Story Kit user, I want the server to automatically advance stories through the pipeline when agents complete, so that the full flow (coding, QA, merge, archive) runs without agents needing to know about pipeline transitions.

## Acceptance Criteria

- [ ] When a coder agent completes, the server automatically runs script/test in the worktree
- [ ] If script/test passes (exit 0), the server moves the story to work/3_qa/ and starts the QA agent
- [ ] If script/test fails (non-zero), the server restarts the coder with failure output
- [ ] When the QA agent completes, the server runs script/test in the worktree — if non-zero, restarts the QA agent with failure output
- [ ] If script/test passes after QA, the server moves the story to work/4_merge/ and starts the mergemaster
- [ ] When the mergemaster completes, the server runs script/test on master — if non-zero, restarts the mergemaster with failure output
- [ ] If script/test passes after merge, the server moves the story to work/5_archived/ and cleans up the worktree
- [ ] Agents no longer need to call move_story_to_merge, request_qa, or any pipeline-advancing MCP tools — the server handles all transitions
- [ ] The completion handler in agents.rs reacts to AgentStatus::Completed and triggers the next stage

## Out of Scope

- TBD
