2026-07-12 11:28:39 +07:00
|
|
|
//! Construction of a `SubagentContext` from an `AgentDefinition`,
|
|
|
|
|
//! including the default read-only tool set for reviewer agents.
|
|
|
|
|
|
2026-07-11 13:16:10 +07:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
use super::spawn::AgentDefinition;
|
|
|
|
|
|
2026-07-12 11:28:39 +07:00
|
|
|
/// Default read-only tool names granted to `role == "reviewer"` agents.
|
2026-07-11 13:16:10 +07:00
|
|
|
pub const REVIEWER_ALLOWED: &[&str] = &["read", "grep", "glob", "recall", "remember"];
|
|
|
|
|
|
2026-07-12 11:28:39 +07:00
|
|
|
/// Per-invocation configuration for a subagent: prompt, allowed tools,
|
|
|
|
|
/// step budget, and the session directory it should operate against.
|
2026-07-11 13:16:10 +07:00
|
|
|
pub struct SubagentContext {
|
|
|
|
|
pub system_prompt: String,
|
|
|
|
|
pub allowed_tools: Vec<String>,
|
|
|
|
|
pub max_steps: usize,
|
|
|
|
|
pub session_dir: PathBuf,
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-12 11:28:39 +07:00
|
|
|
/// Build a `SubagentContext` from an `AgentDefinition`.
|
|
|
|
|
///
|
2026-07-12 17:49:34 +07:00
|
|
|
/// Flow: copy optional `allowed_tools` from the def → fall back to the
|
|
|
|
|
/// reviewer-allowlist when the def has none and the role is "reviewer" →
|
2026-07-12 11:28:39 +07:00
|
|
|
/// fall back to an empty list (i.e. "all tools allowed") for other roles.
|
2026-07-12 17:49:34 +07:00
|
|
|
/// `max_steps` is read from the definition, defaulting to 25 if absent.
|
2026-07-12 11:28:39 +07:00
|
|
|
///
|
|
|
|
|
/// Return: a context with empty `system_prompt` and `session_dir`,
|
2026-07-12 17:49:34 +07:00
|
|
|
/// resolved `max_steps`, and the resolved allowed-tool list.
|
2026-07-11 13:16:10 +07:00
|
|
|
pub fn build_subagent_context(def: AgentDefinition) -> SubagentContext {
|
|
|
|
|
let allowed_tools = def.allowed_tools.clone().unwrap_or_else(|| {
|
|
|
|
|
if def.role == "reviewer" {
|
|
|
|
|
REVIEWER_ALLOWED.iter().map(|s| s.to_string()).collect()
|
|
|
|
|
} else {
|
|
|
|
|
Vec::new()
|
|
|
|
|
}
|
|
|
|
|
});
|
2026-07-12 17:49:34 +07:00
|
|
|
let max_steps = def.max_steps.unwrap_or(25);
|
2026-07-11 13:16:10 +07:00
|
|
|
SubagentContext {
|
|
|
|
|
system_prompt: String::new(),
|
|
|
|
|
allowed_tools,
|
2026-07-12 17:49:34 +07:00
|
|
|
max_steps,
|
2026-07-11 13:16:10 +07:00
|
|
|
session_dir: PathBuf::new(),
|
|
|
|
|
}
|
|
|
|
|
}
|