diff --git a/crates/project/src/agent_server_store.rs b/crates/project/src/agent_server_store.rs index a1897a89d1f0fe52fedf8902e8c631a367627b20..a6efa1ef75786d3f0dc77ed2e57ec0edec42fc8c 100644 --- a/crates/project/src/agent_server_store.rs +++ b/crates/project/src/agent_server_store.rs @@ -1638,7 +1638,9 @@ impl BuiltinAgentServerSettings { impl From for BuiltinAgentServerSettings { fn from(value: settings::BuiltinAgentServerSettings) -> Self { BuiltinAgentServerSettings { - path: value.path, + path: value + .path + .map(|p| PathBuf::from(shellexpand::tilde(&p.to_string_lossy()).as_ref())), args: value.args, env: value.env, ignore_system_version: value.ignore_system_version, @@ -1673,7 +1675,7 @@ impl From for CustomAgentServerSettings { fn from(value: settings::CustomAgentServerSettings) -> Self { CustomAgentServerSettings { command: AgentServerCommand { - path: value.path, + path: PathBuf::from(shellexpand::tilde(&value.path.to_string_lossy()).as_ref()), args: value.args, env: value.env, }, @@ -1893,4 +1895,40 @@ mod extension_agent_tests { let target = manifest_entry.targets.get("linux-x86_64").unwrap(); assert_eq!(target.cmd, "./release-agent"); } + + #[test] + fn test_tilde_expansion_in_settings() { + let settings = settings::BuiltinAgentServerSettings { + path: Some(PathBuf::from("~/bin/agent")), + args: Some(vec!["--flag".into()]), + env: None, + ignore_system_version: None, + default_mode: None, + }; + + let BuiltinAgentServerSettings { path, .. } = settings.into(); + + let path = path.unwrap(); + assert!( + !path.to_string_lossy().starts_with("~"), + "Tilde should be expanded for builtin agent path" + ); + + let settings = settings::CustomAgentServerSettings { + path: PathBuf::from("~/custom/agent"), + args: vec!["serve".into()], + env: None, + default_mode: None, + }; + + let CustomAgentServerSettings { + command: AgentServerCommand { path, .. }, + .. + } = settings.into(); + + assert!( + !path.to_string_lossy().starts_with("~"), + "Tilde should be expanded for custom agent path" + ); + } }