Skip to content

Commit 6e17850

Browse files
author
Olivier Mansour
committed
fix: adapt interactive allowed commands to use regex patterns
- Update interactive 'a' option to generate regex patterns instead of glob patterns - Fix pattern generation for option 1: use regex::escape() for exact commands - Fix pattern generation for option 2: use 'command\s.*' to match 'command ' + anything (but not command alone) - Remove glob-based pattern matching code that conflicted with main branch's regex approach - Update unit tests to reflect regex pattern behavior - Fix bug where commands like 'git log -1' weren't matching the allowed pattern Key changes: - Option 1 now generates: 'touch\ test\.txt' (escaped exact match) - Option 2 now generates: 'git\s.*' (matches 'git ' + anything, not 'git' alone) - Maintains compatibility with main branch's regex-based allowedCommands system - All tests passing with proper regex pattern validation Fixes issue where interactive menu generated incompatible glob patterns instead of the expected regex patterns used by the main branch.
1 parent 826db79 commit 6e17850

File tree

2 files changed

+54
-308
lines changed

2 files changed

+54
-308
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,7 +1544,7 @@ impl ChatSession {
15441544
};
15451545

15461546
let (option_key, option_description) = if is_execute_tool {
1547-
("a", "' to allow similar commands. [")
1547+
("a", "' to allow similar or exact commands in the futur. [")
15481548
} else {
15491549
("t", "' to trust (always allow) this tool for the session. [")
15501550
};
@@ -2843,8 +2843,9 @@ impl ChatSession {
28432843

28442844
match choice {
28452845
"1" => {
2846-
// Allow this exact command only
2847-
self.add_allowed_command_pattern(&command, os).await?;
2846+
// Allow this exact command only - escape regex special characters
2847+
let escaped_command = regex::escape(&command);
2848+
self.add_allowed_command_pattern(&escaped_command, os).await?;
28482849
queue!(
28492850
self.stderr,
28502851
style::SetForegroundColor(Color::Green),
@@ -2854,13 +2855,14 @@ impl ChatSession {
28542855
return Ok(AllowCommandResult::AddedRule);
28552856
},
28562857
"2" => {
2857-
// Allow all commands with first word (e.g., "touch *")
2858-
let pattern = format!("{} *", first_word);
2858+
// Allow all commands with first word - create regex pattern
2859+
let escaped_first_word = regex::escape(&first_word);
2860+
let pattern = format!("{}\\s.*", escaped_first_word);
28592861
self.add_allowed_command_pattern(&pattern, os).await?;
28602862
queue!(
28612863
self.stderr,
28622864
style::SetForegroundColor(Color::Green),
2863-
style::Print(format!("\nAllowed command rule added: '{}'\n\n", pattern)),
2865+
style::Print(format!("\nAllowed command rule added for all '{}' commands\n\n", first_word)),
28642866
style::SetForegroundColor(Color::Reset)
28652867
)?;
28662868
return Ok(AllowCommandResult::AddedRule);

0 commit comments

Comments
 (0)