Accept story 34: Per-Project Agent Configuration and Role Definitions
Replace single [agent] config with multi-agent [[agent]] roster system.
Each agent has name, role, model, allowed_tools, max_turns, max_budget_usd,
and system_prompt fields that map to Claude CLI flags at spawn time.
- AgentConfig expanded with structured fields, validated at startup (panics
on duplicate names, empty names, non-positive budgets/turns)
- Backwards-compatible: legacy [agent] format auto-wraps with deprecation warning
- AgentPool uses composite "story_id:agent_name" keys for concurrent agents
- agent_name added to AgentEvent variants, AgentInfo, start/stop/subscribe APIs
- GET /agents/config returns roster, POST /agents/config/reload hot-reloads
- POST /agents/start accepts optional agent_name, /agents/stop requires it
- SSE route updated to /agents/:story_id/:agent_name/stream
- Frontend: roster badges, agent selector dropdown, composite-key state
- Project root initialized to cwd at startup so config endpoints work immediately
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 18:46:14 +00:00
|
|
|
use crate::config::ProjectConfig;
|
2026-02-19 15:25:22 +00:00
|
|
|
use crate::http::context::{AppContext, OpenApiResult, bad_request};
|
2026-02-20 14:09:52 +00:00
|
|
|
use crate::worktree;
|
|
|
|
|
use poem_openapi::{Object, OpenApi, Tags, param::Path, payload::Json};
|
2026-02-19 15:25:22 +00:00
|
|
|
use serde::Serialize;
|
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
|
|
#[derive(Tags)]
|
|
|
|
|
enum AgentsTags {
|
|
|
|
|
Agents,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Object)]
|
Accept story 34: Per-Project Agent Configuration and Role Definitions
Replace single [agent] config with multi-agent [[agent]] roster system.
Each agent has name, role, model, allowed_tools, max_turns, max_budget_usd,
and system_prompt fields that map to Claude CLI flags at spawn time.
- AgentConfig expanded with structured fields, validated at startup (panics
on duplicate names, empty names, non-positive budgets/turns)
- Backwards-compatible: legacy [agent] format auto-wraps with deprecation warning
- AgentPool uses composite "story_id:agent_name" keys for concurrent agents
- agent_name added to AgentEvent variants, AgentInfo, start/stop/subscribe APIs
- GET /agents/config returns roster, POST /agents/config/reload hot-reloads
- POST /agents/start accepts optional agent_name, /agents/stop requires it
- SSE route updated to /agents/:story_id/:agent_name/stream
- Frontend: roster badges, agent selector dropdown, composite-key state
- Project root initialized to cwd at startup so config endpoints work immediately
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 18:46:14 +00:00
|
|
|
struct StartAgentPayload {
|
2026-02-19 17:58:53 +00:00
|
|
|
story_id: String,
|
Accept story 34: Per-Project Agent Configuration and Role Definitions
Replace single [agent] config with multi-agent [[agent]] roster system.
Each agent has name, role, model, allowed_tools, max_turns, max_budget_usd,
and system_prompt fields that map to Claude CLI flags at spawn time.
- AgentConfig expanded with structured fields, validated at startup (panics
on duplicate names, empty names, non-positive budgets/turns)
- Backwards-compatible: legacy [agent] format auto-wraps with deprecation warning
- AgentPool uses composite "story_id:agent_name" keys for concurrent agents
- agent_name added to AgentEvent variants, AgentInfo, start/stop/subscribe APIs
- GET /agents/config returns roster, POST /agents/config/reload hot-reloads
- POST /agents/start accepts optional agent_name, /agents/stop requires it
- SSE route updated to /agents/:story_id/:agent_name/stream
- Frontend: roster badges, agent selector dropdown, composite-key state
- Project root initialized to cwd at startup so config endpoints work immediately
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 18:46:14 +00:00
|
|
|
agent_name: Option<String>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Object)]
|
|
|
|
|
struct StopAgentPayload {
|
|
|
|
|
story_id: String,
|
|
|
|
|
agent_name: String,
|
2026-02-19 15:25:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Object, Serialize)]
|
|
|
|
|
struct AgentInfoResponse {
|
2026-02-19 17:58:53 +00:00
|
|
|
story_id: String,
|
Accept story 34: Per-Project Agent Configuration and Role Definitions
Replace single [agent] config with multi-agent [[agent]] roster system.
Each agent has name, role, model, allowed_tools, max_turns, max_budget_usd,
and system_prompt fields that map to Claude CLI flags at spawn time.
- AgentConfig expanded with structured fields, validated at startup (panics
on duplicate names, empty names, non-positive budgets/turns)
- Backwards-compatible: legacy [agent] format auto-wraps with deprecation warning
- AgentPool uses composite "story_id:agent_name" keys for concurrent agents
- agent_name added to AgentEvent variants, AgentInfo, start/stop/subscribe APIs
- GET /agents/config returns roster, POST /agents/config/reload hot-reloads
- POST /agents/start accepts optional agent_name, /agents/stop requires it
- SSE route updated to /agents/:story_id/:agent_name/stream
- Frontend: roster badges, agent selector dropdown, composite-key state
- Project root initialized to cwd at startup so config endpoints work immediately
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 18:46:14 +00:00
|
|
|
agent_name: String,
|
2026-02-19 15:25:22 +00:00
|
|
|
status: String,
|
|
|
|
|
session_id: Option<String>,
|
2026-02-19 17:58:53 +00:00
|
|
|
worktree_path: Option<String>,
|
2026-02-19 15:25:22 +00:00
|
|
|
}
|
|
|
|
|
|
Accept story 34: Per-Project Agent Configuration and Role Definitions
Replace single [agent] config with multi-agent [[agent]] roster system.
Each agent has name, role, model, allowed_tools, max_turns, max_budget_usd,
and system_prompt fields that map to Claude CLI flags at spawn time.
- AgentConfig expanded with structured fields, validated at startup (panics
on duplicate names, empty names, non-positive budgets/turns)
- Backwards-compatible: legacy [agent] format auto-wraps with deprecation warning
- AgentPool uses composite "story_id:agent_name" keys for concurrent agents
- agent_name added to AgentEvent variants, AgentInfo, start/stop/subscribe APIs
- GET /agents/config returns roster, POST /agents/config/reload hot-reloads
- POST /agents/start accepts optional agent_name, /agents/stop requires it
- SSE route updated to /agents/:story_id/:agent_name/stream
- Frontend: roster badges, agent selector dropdown, composite-key state
- Project root initialized to cwd at startup so config endpoints work immediately
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 18:46:14 +00:00
|
|
|
#[derive(Object, Serialize)]
|
|
|
|
|
struct AgentConfigInfoResponse {
|
|
|
|
|
name: String,
|
|
|
|
|
role: String,
|
|
|
|
|
model: Option<String>,
|
|
|
|
|
allowed_tools: Option<Vec<String>>,
|
|
|
|
|
max_turns: Option<u32>,
|
|
|
|
|
max_budget_usd: Option<f64>,
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-20 14:09:52 +00:00
|
|
|
#[derive(Object)]
|
|
|
|
|
struct CreateWorktreePayload {
|
|
|
|
|
story_id: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Object, Serialize)]
|
|
|
|
|
struct WorktreeInfoResponse {
|
|
|
|
|
story_id: String,
|
|
|
|
|
worktree_path: String,
|
|
|
|
|
branch: String,
|
|
|
|
|
base_branch: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Object, Serialize)]
|
|
|
|
|
struct WorktreeListEntry {
|
|
|
|
|
story_id: String,
|
|
|
|
|
path: String,
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-19 15:25:22 +00:00
|
|
|
pub struct AgentsApi {
|
|
|
|
|
pub ctx: Arc<AppContext>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[OpenApi(tag = "AgentsTags::Agents")]
|
|
|
|
|
impl AgentsApi {
|
2026-02-19 17:58:53 +00:00
|
|
|
/// Start an agent for a given story (creates worktree, runs setup, spawns agent).
|
Accept story 34: Per-Project Agent Configuration and Role Definitions
Replace single [agent] config with multi-agent [[agent]] roster system.
Each agent has name, role, model, allowed_tools, max_turns, max_budget_usd,
and system_prompt fields that map to Claude CLI flags at spawn time.
- AgentConfig expanded with structured fields, validated at startup (panics
on duplicate names, empty names, non-positive budgets/turns)
- Backwards-compatible: legacy [agent] format auto-wraps with deprecation warning
- AgentPool uses composite "story_id:agent_name" keys for concurrent agents
- agent_name added to AgentEvent variants, AgentInfo, start/stop/subscribe APIs
- GET /agents/config returns roster, POST /agents/config/reload hot-reloads
- POST /agents/start accepts optional agent_name, /agents/stop requires it
- SSE route updated to /agents/:story_id/:agent_name/stream
- Frontend: roster badges, agent selector dropdown, composite-key state
- Project root initialized to cwd at startup so config endpoints work immediately
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 18:46:14 +00:00
|
|
|
/// If agent_name is omitted, the first configured agent is used.
|
2026-02-19 17:58:53 +00:00
|
|
|
#[oai(path = "/agents/start", method = "post")]
|
|
|
|
|
async fn start_agent(
|
2026-02-19 15:25:22 +00:00
|
|
|
&self,
|
Accept story 34: Per-Project Agent Configuration and Role Definitions
Replace single [agent] config with multi-agent [[agent]] roster system.
Each agent has name, role, model, allowed_tools, max_turns, max_budget_usd,
and system_prompt fields that map to Claude CLI flags at spawn time.
- AgentConfig expanded with structured fields, validated at startup (panics
on duplicate names, empty names, non-positive budgets/turns)
- Backwards-compatible: legacy [agent] format auto-wraps with deprecation warning
- AgentPool uses composite "story_id:agent_name" keys for concurrent agents
- agent_name added to AgentEvent variants, AgentInfo, start/stop/subscribe APIs
- GET /agents/config returns roster, POST /agents/config/reload hot-reloads
- POST /agents/start accepts optional agent_name, /agents/stop requires it
- SSE route updated to /agents/:story_id/:agent_name/stream
- Frontend: roster badges, agent selector dropdown, composite-key state
- Project root initialized to cwd at startup so config endpoints work immediately
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 18:46:14 +00:00
|
|
|
payload: Json<StartAgentPayload>,
|
2026-02-19 15:25:22 +00:00
|
|
|
) -> OpenApiResult<Json<AgentInfoResponse>> {
|
2026-02-19 17:58:53 +00:00
|
|
|
let project_root = self
|
|
|
|
|
.ctx
|
|
|
|
|
.agents
|
|
|
|
|
.get_project_root(&self.ctx.state)
|
|
|
|
|
.map_err(bad_request)?;
|
2026-02-19 15:25:22 +00:00
|
|
|
|
2026-02-19 17:58:53 +00:00
|
|
|
let info = self
|
|
|
|
|
.ctx
|
|
|
|
|
.agents
|
Accept story 34: Per-Project Agent Configuration and Role Definitions
Replace single [agent] config with multi-agent [[agent]] roster system.
Each agent has name, role, model, allowed_tools, max_turns, max_budget_usd,
and system_prompt fields that map to Claude CLI flags at spawn time.
- AgentConfig expanded with structured fields, validated at startup (panics
on duplicate names, empty names, non-positive budgets/turns)
- Backwards-compatible: legacy [agent] format auto-wraps with deprecation warning
- AgentPool uses composite "story_id:agent_name" keys for concurrent agents
- agent_name added to AgentEvent variants, AgentInfo, start/stop/subscribe APIs
- GET /agents/config returns roster, POST /agents/config/reload hot-reloads
- POST /agents/start accepts optional agent_name, /agents/stop requires it
- SSE route updated to /agents/:story_id/:agent_name/stream
- Frontend: roster badges, agent selector dropdown, composite-key state
- Project root initialized to cwd at startup so config endpoints work immediately
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 18:46:14 +00:00
|
|
|
.start_agent(
|
|
|
|
|
&project_root,
|
|
|
|
|
&payload.0.story_id,
|
|
|
|
|
payload.0.agent_name.as_deref(),
|
|
|
|
|
)
|
2026-02-19 17:58:53 +00:00
|
|
|
.await
|
|
|
|
|
.map_err(bad_request)?;
|
2026-02-19 15:25:22 +00:00
|
|
|
|
|
|
|
|
Ok(Json(AgentInfoResponse {
|
2026-02-19 17:58:53 +00:00
|
|
|
story_id: info.story_id,
|
Accept story 34: Per-Project Agent Configuration and Role Definitions
Replace single [agent] config with multi-agent [[agent]] roster system.
Each agent has name, role, model, allowed_tools, max_turns, max_budget_usd,
and system_prompt fields that map to Claude CLI flags at spawn time.
- AgentConfig expanded with structured fields, validated at startup (panics
on duplicate names, empty names, non-positive budgets/turns)
- Backwards-compatible: legacy [agent] format auto-wraps with deprecation warning
- AgentPool uses composite "story_id:agent_name" keys for concurrent agents
- agent_name added to AgentEvent variants, AgentInfo, start/stop/subscribe APIs
- GET /agents/config returns roster, POST /agents/config/reload hot-reloads
- POST /agents/start accepts optional agent_name, /agents/stop requires it
- SSE route updated to /agents/:story_id/:agent_name/stream
- Frontend: roster badges, agent selector dropdown, composite-key state
- Project root initialized to cwd at startup so config endpoints work immediately
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 18:46:14 +00:00
|
|
|
agent_name: info.agent_name,
|
2026-02-19 17:58:53 +00:00
|
|
|
status: info.status.to_string(),
|
2026-02-19 15:25:22 +00:00
|
|
|
session_id: info.session_id,
|
2026-02-19 17:58:53 +00:00
|
|
|
worktree_path: info.worktree_path,
|
2026-02-19 15:25:22 +00:00
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-19 17:58:53 +00:00
|
|
|
/// Stop a running agent and clean up its worktree.
|
|
|
|
|
#[oai(path = "/agents/stop", method = "post")]
|
Accept story 34: Per-Project Agent Configuration and Role Definitions
Replace single [agent] config with multi-agent [[agent]] roster system.
Each agent has name, role, model, allowed_tools, max_turns, max_budget_usd,
and system_prompt fields that map to Claude CLI flags at spawn time.
- AgentConfig expanded with structured fields, validated at startup (panics
on duplicate names, empty names, non-positive budgets/turns)
- Backwards-compatible: legacy [agent] format auto-wraps with deprecation warning
- AgentPool uses composite "story_id:agent_name" keys for concurrent agents
- agent_name added to AgentEvent variants, AgentInfo, start/stop/subscribe APIs
- GET /agents/config returns roster, POST /agents/config/reload hot-reloads
- POST /agents/start accepts optional agent_name, /agents/stop requires it
- SSE route updated to /agents/:story_id/:agent_name/stream
- Frontend: roster badges, agent selector dropdown, composite-key state
- Project root initialized to cwd at startup so config endpoints work immediately
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 18:46:14 +00:00
|
|
|
async fn stop_agent(&self, payload: Json<StopAgentPayload>) -> OpenApiResult<Json<bool>> {
|
2026-02-19 17:58:53 +00:00
|
|
|
let project_root = self
|
|
|
|
|
.ctx
|
|
|
|
|
.agents
|
|
|
|
|
.get_project_root(&self.ctx.state)
|
|
|
|
|
.map_err(bad_request)?;
|
|
|
|
|
|
|
|
|
|
self.ctx
|
|
|
|
|
.agents
|
Accept story 34: Per-Project Agent Configuration and Role Definitions
Replace single [agent] config with multi-agent [[agent]] roster system.
Each agent has name, role, model, allowed_tools, max_turns, max_budget_usd,
and system_prompt fields that map to Claude CLI flags at spawn time.
- AgentConfig expanded with structured fields, validated at startup (panics
on duplicate names, empty names, non-positive budgets/turns)
- Backwards-compatible: legacy [agent] format auto-wraps with deprecation warning
- AgentPool uses composite "story_id:agent_name" keys for concurrent agents
- agent_name added to AgentEvent variants, AgentInfo, start/stop/subscribe APIs
- GET /agents/config returns roster, POST /agents/config/reload hot-reloads
- POST /agents/start accepts optional agent_name, /agents/stop requires it
- SSE route updated to /agents/:story_id/:agent_name/stream
- Frontend: roster badges, agent selector dropdown, composite-key state
- Project root initialized to cwd at startup so config endpoints work immediately
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 18:46:14 +00:00
|
|
|
.stop_agent(
|
|
|
|
|
&project_root,
|
|
|
|
|
&payload.0.story_id,
|
|
|
|
|
&payload.0.agent_name,
|
|
|
|
|
)
|
2026-02-19 17:58:53 +00:00
|
|
|
.await
|
|
|
|
|
.map_err(bad_request)?;
|
|
|
|
|
|
|
|
|
|
Ok(Json(true))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// List all agents with their status.
|
2026-02-19 15:25:22 +00:00
|
|
|
#[oai(path = "/agents", method = "get")]
|
|
|
|
|
async fn list_agents(&self) -> OpenApiResult<Json<Vec<AgentInfoResponse>>> {
|
|
|
|
|
let agents = self.ctx.agents.list_agents().map_err(bad_request)?;
|
|
|
|
|
|
|
|
|
|
Ok(Json(
|
|
|
|
|
agents
|
|
|
|
|
.into_iter()
|
|
|
|
|
.map(|info| AgentInfoResponse {
|
2026-02-19 17:58:53 +00:00
|
|
|
story_id: info.story_id,
|
Accept story 34: Per-Project Agent Configuration and Role Definitions
Replace single [agent] config with multi-agent [[agent]] roster system.
Each agent has name, role, model, allowed_tools, max_turns, max_budget_usd,
and system_prompt fields that map to Claude CLI flags at spawn time.
- AgentConfig expanded with structured fields, validated at startup (panics
on duplicate names, empty names, non-positive budgets/turns)
- Backwards-compatible: legacy [agent] format auto-wraps with deprecation warning
- AgentPool uses composite "story_id:agent_name" keys for concurrent agents
- agent_name added to AgentEvent variants, AgentInfo, start/stop/subscribe APIs
- GET /agents/config returns roster, POST /agents/config/reload hot-reloads
- POST /agents/start accepts optional agent_name, /agents/stop requires it
- SSE route updated to /agents/:story_id/:agent_name/stream
- Frontend: roster badges, agent selector dropdown, composite-key state
- Project root initialized to cwd at startup so config endpoints work immediately
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 18:46:14 +00:00
|
|
|
agent_name: info.agent_name,
|
2026-02-19 17:58:53 +00:00
|
|
|
status: info.status.to_string(),
|
2026-02-19 15:25:22 +00:00
|
|
|
session_id: info.session_id,
|
2026-02-19 17:58:53 +00:00
|
|
|
worktree_path: info.worktree_path,
|
2026-02-19 15:25:22 +00:00
|
|
|
})
|
|
|
|
|
.collect(),
|
|
|
|
|
))
|
|
|
|
|
}
|
Accept story 34: Per-Project Agent Configuration and Role Definitions
Replace single [agent] config with multi-agent [[agent]] roster system.
Each agent has name, role, model, allowed_tools, max_turns, max_budget_usd,
and system_prompt fields that map to Claude CLI flags at spawn time.
- AgentConfig expanded with structured fields, validated at startup (panics
on duplicate names, empty names, non-positive budgets/turns)
- Backwards-compatible: legacy [agent] format auto-wraps with deprecation warning
- AgentPool uses composite "story_id:agent_name" keys for concurrent agents
- agent_name added to AgentEvent variants, AgentInfo, start/stop/subscribe APIs
- GET /agents/config returns roster, POST /agents/config/reload hot-reloads
- POST /agents/start accepts optional agent_name, /agents/stop requires it
- SSE route updated to /agents/:story_id/:agent_name/stream
- Frontend: roster badges, agent selector dropdown, composite-key state
- Project root initialized to cwd at startup so config endpoints work immediately
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 18:46:14 +00:00
|
|
|
|
|
|
|
|
/// Get the configured agent roster from project.toml.
|
|
|
|
|
#[oai(path = "/agents/config", method = "get")]
|
|
|
|
|
async fn get_agent_config(
|
|
|
|
|
&self,
|
|
|
|
|
) -> OpenApiResult<Json<Vec<AgentConfigInfoResponse>>> {
|
|
|
|
|
let project_root = self
|
|
|
|
|
.ctx
|
|
|
|
|
.agents
|
|
|
|
|
.get_project_root(&self.ctx.state)
|
|
|
|
|
.map_err(bad_request)?;
|
|
|
|
|
|
|
|
|
|
let config = ProjectConfig::load(&project_root).map_err(bad_request)?;
|
|
|
|
|
|
|
|
|
|
Ok(Json(
|
|
|
|
|
config
|
|
|
|
|
.agent
|
|
|
|
|
.iter()
|
|
|
|
|
.map(|a| AgentConfigInfoResponse {
|
|
|
|
|
name: a.name.clone(),
|
|
|
|
|
role: a.role.clone(),
|
|
|
|
|
model: a.model.clone(),
|
|
|
|
|
allowed_tools: a.allowed_tools.clone(),
|
|
|
|
|
max_turns: a.max_turns,
|
|
|
|
|
max_budget_usd: a.max_budget_usd,
|
|
|
|
|
})
|
|
|
|
|
.collect(),
|
|
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Reload project config and return the updated agent roster.
|
|
|
|
|
#[oai(path = "/agents/config/reload", method = "post")]
|
|
|
|
|
async fn reload_config(
|
|
|
|
|
&self,
|
|
|
|
|
) -> OpenApiResult<Json<Vec<AgentConfigInfoResponse>>> {
|
|
|
|
|
let project_root = self
|
|
|
|
|
.ctx
|
|
|
|
|
.agents
|
|
|
|
|
.get_project_root(&self.ctx.state)
|
|
|
|
|
.map_err(bad_request)?;
|
|
|
|
|
|
|
|
|
|
let config = ProjectConfig::load(&project_root).map_err(bad_request)?;
|
|
|
|
|
|
|
|
|
|
Ok(Json(
|
|
|
|
|
config
|
|
|
|
|
.agent
|
|
|
|
|
.iter()
|
|
|
|
|
.map(|a| AgentConfigInfoResponse {
|
|
|
|
|
name: a.name.clone(),
|
|
|
|
|
role: a.role.clone(),
|
|
|
|
|
model: a.model.clone(),
|
|
|
|
|
allowed_tools: a.allowed_tools.clone(),
|
|
|
|
|
max_turns: a.max_turns,
|
|
|
|
|
max_budget_usd: a.max_budget_usd,
|
|
|
|
|
})
|
|
|
|
|
.collect(),
|
|
|
|
|
))
|
|
|
|
|
}
|
2026-02-20 14:09:52 +00:00
|
|
|
|
|
|
|
|
/// Create a git worktree for a story under .story_kit/worktrees/{story_id}.
|
|
|
|
|
#[oai(path = "/agents/worktrees", method = "post")]
|
|
|
|
|
async fn create_worktree(
|
|
|
|
|
&self,
|
|
|
|
|
payload: Json<CreateWorktreePayload>,
|
|
|
|
|
) -> OpenApiResult<Json<WorktreeInfoResponse>> {
|
|
|
|
|
let project_root = self
|
|
|
|
|
.ctx
|
|
|
|
|
.agents
|
|
|
|
|
.get_project_root(&self.ctx.state)
|
|
|
|
|
.map_err(bad_request)?;
|
|
|
|
|
|
|
|
|
|
let info = self
|
|
|
|
|
.ctx
|
|
|
|
|
.agents
|
|
|
|
|
.create_worktree(&project_root, &payload.0.story_id)
|
|
|
|
|
.await
|
|
|
|
|
.map_err(bad_request)?;
|
|
|
|
|
|
|
|
|
|
Ok(Json(WorktreeInfoResponse {
|
|
|
|
|
story_id: payload.0.story_id,
|
|
|
|
|
worktree_path: info.path.to_string_lossy().to_string(),
|
|
|
|
|
branch: info.branch,
|
|
|
|
|
base_branch: info.base_branch,
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// List all worktrees under .story_kit/worktrees/.
|
|
|
|
|
#[oai(path = "/agents/worktrees", method = "get")]
|
|
|
|
|
async fn list_worktrees(&self) -> OpenApiResult<Json<Vec<WorktreeListEntry>>> {
|
|
|
|
|
let project_root = self
|
|
|
|
|
.ctx
|
|
|
|
|
.agents
|
|
|
|
|
.get_project_root(&self.ctx.state)
|
|
|
|
|
.map_err(bad_request)?;
|
|
|
|
|
|
|
|
|
|
let entries = worktree::list_worktrees(&project_root).map_err(bad_request)?;
|
|
|
|
|
|
|
|
|
|
Ok(Json(
|
|
|
|
|
entries
|
|
|
|
|
.into_iter()
|
|
|
|
|
.map(|e| WorktreeListEntry {
|
|
|
|
|
story_id: e.story_id,
|
|
|
|
|
path: e.path.to_string_lossy().to_string(),
|
|
|
|
|
})
|
|
|
|
|
.collect(),
|
|
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Remove a git worktree and its feature branch for a story.
|
|
|
|
|
#[oai(path = "/agents/worktrees/:story_id", method = "delete")]
|
|
|
|
|
async fn remove_worktree(&self, story_id: Path<String>) -> OpenApiResult<Json<bool>> {
|
|
|
|
|
let project_root = self
|
|
|
|
|
.ctx
|
|
|
|
|
.agents
|
|
|
|
|
.get_project_root(&self.ctx.state)
|
|
|
|
|
.map_err(bad_request)?;
|
|
|
|
|
|
|
|
|
|
let config = ProjectConfig::load(&project_root).map_err(bad_request)?;
|
|
|
|
|
worktree::remove_worktree_by_story_id(&project_root, &story_id.0, &config)
|
|
|
|
|
.await
|
|
|
|
|
.map_err(bad_request)?;
|
|
|
|
|
|
|
|
|
|
Ok(Json(true))
|
|
|
|
|
}
|
2026-02-19 15:25:22 +00:00
|
|
|
}
|