Skip to content

Commit f6d9694

Browse files
authored
Fix: prompt denial reason upon tool use denial (#220)
1 parent ae15bf2 commit f6d9694

File tree

1 file changed

+20
-2
lines changed
  • crates/chat-cli/src/cli/chat

1 file changed

+20
-2
lines changed

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,9 +1564,9 @@ impl ChatContext {
15641564
Ok(match command {
15651565
Command::Ask { prompt } => {
15661566
// Check for a pending tool approval
1567+
let tool_denied_without_reason = ["n", "N"].contains(&prompt.as_str());
15671568
if let Some(index) = pending_tool_index {
15681569
let tool_use = &mut tool_uses[index];
1569-
15701570
let is_trust = ["t", "T"].contains(&prompt.as_str());
15711571
if ["y", "Y"].contains(&prompt.as_str()) || is_trust {
15721572
if is_trust {
@@ -1575,6 +1575,23 @@ impl ChatContext {
15751575
tool_use.accepted = true;
15761576

15771577
return Ok(ChatState::ExecuteTools(tool_uses));
1578+
// Prompt reason if no selected
1579+
} else if tool_denied_without_reason {
1580+
tool_use.accepted = false;
1581+
execute!(
1582+
self.output,
1583+
style::SetForegroundColor(Color::DarkGrey),
1584+
style::Print(
1585+
"\nPlease provide a reason for denying this tool use, or otherwise continue your conversation:\n\n"
1586+
),
1587+
style::SetForegroundColor(Color::Reset),
1588+
)?;
1589+
1590+
return Ok(ChatState::PromptUser {
1591+
tool_uses: Some(tool_uses),
1592+
pending_tool_index,
1593+
skip_printing_tools: true,
1594+
});
15781595
}
15791596
} else if !self.pending_prompts.is_empty() {
15801597
let prompts = self.pending_prompts.drain(0..).collect();
@@ -1586,7 +1603,6 @@ impl ChatContext {
15861603

15871604
// Otherwise continue with normal chat on 'n' or other responses
15881605
self.tool_use_status = ToolUseStatus::Idle;
1589-
15901606
if pending_tool_index.is_some() {
15911607
self.conversation_state.abandon_tool_use(tool_uses, user_input);
15921608
} else {
@@ -4602,11 +4618,13 @@ mod tests {
46024618
"/tools untrust fs_write".to_string(),
46034619
"create a file".to_string(), // prompt again due to untrust
46044620
"n".to_string(), // cancel
4621+
"no reason".to_string(), // dummy reason
46054622
"/tools trust fs_write".to_string(),
46064623
"create a file".to_string(), // again without prompting due to '/tools trust'
46074624
"/tools reset".to_string(),
46084625
"create a file".to_string(), // prompt again due to reset
46094626
"n".to_string(), // cancel
4627+
"no reason".to_string(), // dummy reason
46104628
"exit".to_string(),
46114629
]),
46124630
true,

0 commit comments

Comments
 (0)