(dir: &Path, agents: &mut Vec<AgentDefinition>)
| 910 | } |
| 911 | |
| 912 | fn load_agents_from_dir_inner(dir: &Path, agents: &mut Vec<AgentDefinition>) { |
| 913 | let Ok(entries) = std::fs::read_dir(dir) else { |
| 914 | tracing::warn!("Failed to read agent directory: {}", dir.display()); |
| 915 | return; |
| 916 | }; |
| 917 | |
| 918 | for entry in entries.flatten() { |
| 919 | let path = entry.path(); |
| 920 | |
| 921 | if path.is_dir() { |
| 922 | load_agents_from_dir_inner(&path, agents); |
| 923 | continue; |
| 924 | } |
| 925 | if !path.is_file() { |
| 926 | continue; |
| 927 | } |
| 928 | |
| 929 | let Some(ext) = path.extension().and_then(|e| e.to_str()) else { |
| 930 | continue; |
| 931 | }; |
| 932 | |
| 933 | // Read file content |
| 934 | let Ok(content) = std::fs::read_to_string(&path) else { |
| 935 | tracing::warn!("Failed to read agent file: {}", path.display()); |
| 936 | continue; |
| 937 | }; |
| 938 | |
| 939 | // Parse based on extension |
| 940 | let result = match ext { |
| 941 | "yaml" | "yml" => parse_agent_yaml(&content), |
| 942 | "md" => parse_agent_md(&content), |
| 943 | _ => continue, |
| 944 | }; |
| 945 | |
| 946 | match result { |
| 947 | Ok(agent) => { |
| 948 | tracing::debug!("Loaded agent '{}' from {}", agent.name, path.display()); |
| 949 | agents.push(agent); |
| 950 | } |
| 951 | Err(e) => { |
| 952 | tracing::warn!("Failed to parse agent file {}: {}", path.display(), e); |
| 953 | } |
| 954 | } |
| 955 | } |
| 956 | } |
| 957 | |
| 958 | /// Create built-in agent definitions |
| 959 | pub fn builtin_agents() -> Vec<AgentDefinition> { |
no test coverage detected