Skip to content

Commit c9b942f

Browse files
author
Olivier Mansour
committed
fix: comprehensive --quiet mode cleanup for scripting
- Suppress spinner cleanup operations in quiet mode - Suppress cursor operations and terminal clearing - Suppress notification bells and color resets to stderr - Suppress tool execution UI elements (tool messages, continuation lines) - Suppress startup warnings (profile deprecation, MCP safety, trust-tools) - Suppress input handling newline in quiet mode - Force disable markdown rendering to eliminate ANSI codes - Maintain complete response output and proper termination Result: Clean, minimal output for scripting and automation - Regular chat: No blank lines - Tool execution: Reduced from 4+ blank lines to 1 blank line
1 parent e3e88af commit c9b942f

File tree

1 file changed

+38
-27
lines changed
  • crates/chat-cli/src/cli/chat

1 file changed

+38
-27
lines changed

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

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ impl ChatArgs {
237237
let mut stderr = std::io::stderr();
238238

239239
let args: Vec<String> = std::env::args().collect();
240-
if args
240+
if !self.quiet && args
241241
.iter()
242242
.any(|arg| arg == "--profile" || arg.starts_with("--profile="))
243243
{
@@ -287,7 +287,7 @@ impl ChatArgs {
287287
.get_active()
288288
.is_some_and(|a| !a.mcp_servers.mcp_servers.is_empty())
289289
{
290-
if !self.no_interactive && !os.database.settings.get_bool(Setting::McpLoadedBefore).unwrap_or(false) {
290+
if !self.no_interactive && !self.quiet && !os.database.settings.get_bool(Setting::McpLoadedBefore).unwrap_or(false) {
291291
execute!(
292292
stderr,
293293
style::Print(
@@ -300,7 +300,7 @@ impl ChatArgs {
300300

301301
if let Some(trust_tools) = self.trust_tools.take() {
302302
for tool in &trust_tools {
303-
if !tool.starts_with("@") && !NATIVE_TOOLS.contains(&tool.as_str()) {
303+
if !self.quiet && !tool.starts_with("@") && !NATIVE_TOOLS.contains(&tool.as_str()) {
304304
let _ = queue!(
305305
stderr,
306306
style::SetForegroundColor(Color::Yellow),
@@ -1661,7 +1661,9 @@ impl ChatSession {
16611661
}
16621662

16631663
async fn handle_input(&mut self, os: &mut Os, mut user_input: String) -> Result<ChatState, ChatError> {
1664-
queue!(self.stderr, style::Print('\n'))?;
1664+
if !self.quiet {
1665+
queue!(self.stderr, style::Print('\n'))?;
1666+
}
16651667
user_input = sanitize_unicode_tags(&user_input);
16661668
let input = user_input.trim();
16671669

@@ -2190,7 +2192,12 @@ impl ChatSession {
21902192
)?;
21912193
response_prefix_printed = true;
21922194
}
2193-
buf.push_str(&text);
2195+
if self.quiet && buf.is_empty() {
2196+
// In quiet mode, trim leading whitespace from the first text
2197+
buf.push_str(text.trim_start());
2198+
} else {
2199+
buf.push_str(&text);
2200+
}
21942201
},
21952202
parser::ResponseEvent::ToolUse(tool_use) => {
21962203
if self.spinner.is_some() {
@@ -2593,34 +2600,38 @@ impl ChatSession {
25932600

25942601
let tool_use = &self.tool_uses[tool_index];
25952602

2596-
queue!(
2597-
self.stdout,
2598-
style::SetForegroundColor(Color::Magenta),
2599-
style::Print(format!(
2600-
"🛠️ Using tool: {}{}",
2601-
tool_use.tool.display_name(),
2602-
if trusted { " (trusted)".dark_green() } else { "".reset() }
2603-
)),
2604-
style::SetForegroundColor(Color::Reset)
2605-
)?;
2606-
if let Tool::Custom(ref tool) = tool_use.tool {
2603+
if !self.quiet {
26072604
queue!(
26082605
self.stdout,
2609-
style::SetForegroundColor(Color::Reset),
2610-
style::Print(" from mcp server "),
26112606
style::SetForegroundColor(Color::Magenta),
2612-
style::Print(tool.client.get_server_name()),
2613-
style::SetForegroundColor(Color::Reset),
2607+
style::Print(format!(
2608+
"🛠️ Using tool: {}{}",
2609+
tool_use.tool.display_name(),
2610+
if trusted { " (trusted)".dark_green() } else { "".reset() }
2611+
)),
2612+
style::SetForegroundColor(Color::Reset)
26142613
)?;
2614+
if let Tool::Custom(ref tool) = tool_use.tool {
2615+
queue!(
2616+
self.stdout,
2617+
style::SetForegroundColor(Color::Reset),
2618+
style::Print(" from mcp server "),
2619+
style::SetForegroundColor(Color::Magenta),
2620+
style::Print(tool.client.get_server_name()),
2621+
style::SetForegroundColor(Color::Reset),
2622+
)?;
2623+
}
26152624
}
26162625

2617-
execute!(
2618-
self.stdout,
2619-
style::Print("\n"),
2620-
style::Print(CONTINUATION_LINE),
2621-
style::Print("\n"),
2622-
style::Print(TOOL_BULLET)
2623-
)?;
2626+
if !self.quiet {
2627+
execute!(
2628+
self.stdout,
2629+
style::Print("\n"),
2630+
style::Print(CONTINUATION_LINE),
2631+
style::Print("\n"),
2632+
style::Print(TOOL_BULLET)
2633+
)?;
2634+
}
26242635

26252636
tool_use
26262637
.tool

0 commit comments

Comments
 (0)