Retrieves an agent by name. It does so via first seeking the given agent under local dir, and falling back to global dir if it does not exist in local.
(os: &Os, agent_name: &str)
| 340 | /// Retrieves an agent by name. It does so via first seeking the given agent under local dir, |
| 341 | /// and falling back to global dir if it does not exist in local. |
| 342 | pub async fn get_agent_by_name(os: &Os, agent_name: &str) -> eyre::Result<(Agent, PathBuf)> { |
| 343 | let resolver = PathResolver::new(os); |
| 344 | let config_path: Result<PathBuf, PathBuf> = 'config: { |
| 345 | // local first, and then fall back to looking at global |
| 346 | let local_config_dir = resolver.workspace().agents_dir()?.join(format!("{agent_name}.json")); |
| 347 | if os.fs.exists(&local_config_dir) { |
| 348 | break 'config Ok(local_config_dir); |
| 349 | } |
| 350 | |
| 351 | let global_config_dir = resolver.global().agents_dir()?.join(format!("{agent_name}.json")); |
| 352 | if os.fs.exists(&global_config_dir) { |
| 353 | break 'config Ok(global_config_dir); |
| 354 | } |
| 355 | |
| 356 | Err(global_config_dir) |
| 357 | }; |
| 358 | |
| 359 | match config_path { |
| 360 | Ok(config_path) => { |
| 361 | let content = os.fs.read(&config_path).await?; |
| 362 | let mut agent = serde_json::from_slice::<Agent>(&content)?; |
| 363 | let legacy_mcp_config = if agent.use_legacy_mcp_json { |
| 364 | load_legacy_mcp_config(os).await.unwrap_or(None) |
| 365 | } else { |
| 366 | None |
| 367 | }; |
| 368 | let mut stderr = std::io::stderr(); |
| 369 | agent.thaw(&config_path, legacy_mcp_config.as_ref(), &mut stderr)?; |
| 370 | Ok((agent, config_path)) |
| 371 | }, |
| 372 | _ => bail!("Agent {agent_name} does not exist"), |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | pub async fn load( |
| 377 | os: &Os, |
nothing calls this directly
no test coverage detected