Accept story 30: Worktree-based agent orchestration

Add git worktree isolation for concurrent story agents. Each agent now
runs in its own worktree with setup/teardown commands driven by
.story_kit/project.toml config. Agents stream output via SSE and support
start/stop lifecycle with Pending/Running/Completed/Failed statuses.

Backend: config.rs (TOML parsing), worktree.rs (git worktree lifecycle),
refactored agents.rs (broadcast streaming), agents_sse.rs (SSE endpoint).
Frontend: AgentPanel.tsx with Run/Stop buttons and streaming output log.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dave
2026-02-19 17:58:53 +00:00
parent 7e56648954
commit 5e5cdd9b2f
15 changed files with 1440 additions and 281 deletions

View File

@@ -1,50 +0,0 @@
---
name: Worktree-Based Agent Orchestration
test_plan: pending
---
# Story 30: Worktree-Based Agent Orchestration
## User Story
As a user, I want to press a button in the frontend to spin up an agent that works on a story in its own git worktree, so that multiple stories can be worked on concurrently without branch conflicts.
## Acceptance Criteria
- [ ] The Rust binary can create a git worktree for a given story, on a new feature branch.
- [ ] The Rust binary can remove a git worktree and clean up the feature branch after story completion.
- [ ] Project-specific setup commands (e.g., dependency install) are configurable per-project, not hardcoded to any language or framework.
- [ ] The Rust binary can spawn an agent process (e.g., Claude Code CLI) pointed at the worktree directory.
- [ ] The backend exposes an API endpoint to start an agent for a given story (creates worktree, runs setup, spawns agent).
- [ ] The backend exposes an API endpoint to stop a running agent and optionally tear down its worktree.
- [ ] The backend tracks running agents and their status (idle/running/done/error).
- [ ] The frontend displays a "Run" button on stories that are ready to be worked on.
- [ ] The frontend shows agent status (running/done/error) for active stories.
- [ ] Agent stdout/stderr is streamed to the frontend in real time (via WebSocket or SSE).
## Configuration
Agent and worktree behavior is driven by a project-level config file (e.g., `.story_kit/config.toml`), keeping the Rust binary language-agnostic. Projects can define multiple components, each with their own working directory and setup/teardown commands:
```toml
[[component]]
name = "server"
path = "." # relative to worktree root
setup = ["cargo check"]
teardown = []
[[component]]
name = "frontend"
path = "frontend"
setup = ["pnpm install"]
teardown = []
[agent]
command = "claude"
args = ["--print", "--directory", "{{worktree_path}}"]
prompt = "Read .story_kit/README.md, then pick up story {{story_id}}"
```
Components are set up in order. Each `path` is relative to the worktree root.
## Out of Scope
- Coordinating merges to master when multiple agents finish simultaneously (see Story 29).
- Lock file implementation for multi-agent conflict prevention (see Story 29).
- Port management for dev servers within worktrees.
- Agent-to-agent communication.