story-kit: merge 176_bug_stories_moved_to_current_get_supervisor_instead_of_coder

This commit is contained in:
Dave
2026-02-25 09:30:15 +00:00
parent 553b21f7b5
commit d70285adda
3 changed files with 176 additions and 3 deletions

View File

@@ -57,6 +57,20 @@ pub struct AgentConfig {
pub inactivity_timeout_secs: u64,
}
impl AgentConfig {
/// Returns true if this agent is a coder.
///
/// Prefers the explicit `stage` field; falls back to checking whether the
/// agent name starts with `"coder"` for backwards compatibility.
pub fn is_coder(&self) -> bool {
match self.stage.as_deref() {
Some("coder") => true,
Some(_) => false,
None => self.name.starts_with("coder"),
}
}
}
fn default_path() -> String {
".".to_string()
}
@@ -189,6 +203,15 @@ impl ProjectConfig {
self.agent.first()
}
/// Get the first coder agent config.
///
/// Prefers the explicit `stage = "coder"` field over the legacy name-based
/// heuristic (names starting with "coder"). Returns `None` if no coder
/// agent is configured.
pub fn default_coder_agent(&self) -> Option<&AgentConfig> {
self.agent.iter().find(|a| a.is_coder())
}
/// Render template variables in agent args and prompt for the given agent.
/// If `agent_name` is None, uses the first (default) agent.
pub fn render_agent_args(
@@ -480,6 +503,89 @@ name = "second"
assert!(config.find_agent("missing").is_none());
}
#[test]
fn default_coder_agent_skips_supervisor() {
let toml_str = r#"
[[agent]]
name = "supervisor"
stage = "other"
[[agent]]
name = "coder-1"
stage = "coder"
"#;
let config = ProjectConfig::parse(toml_str).unwrap();
assert_eq!(config.default_coder_agent().unwrap().name, "coder-1");
}
#[test]
fn default_coder_agent_uses_name_heuristic_when_no_stage() {
let toml_str = r#"
[[agent]]
name = "supervisor"
[[agent]]
name = "coder-1"
"#;
let config = ProjectConfig::parse(toml_str).unwrap();
assert_eq!(config.default_coder_agent().unwrap().name, "coder-1");
}
#[test]
fn default_coder_agent_returns_none_when_no_coders() {
let toml_str = r#"
[[agent]]
name = "supervisor"
stage = "other"
"#;
let config = ProjectConfig::parse(toml_str).unwrap();
assert!(config.default_coder_agent().is_none());
}
#[test]
fn is_coder_explicit_stage() {
let mut agent = AgentConfig {
name: "my-agent".to_string(),
role: String::new(),
command: "claude".to_string(),
args: vec![],
prompt: String::new(),
model: None,
allowed_tools: None,
max_turns: None,
max_budget_usd: None,
system_prompt: None,
stage: Some("coder".to_string()),
inactivity_timeout_secs: 300,
};
assert!(agent.is_coder());
agent.stage = Some("other".to_string());
assert!(!agent.is_coder());
}
#[test]
fn is_coder_name_heuristic() {
let make = |name: &str| AgentConfig {
name: name.to_string(),
role: String::new(),
command: "claude".to_string(),
args: vec![],
prompt: String::new(),
model: None,
allowed_tools: None,
max_turns: None,
max_budget_usd: None,
system_prompt: None,
stage: None,
inactivity_timeout_secs: 300,
};
assert!(make("coder-1").is_coder());
assert!(make("coder-opus").is_coder());
assert!(!make("supervisor").is_coder());
assert!(!make("qa").is_coder());
assert!(!make("mergemaster").is_coder());
}
#[test]
fn parse_project_toml_from_file() {
let tmp = tempfile::tempdir().unwrap();