-
Notifications
You must be signed in to change notification settings - Fork 10
fix: prompt user explicitly for reason upon denying tool request #145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1336,6 +1336,7 @@ impl ChatContext { | |
Ok(match command { | ||
Command::Ask { prompt } => { | ||
// Check for a pending tool approval | ||
let mut reason_prompt = String::from("Tool denied: "); | ||
if let Some(index) = pending_tool_index { | ||
let tool_use = &mut tool_uses[index]; | ||
|
||
|
@@ -1347,6 +1348,23 @@ impl ChatContext { | |
tool_use.accepted = true; | ||
|
||
return Ok(ChatState::ExecuteTools(tool_uses)); | ||
// Prompt reason if no selected | ||
} else if ["n", "N"].contains(&prompt.as_str()) { | ||
tool_use.accepted = false; | ||
execute!( | ||
self.output, | ||
style::SetForegroundColor(Color::DarkGrey), | ||
style::Print("\nPlease provide a reason for denying this tool use:\n\n"), | ||
style::SetForegroundColor(Color::Reset), | ||
)?; | ||
let reason: String = match self.read_user_input("> ".yellow().to_string().as_str(), true) { | ||
Some(input) if !input.trim().is_empty() => input, | ||
_ => "No reason provided".to_string(), | ||
}; | ||
reason_prompt.push_str(&reason); | ||
reason_prompt.push_str( | ||
". Take user feedback and try again if reason provided, else continue conversation.", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only way to provide no reason seems to be Instead, I think the flow should be:
|
||
); | ||
} | ||
} else if !self.pending_prompts.is_empty() { | ||
let prompts = self.pending_prompts.drain(0..).collect(); | ||
|
@@ -1358,9 +1376,12 @@ impl ChatContext { | |
|
||
// Otherwise continue with normal chat on 'n' or other responses | ||
self.tool_use_status = ToolUseStatus::Idle; | ||
|
||
if pending_tool_index.is_some() { | ||
self.conversation_state.abandon_tool_use(tool_uses, user_input); | ||
if ["n", "N"].contains(&prompt.as_str()) { | ||
self.conversation_state.abandon_tool_use(tool_uses, reason_prompt); | ||
} else { | ||
self.conversation_state.abandon_tool_use(tool_uses, user_input); | ||
} | ||
} else { | ||
self.conversation_state.set_next_user_message(user_input).await; | ||
} | ||
|
@@ -3973,11 +3994,13 @@ mod tests { | |
"/tools untrust fs_write".to_string(), | ||
"create a file".to_string(), // prompt again due to untrust | ||
"n".to_string(), // cancel | ||
"No reason".to_string(), // provide reason for cancel | ||
"/tools trust fs_write".to_string(), | ||
"create a file".to_string(), // again without prompting due to '/tools trust' | ||
"/tools reset".to_string(), | ||
"create a file".to_string(), // prompt again due to reset | ||
"n".to_string(), // cancel | ||
"No reason".to_string(), // provide reason for cancel | ||
"exit".to_string(), | ||
]), | ||
true, | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you instead just define a variable like
tool_use_denied_without_reason
or something for the["n", "N"].contains(&prompt.as_str())
check? In case we also add other cases like "no" etc.