Skip to content

Commit 810a63a

Browse files
kzhou003jsamuel1
authored andcommitted
feat: enhance tools reset (#1102)
* feat: enhance tools reset * add logging when tool name not in hashmap
1 parent 57328b5 commit 810a63a

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
@@ -1427,6 +1427,15 @@ where
14271427
style::SetForegroundColor(Color::Reset),
14281428
)?;
14291429
},
1430+
Some(ToolsSubcommand::ResetSingle { tool_name }) => {
1431+
self.tool_permissions.reset_tool(&tool_name);
1432+
queue!(
1433+
self.output,
1434+
style::SetForegroundColor(Color::Green),
1435+
style::Print(format!("\nReset tool '{}' to the default permission level.", tool_name)),
1436+
style::SetForegroundColor(Color::Reset),
1437+
)?;
1438+
},
14301439
Some(ToolsSubcommand::Help) => {
14311440
queue!(
14321441
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
@@ -28,6 +28,7 @@ use fs_read::FsRead;
2828
use fs_write::FsWrite;
2929
use gh_issue::GhIssue;
3030
use serde::Deserialize;
31+
use tracing::warn;
3132
use use_aws::UseAws;
3233
use use_q_command::UseQCommand;
3334

@@ -206,6 +207,14 @@ impl ToolPermissions {
206207
self.permissions.clear();
207208
}
208209

210+
pub fn reset_tool(&mut self, tool_name: &str) {
211+
if !self.permissions.contains_key(tool_name) {
212+
warn!("No custom permissions set for tool '{tool_name}' to reset");
213+
return;
214+
}
215+
self.permissions.remove(tool_name);
216+
}
217+
209218
pub fn has(&self, tool_name: &str) -> bool {
210219
self.permissions.contains_key(tool_name)
211220
}

0 commit comments

Comments
 (0)