diff --git a/src/terminal/composer.rs b/src/terminal/composer.rs index cdb08943..a87c0e73 100644 --- a/src/terminal/composer.rs +++ b/src/terminal/composer.rs @@ -581,15 +581,27 @@ pub(super) fn command_items(commands: &[(String, String)], query: &str) -> Vec, path: &str, shell: Option<&str>) -> String { - if agent != Some(CLIAgent::Gemini) { - return format!("@{path}"); + let spaced = path.chars().any(char::is_whitespace); + match agent { + Some(CLIAgent::Gemini) => {} + Some(CLIAgent::Claude) if spaced => return format!("@\"{path}\""), + Some(CLIAgent::Codex) if spaced && !path.contains('"') => return format!("\"{path}\""), + Some(CLIAgent::Codex) => return path.to_string(), + _ => return format!("@{path}"), } let spelled = match quoting_for(shell) { Quoting::Posix => { @@ -2297,10 +2309,29 @@ mod tests { mention(Some(CLIAgent::Gemini), r"C:\src\a.rs", Some("pwsh")), r"@C:\src\a.rs" ); + } + + #[test] + fn a_mention_with_a_space_is_spelled_the_way_each_agent_reads_it() { + let zsh = Some("zsh"); assert_eq!( - mention(Some(CLIAgent::Claude), "my notes.md", Some("zsh")), - "@my notes.md" + mention(Some(CLIAgent::Claude), "my notes.md", zsh), + r#"@"my notes.md""# ); + assert_eq!( + mention(Some(CLIAgent::Claude), "src/a.rs", zsh), + "@src/a.rs" + ); + assert_eq!( + mention(Some(CLIAgent::Codex), "my notes.md", zsh), + r#""my notes.md""# + ); + assert_eq!(mention(Some(CLIAgent::Codex), "src/a.rs", zsh), "src/a.rs"); + assert_eq!( + mention(Some(CLIAgent::Gemini), "my notes.md", zsh), + r"@my\ notes.md" + ); + assert_eq!(mention(None, "my notes.md", zsh), "@my notes.md"); } fn screen(lines: &[&str]) -> Vec {