| 882 | } |
| 883 | |
| 884 | async fn load_agents_from_entries( |
| 885 | mut files: ReadDir, |
| 886 | os: &Os, |
| 887 | global_mcp_config: &mut Option<McpServerConfig>, |
| 888 | mcp_enabled: bool, |
| 889 | is_from_global_dir: bool, |
| 890 | output: &mut impl Write, |
| 891 | ) -> Vec<Result<Agent, AgentConfigError>> { |
| 892 | let mut res = Vec::<Result<Agent, AgentConfigError>>::new(); |
| 893 | |
| 894 | while let Ok(Some(file)) = files.next_entry().await { |
| 895 | let file_path = &file.path(); |
| 896 | if file_path |
| 897 | .extension() |
| 898 | .and_then(OsStr::to_str) |
| 899 | .is_some_and(|s| s == "json") |
| 900 | { |
| 901 | let agent_res = Agent::load(os, file_path, global_mcp_config, mcp_enabled, output).await; |
| 902 | if let Ok(agent) = &agent_res { |
| 903 | if res.iter().any(|res| match res { |
| 904 | Ok(a) => a.name == agent.name, |
| 905 | Err(_) => false, |
| 906 | }) { |
| 907 | let _ = queue!( |
| 908 | output, |
| 909 | StyledText::warning_fg(), |
| 910 | style::Print("WARNING: "), |
| 911 | StyledText::reset(), |
| 912 | style::Print("Duplicate agent with name "), |
| 913 | StyledText::success_fg(), |
| 914 | style::Print(&agent.name), |
| 915 | StyledText::reset(), |
| 916 | style::Print(" was found in the "), |
| 917 | style::Print(if is_from_global_dir { "global" } else { "workspace" }), |
| 918 | style::Print(" directory.\n"), |
| 919 | StyledText::reset(), |
| 920 | ); |
| 921 | continue; |
| 922 | } |
| 923 | } |
| 924 | res.push(agent_res); |
| 925 | } |
| 926 | } |
| 927 | |
| 928 | res |
| 929 | } |
| 930 | |
| 931 | /// Loads legacy mcp config by combining workspace and global config. |
| 932 | /// In case of a server naming conflict, the workspace config is prioritized. |