Skip to content

Commit 4e6083a

Browse files
authored
fix: gracefully handle file paths in user input (#1761)
1 parent 522bbb7 commit 4e6083a

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

crates/chat-cli/src/cli/chat/command.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -810,8 +810,26 @@ impl Command {
810810
}
811811
},
812812
"usage" => Self::Usage,
813-
_unknown_command => Self::Ask {
814-
prompt: input.to_string(),
813+
unknown_command => {
814+
let looks_like_path = {
815+
let after_slash_command_str = parts[1..].join(" ");
816+
unknown_command.contains('/')
817+
|| unknown_command.contains('.')
818+
|| unknown_command.contains('\\')
819+
|| after_slash_command_str.contains('/')
820+
|| after_slash_command_str.contains('.')
821+
|| after_slash_command_str.contains('\\')
822+
};
823+
if looks_like_path {
824+
return Ok(Self::Ask {
825+
prompt: command.to_string(),
826+
});
827+
}
828+
829+
return Err(format!(
830+
"Unknown command: '/{}'. Type '/help' to see available commands.\nTo use a literal slash at the beginning of your message, escape it with a backslash (e.g., '\\//hey' for '/hey').",
831+
unknown_command
832+
));
815833
},
816834
});
817835
}

0 commit comments

Comments
 (0)