MCPcopy Index your code
hub / github.com/ChrisFeldmeier/OpenCodeRust / handle_agent_command

Function handle_agent_command

crates/opencode-cli/src/main.rs:3232–3303  ·  view source on GitHub ↗
(action: AgentCommands)

Source from the content-addressed store, hash-verified

3230}
3231
3232async fn handle_agent_command(action: AgentCommands) -> anyhow::Result<()> {
3233 match action {
3234 AgentCommands::List => {
3235 let cwd = std::env::current_dir()?;
3236 let config = load_config(&cwd)?;
3237 let registry = AgentRegistry::from_config(&config);
3238 println!("\nAvailable agents:\n");
3239 for agent in registry.list() {
3240 let description = agent.description.as_deref().unwrap_or("no description");
3241 println!(" {:<12} {}", agent.name, description);
3242 }
3243 println!();
3244 }
3245 AgentCommands::Create {
3246 name,
3247 description,
3248 mode,
3249 path,
3250 tools,
3251 model,
3252 } => {
3253 let sanitized: String = name
3254 .chars()
3255 .map(|c| {
3256 if c.is_ascii_alphanumeric() || c == '_' || c == '-' {
3257 c.to_ascii_lowercase()
3258 } else {
3259 '_'
3260 }
3261 })
3262 .collect();
3263
3264 if sanitized.is_empty() {
3265 anyhow::bail!("Agent name is empty after sanitization");
3266 }
3267
3268 let base = match path {
3269 Some(path) => path,
3270 None => std::env::current_dir()?.join(".opencode/agent"),
3271 };
3272 fs::create_dir_all(&base)?;
3273
3274 let file_path = base.join(format!("{}.md", sanitized));
3275 if file_path.exists() {
3276 anyhow::bail!("Agent file already exists: {}", file_path.display());
3277 }
3278
3279 let yaml_description = description.replace('\n', " ").replace('"', "\\\"");
3280 let mut frontmatter = format!(
3281 "---\ndescription: \"{}\"\nmode: {}\n",
3282 yaml_description,
3283 mode.as_str(),
3284 );
3285 if let Some(model) = model {
3286 frontmatter.push_str(&format!("model: \"{}\"\n", model));
3287 }
3288 if let Some(tools) = tools {
3289 frontmatter.push_str(&format!("tools: \"{}\"\n", tools));

Callers 1

mainFunction · 0.85

Calls 6

load_configFunction · 0.85
from_configFunction · 0.85
is_emptyMethod · 0.80
existsMethod · 0.80
replaceMethod · 0.80
listMethod · 0.45

Tested by

no test coverage detected