Skip to content

Commit 2d15346

Browse files
authored
feat: enhance tools reset (#1102)
* feat: enhance tools reset * add logging when tool name not in hashmap
1 parent 51f8a2f commit 2d15346

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ pub enum ToolsSubcommand {
162162
Untrust { tool_name: String },
163163
TrustAll,
164164
Reset,
165+
ResetSingle { tool_name: String },
165166
Help,
166167
}
167168

@@ -171,7 +172,8 @@ impl ToolsSubcommand {
171172
<em>trust <<tool name>></em> <black!>Trust a specific tool for the session</black!>
172173
<em>untrust <<tool name>></em> <black!>Revert a tool to per-request confirmation</black!>
173174
<em>trustall</em> <black!>Trust all tools (equivalent to deprecated /acceptall)</black!>
174-
<em>reset</em> <black!>Reset all tools to default permission levels</black!>"};
175+
<em>reset</em> <black!>Reset all tools to default permission levels</black!>
176+
<em>reset <<tool name>></em> <black!>Reset a single tool to default permission level</black!>"};
175177
const BASE_COMMAND: &str = color_print::cstr! {"<cyan!>Usage: /tools [SUBCOMMAND]</cyan!>
176178
177179
<cyan!>Description</cyan!>
@@ -538,8 +540,18 @@ impl Command {
538540
"trustall" => Self::Tools {
539541
subcommand: Some(ToolsSubcommand::TrustAll),
540542
},
541-
"reset" => Self::Tools {
542-
subcommand: Some(ToolsSubcommand::Reset),
543+
"reset" => {
544+
let tool_name = parts.get(2);
545+
match tool_name {
546+
Some(tool_name) => Self::Tools {
547+
subcommand: Some(ToolsSubcommand::ResetSingle {
548+
tool_name: (*tool_name).to_string(),
549+
}),
550+
},
551+
None => Self::Tools {
552+
subcommand: Some(ToolsSubcommand::Reset),
553+
},
554+
}
543555
},
544556
"help" => Self::Tools {
545557
subcommand: Some(ToolsSubcommand::Help),

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,6 +1490,15 @@ where
14901490
style::SetForegroundColor(Color::Reset),
14911491
)?;
14921492
},
1493+
Some(ToolsSubcommand::ResetSingle { tool_name }) => {
1494+
self.tool_permissions.reset_tool(&tool_name);
1495+
queue!(
1496+
self.output,
1497+
style::SetForegroundColor(Color::Green),
1498+
style::Print(format!("\nReset tool '{}' to the default permission level.", tool_name)),
1499+
style::SetForegroundColor(Color::Reset),
1500+
)?;
1501+
},
14931502
Some(ToolsSubcommand::Help) => {
14941503
queue!(
14951504
self.output,

crates/q_cli/src/cli/chat/tools/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use fs_read::FsRead;
2727
use fs_write::FsWrite;
2828
use gh_issue::GhIssue;
2929
use serde::Deserialize;
30+
use tracing::warn;
3031
use use_aws::UseAws;
3132

3233
use super::parser::ToolUse;
@@ -194,6 +195,14 @@ impl ToolPermissions {
194195
self.permissions.clear();
195196
}
196197

198+
pub fn reset_tool(&mut self, tool_name: &str) {
199+
if !self.permissions.contains_key(tool_name) {
200+
warn!("No custom permissions set for tool '{tool_name}' to reset");
201+
return;
202+
}
203+
self.permissions.remove(tool_name);
204+
}
205+
197206
pub fn has(&self, tool_name: &str) -> bool {
198207
self.permissions.contains_key(tool_name)
199208
}

0 commit comments

Comments
 (0)