diff --git a/.gitignore b/.gitignore index b8eecf8..fe29988 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,7 @@ target # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ + +# Session logs directory +logs/ +*.json diff --git a/README.md b/README.md index 7280843..57b326b 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,15 @@ cargo run g3 "implement a function to calculate fibonacci numbers" ``` +## Session Logs + +G3 automatically saves session logs for each interaction in the `logs/` directory. These logs contain: +- Complete conversation history +- Token usage statistics +- Timestamps and session status + +The `logs/` directory is created automatically on first use and is excluded from version control. + ## License MIT License - see LICENSE file for details diff --git a/crates/g3-core/src/lib.rs b/crates/g3-core/src/lib.rs index 0bdc57e..17142d8 100644 --- a/crates/g3-core/src/lib.rs +++ b/crates/g3-core/src/lib.rs @@ -789,11 +789,20 @@ The tool will execute immediately and you'll receive the result (success or erro .unwrap_or_default() .as_secs(); + // Create logs directory if it doesn't exist + let logs_dir = std::path::Path::new("logs"); + if !logs_dir.exists() { + if let Err(e) = std::fs::create_dir_all(logs_dir) { + error!("Failed to create logs directory: {}", e); + return; + } + } + // Use session-based filename if we have a session ID, otherwise fall back to timestamp let filename = if let Some(ref session_id) = self.session_id { - format!("g3_session_{}.json", session_id) + format!("logs/g3_session_{}.json", session_id) } else { - format!("g3_context_{}.json", timestamp) + format!("logs/g3_context_{}.json", timestamp) }; let context_data = serde_json::json!({