Skip to content

Commit 6e01028

Browse files
hayemaxiKonippi
authored andcommitted
feat(chat): all-tools-trusted indicator
Ref: aws#1042 Attaches a red ! to ">" prompt indicator if **all** available tools are trusted.
1 parent 2222626 commit 6e01028

File tree

2 files changed

+27
-32
lines changed

2 files changed

+27
-32
lines changed

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -680,8 +680,12 @@ where
680680
// Require two consecutive sigint's to exit.
681681
let mut ctrl_c = false;
682682
let user_input = loop {
683-
// Generate prompt based on active context profile
684-
let prompt = prompt::generate_prompt(self.conversation_state.current_profile());
683+
let all_tools_trusted = self.conversation_state.tools.iter().all(|t| match t {
684+
FigTool::ToolSpecification(t) => self.tool_permissions.is_trusted(&t.name),
685+
});
686+
687+
// Generate prompt based on active context profile and trusted tools
688+
let prompt = prompt::generate_prompt(self.conversation_state.current_profile(), all_tools_trusted);
685689

686690
match (self.input_source.read_line(Some(&prompt))?, ctrl_c) {
687691
(Some(line), _) => {

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

+21-30
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,14 @@ const COMMANDS: &[&str] = &[
6666
"/context clear --global",
6767
];
6868

69-
pub fn generate_prompt(current_profile: Option<&str>) -> String {
70-
if let Some(profile_name) = &current_profile {
71-
if *profile_name != "default" {
72-
// Format with profile name for non-default profiles
73-
return format!("[{}] > ", profile_name);
74-
}
75-
}
76-
77-
// Default prompt
78-
"> ".to_string()
69+
pub fn generate_prompt(current_profile: Option<&str>, warning: bool) -> String {
70+
let warning_symbol = if warning { "!".red().to_string() } else { "".to_string() };
71+
let profile_part = current_profile
72+
.filter(|&p| p != "default")
73+
.map(|p| format!("[{p}] ").cyan().to_string())
74+
.unwrap_or_default();
75+
76+
format!("{profile_part}{warning_symbol}{}", "> ".magenta())
7977
}
8078

8179
/// Complete commands that start with a slash
@@ -200,21 +198,6 @@ impl Validator for ChatHelper {
200198
}
201199

202200
impl Highlighter for ChatHelper {
203-
fn highlight_prompt<'b, 's: 'b, 'p: 'b>(&'s self, prompt: &'p str, _default: bool) -> Cow<'b, str> {
204-
// Check if the prompt contains a context profile indicator
205-
if let Some(profile_end) = prompt.find("] ") {
206-
// Split the prompt into context part and the rest
207-
let context_part = &prompt[..=profile_end];
208-
let rest = &prompt[(profile_end + 1)..];
209-
210-
// Color the context part cyan and the rest magenta
211-
Cow::Owned(format!("{}{}", context_part.cyan(), rest.magenta()))
212-
} else {
213-
// Default prompt with magenta color
214-
Cow::Owned(prompt.magenta().to_string())
215-
}
216-
}
217-
218201
fn highlight_hint<'h>(&self, hint: &'h str) -> Cow<'h, str> {
219202
Cow::Owned(format!("\x1b[1m{hint}\x1b[m"))
220203
}
@@ -268,13 +251,21 @@ mod tests {
268251
#[test]
269252
fn test_generate_prompt() {
270253
// Test default prompt (no profile)
271-
assert_eq!(generate_prompt(None), "> ");
254+
assert_eq!(generate_prompt(None, false), "> ".magenta().to_string());
255+
// Test default prompt with warning
256+
assert_eq!(generate_prompt(None, true), format!("{}{}", "!".red(), "> ".magenta()));
272257
// Test default profile (should be same as no profile)
273-
assert_eq!(generate_prompt(Some("default")), "> ");
258+
assert_eq!(generate_prompt(Some("default"), false), "> ".magenta().to_string());
274259
// Test custom profile
275-
assert_eq!(generate_prompt(Some("test-profile")), "[test-profile] > ");
276-
// Test another custom profile
277-
assert_eq!(generate_prompt(Some("dev")), "[dev] > ");
260+
assert_eq!(
261+
generate_prompt(Some("test-profile"), false),
262+
format!("{}{}", "[test-profile] ".cyan(), "> ".magenta())
263+
);
264+
// Test another custom profile with warning
265+
assert_eq!(
266+
generate_prompt(Some("dev"), true),
267+
format!("{}{}{}", "[dev] ".cyan(), "!".red(), "> ".magenta())
268+
);
278269
}
279270

280271
#[test]

0 commit comments

Comments
 (0)