--quiet flag suppresses logs

This commit is contained in:
Dhanji Prasanna
2025-10-16 13:08:26 +11:00
parent 41c1363fb5
commit 444c0bc6c6
3 changed files with 59 additions and 12 deletions

View File

@@ -1,4 +1,4 @@
use anyhow::Result;
/// Extract coach feedback by reading from the coach agent's specific log file /// Extract coach feedback by reading from the coach agent's specific log file
/// Uses the coach agent's session ID to find the exact log file /// Uses the coach agent's session ID to find the exact log file
fn extract_coach_feedback_from_logs(_coach_result: &g3_core::TaskResult, coach_agent: &g3_core::Agent<ConsoleUiWriter>, output: &SimpleOutput) -> Result<String> { fn extract_coach_feedback_from_logs(_coach_result: &g3_core::TaskResult, coach_agent: &g3_core::Agent<ConsoleUiWriter>, output: &SimpleOutput) -> Result<String> {
@@ -37,7 +37,8 @@ fn extract_coach_feedback_from_logs(_coach_result: &g3_core::TaskResult, coach_a
} }
Err(anyhow::anyhow!("Could not extract feedback from coach session: {}", session_id)) Err(anyhow::anyhow!("Could not extract feedback from coach session: {}", session_id))
}use anyhow::Result; }
use clap::Parser; use clap::Parser;
use g3_config::Config; use g3_config::Config;
use g3_core::{project::Project, ui_writer::UiWriter, Agent}; use g3_core::{project::Project, ui_writer::UiWriter, Agent};
@@ -113,6 +114,10 @@ pub struct Cli {
/// Override the model for the selected provider /// Override the model for the selected provider
#[arg(long, value_name = "MODEL")] #[arg(long, value_name = "MODEL")]
pub model: Option<String>, pub model: Option<String>,
/// Disable log file creation (no logs/ directory or session logs)
#[arg(long)]
pub quiet: bool,
} }
pub async fn run() -> Result<()> { pub async fn run() -> Result<()> {
@@ -218,9 +223,9 @@ pub async fn run() -> Result<()> {
// Initialize agent // Initialize agent
let ui_writer = ConsoleUiWriter::new(); let ui_writer = ConsoleUiWriter::new();
let mut agent = if cli.autonomous { let mut agent = if cli.autonomous {
Agent::new_autonomous_with_readme(config.clone(), ui_writer, readme_content.clone()).await? Agent::new_autonomous_with_readme_and_quiet(config.clone(), ui_writer, readme_content.clone(), cli.quiet).await?
} else { } else {
Agent::new_with_readme(config.clone(), ui_writer, readme_content.clone()).await? Agent::new_with_readme_and_quiet(config.clone(), ui_writer, readme_content.clone(), cli.quiet).await?
}; };
// Execute task, autonomous mode, or start interactive mode // Execute task, autonomous mode, or start interactive mode
@@ -235,6 +240,7 @@ pub async fn run() -> Result<()> {
cli.show_prompt, cli.show_prompt,
cli.show_code, cli.show_code,
cli.max_turns, cli.max_turns,
cli.quiet,
) )
.await?; .await?;
} else if let Some(task) = cli.task { } else if let Some(task) = cli.task {
@@ -396,7 +402,7 @@ async fn run_interactive_retro(
// Create agent with RetroTuiWriter // Create agent with RetroTuiWriter
let ui_writer = RetroTuiWriter::new(tui.clone()); let ui_writer = RetroTuiWriter::new(tui.clone());
let mut agent = Agent::new_with_readme(config, ui_writer, readme_content.clone()).await?; let mut agent = Agent::new_with_readme_and_quiet(config, ui_writer, readme_content.clone(), false).await?;
// Display initial system messages // Display initial system messages
tui.output("SYSTEM: AGENT ONLINE\n\n"); tui.output("SYSTEM: AGENT ONLINE\n\n");
@@ -930,6 +936,7 @@ async fn run_autonomous(
show_prompt: bool, show_prompt: bool,
show_code: bool, show_code: bool,
max_turns: usize, max_turns: usize,
quiet: bool,
) -> Result<()> { ) -> Result<()> {
let start_time = std::time::Instant::now(); let start_time = std::time::Instant::now();
let output = SimpleOutput::new(); let output = SimpleOutput::new();
@@ -1194,7 +1201,7 @@ async fn run_autonomous(
// Use the same config with overrides that was passed to the player agent // Use the same config with overrides that was passed to the player agent
let config = agent.get_config().clone(); let config = agent.get_config().clone();
let ui_writer = ConsoleUiWriter::new(); let ui_writer = ConsoleUiWriter::new();
let mut coach_agent = Agent::new_autonomous(config, ui_writer).await?; let mut coach_agent = Agent::new_autonomous_with_readme_and_quiet(config, ui_writer, None, quiet).await?;
// Ensure coach agent is also in the workspace directory // Ensure coach agent is also in the workspace directory
project.enter_workspace()?; project.enter_workspace()?;

View File

@@ -55,6 +55,8 @@ pub struct ErrorContext {
pub context_tokens: u32, pub context_tokens: u32,
/// Session ID if available /// Session ID if available
pub session_id: Option<String>, pub session_id: Option<String>,
/// Whether to skip file logging (quiet mode)
pub quiet: bool,
} }
impl ErrorContext { impl ErrorContext {
@@ -65,6 +67,7 @@ impl ErrorContext {
last_prompt: String, last_prompt: String,
session_id: Option<String>, session_id: Option<String>,
context_tokens: u32, context_tokens: u32,
quiet: bool,
) -> Self { ) -> Self {
let timestamp = std::time::SystemTime::now() let timestamp = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH) .duration_since(std::time::UNIX_EPOCH)
@@ -85,6 +88,7 @@ impl ErrorContext {
timestamp, timestamp,
context_tokens, context_tokens,
session_id, session_id,
quiet,
} }
} }
@@ -126,6 +130,11 @@ impl ErrorContext {
/// Save error context to a file for later analysis /// Save error context to a file for later analysis
fn save_to_file(&self) { fn save_to_file(&self) {
// Skip file logging if quiet mode is enabled
if self.quiet {
return;
}
let logs_dir = std::path::Path::new("logs/errors"); let logs_dir = std::path::Path::new("logs/errors");
if !logs_dir.exists() { if !logs_dir.exists() {
if let Err(e) = std::fs::create_dir_all(logs_dir) { if let Err(e) = std::fs::create_dir_all(logs_dir) {

View File

@@ -422,11 +422,12 @@ pub struct Agent<W: UiWriter> {
tool_call_metrics: Vec<(String, Duration, bool)>, // (tool_name, duration, success) tool_call_metrics: Vec<(String, Duration, bool)>, // (tool_name, duration, success)
ui_writer: W, ui_writer: W,
is_autonomous: bool, is_autonomous: bool,
quiet: bool,
} }
impl<W: UiWriter> Agent<W> { impl<W: UiWriter> Agent<W> {
pub async fn new(config: Config, ui_writer: W) -> Result<Self> { pub async fn new(config: Config, ui_writer: W) -> Result<Self> {
Self::new_with_mode(config, ui_writer, false).await Self::new_with_mode(config, ui_writer, false, false).await
} }
pub async fn new_with_readme( pub async fn new_with_readme(
@@ -434,7 +435,7 @@ impl<W: UiWriter> Agent<W> {
ui_writer: W, ui_writer: W,
readme_content: Option<String>, readme_content: Option<String>,
) -> Result<Self> { ) -> Result<Self> {
Self::new_with_mode_and_readme(config, ui_writer, false, readme_content).await Self::new_with_mode_and_readme(config, ui_writer, false, readme_content, false).await
} }
pub async fn new_autonomous_with_readme( pub async fn new_autonomous_with_readme(
@@ -442,15 +443,37 @@ impl<W: UiWriter> Agent<W> {
ui_writer: W, ui_writer: W,
readme_content: Option<String>, readme_content: Option<String>,
) -> Result<Self> { ) -> Result<Self> {
Self::new_with_mode_and_readme(config, ui_writer, true, readme_content).await Self::new_with_mode_and_readme(config, ui_writer, true, readme_content, false).await
} }
pub async fn new_autonomous(config: Config, ui_writer: W) -> Result<Self> { pub async fn new_autonomous(config: Config, ui_writer: W) -> Result<Self> {
Self::new_with_mode(config, ui_writer, true).await Self::new_with_mode(config, ui_writer, true, false).await
} }
async fn new_with_mode(config: Config, ui_writer: W, is_autonomous: bool) -> Result<Self> { pub async fn new_with_quiet(config: Config, ui_writer: W, quiet: bool) -> Result<Self> {
Self::new_with_mode_and_readme(config, ui_writer, is_autonomous, None).await Self::new_with_mode(config, ui_writer, false, quiet).await
}
pub async fn new_with_readme_and_quiet(
config: Config,
ui_writer: W,
readme_content: Option<String>,
quiet: bool,
) -> Result<Self> {
Self::new_with_mode_and_readme(config, ui_writer, false, readme_content, quiet).await
}
pub async fn new_autonomous_with_readme_and_quiet(
config: Config,
ui_writer: W,
readme_content: Option<String>,
quiet: bool,
) -> Result<Self> {
Self::new_with_mode_and_readme(config, ui_writer, true, readme_content, quiet).await
}
async fn new_with_mode(config: Config, ui_writer: W, is_autonomous: bool, quiet: bool) -> Result<Self> {
Self::new_with_mode_and_readme(config, ui_writer, is_autonomous, None, quiet).await
} }
async fn new_with_mode_and_readme( async fn new_with_mode_and_readme(
@@ -458,6 +481,7 @@ impl<W: UiWriter> Agent<W> {
ui_writer: W, ui_writer: W,
is_autonomous: bool, is_autonomous: bool,
readme_content: Option<String>, readme_content: Option<String>,
quiet: bool,
) -> Result<Self> { ) -> Result<Self> {
let mut providers = ProviderRegistry::new(); let mut providers = ProviderRegistry::new();
@@ -560,6 +584,7 @@ impl<W: UiWriter> Agent<W> {
tool_call_metrics: Vec::new(), tool_call_metrics: Vec::new(),
ui_writer, ui_writer,
is_autonomous, is_autonomous,
quiet,
}) })
} }
@@ -922,6 +947,11 @@ The tool will execute immediately and you'll receive the result (success or erro
/// Save the entire context window to a per-session file /// Save the entire context window to a per-session file
fn save_context_window(&self, status: &str) { fn save_context_window(&self, status: &str) {
// Skip logging if quiet mode is enabled
if self.quiet {
return;
}
let timestamp = std::time::SystemTime::now() let timestamp = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH) .duration_since(std::time::UNIX_EPOCH)
.unwrap_or_default() .unwrap_or_default()
@@ -1314,6 +1344,7 @@ The tool will execute immediately and you'll receive the result (success or erro
last_prompt, last_prompt,
self.session_id.clone(), self.session_id.clone(),
self.context_window.used_tokens, self.context_window.used_tokens,
self.quiet,
) )
.with_request( .with_request(
serde_json::to_string(&request) serde_json::to_string(&request)