Skip to content

Commit e1191ba

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 c3fb079 commit e1191ba

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
@@ -238,7 +238,7 @@ impl ChatArgs {
238238
let mut stderr = std::io::stderr();
239239

240240
let args: Vec<String> = std::env::args().collect();
241-
if args
241+
if !self.quiet && args
242242
.iter()
243243
.any(|arg| arg == "--profile" || arg.starts_with("--profile="))
244244
{
@@ -288,7 +288,7 @@ impl ChatArgs {
288288
.get_active()
289289
.is_some_and(|a| !a.mcp_servers.mcp_servers.is_empty())
290290
{
291-
if !self.no_interactive && !os.database.settings.get_bool(Setting::McpLoadedBefore).unwrap_or(false) {
291+
if !self.no_interactive && !self.quiet && !os.database.settings.get_bool(Setting::McpLoadedBefore).unwrap_or(false) {
292292
execute!(
293293
stderr,
294294
style::Print(
@@ -301,7 +301,7 @@ impl ChatArgs {
301301

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

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

@@ -2236,7 +2238,12 @@ impl ChatSession {
22362238
)?;
22372239
response_prefix_printed = true;
22382240
}
2239-
buf.push_str(&text);
2241+
if self.quiet && buf.is_empty() {
2242+
// In quiet mode, trim leading whitespace from the first text
2243+
buf.push_str(text.trim_start());
2244+
} else {
2245+
buf.push_str(&text);
2246+
}
22402247
},
22412248
parser::ResponseEvent::ToolUse(tool_use) => {
22422249
if self.spinner.is_some() {
@@ -2639,34 +2646,38 @@ impl ChatSession {
26392646

26402647
let tool_use = &self.tool_uses[tool_index];
26412648

2642-
queue!(
2643-
self.stdout,
2644-
style::SetForegroundColor(Color::Magenta),
2645-
style::Print(format!(
2646-
"🛠️ Using tool: {}{}",
2647-
tool_use.tool.display_name(),
2648-
if trusted { " (trusted)".dark_green() } else { "".reset() }
2649-
)),
2650-
style::SetForegroundColor(Color::Reset)
2651-
)?;
2652-
if let Tool::Custom(ref tool) = tool_use.tool {
2649+
if !self.quiet {
26532650
queue!(
26542651
self.stdout,
2655-
style::SetForegroundColor(Color::Reset),
2656-
style::Print(" from mcp server "),
26572652
style::SetForegroundColor(Color::Magenta),
2658-
style::Print(tool.client.get_server_name()),
2659-
style::SetForegroundColor(Color::Reset),
2653+
style::Print(format!(
2654+
"🛠️ Using tool: {}{}",
2655+
tool_use.tool.display_name(),
2656+
if trusted { " (trusted)".dark_green() } else { "".reset() }
2657+
)),
2658+
style::SetForegroundColor(Color::Reset)
26602659
)?;
2660+
if let Tool::Custom(ref tool) = tool_use.tool {
2661+
queue!(
2662+
self.stdout,
2663+
style::SetForegroundColor(Color::Reset),
2664+
style::Print(" from mcp server "),
2665+
style::SetForegroundColor(Color::Magenta),
2666+
style::Print(tool.client.get_server_name()),
2667+
style::SetForegroundColor(Color::Reset),
2668+
)?;
2669+
}
26612670
}
26622671

2663-
execute!(
2664-
self.stdout,
2665-
style::Print("\n"),
2666-
style::Print(CONTINUATION_LINE),
2667-
style::Print("\n"),
2668-
style::Print(TOOL_BULLET)
2669-
)?;
2672+
if !self.quiet {
2673+
execute!(
2674+
self.stdout,
2675+
style::Print("\n"),
2676+
style::Print(CONTINUATION_LINE),
2677+
style::Print("\n"),
2678+
style::Print(TOOL_BULLET)
2679+
)?;
2680+
}
26702681

26712682
tool_use
26722683
.tool

0 commit comments

Comments
 (0)