Remove legacy logs/ directory, consolidate all data under .g3/

This change removes the legacy logs/ directory and consolidates all
session data, error logs, and discovery files under the .g3/ directory.

New directory structure:
- .g3/sessions/<session_id>/session.json - session logs
- .g3/errors/ - error logs (was logs/errors/)
- .g3/background_processes/ - background process logs
- .g3/discovery/ - planner discovery files (was workspace/logs/)

Changes:
- paths.rs: Remove get_logs_dir()/logs_dir(), add get_errors_dir(),
  get_background_processes_dir(), get_discovery_dir()
- session.rs: Anonymous sessions now use .g3/sessions/anonymous_<ts>/
- error_handling.rs: Errors now saved to .g3/errors/
- project.rs: Remove logs_dir() and ensure_logs_dir() methods
- feedback_extraction.rs: Remove logs_dir field and fallback logic
- planner: Use .g3/ for workspace data and .g3/discovery/ for reports
- flock.rs: Look for session metrics in .g3/sessions/
- coach_feedback.rs: Remove fallback to logs/ path
- Update all tests to use new paths
- Update README.md and .gitignore
This commit is contained in:
Dhanji R. Prasanna
2026-01-12 18:20:08 +05:30
parent 43a5d27149
commit c2aa80647a
68 changed files with 744 additions and 159 deletions

View File

@@ -66,7 +66,7 @@ pub async fn get_initial_discovery_messages(
// Step 1: Run explore_codebase to get the codebase report
let codebase_report = explore_codebase(codebase_path);
// Write the codebase report to logs directory
// Write the codebase report to discovery directory
write_code_report(&codebase_report)?;
// Step 2: Build the prompt with the codebase report appended
@@ -112,7 +112,7 @@ pub async fn get_initial_discovery_messages(
shell_commands.len()
));
// Write the discovery commands to logs directory
// Write the discovery commands to discovery directory
write_discovery_commands(&shell_commands)?;
// Step 6: Format as tool messages
@@ -194,21 +194,21 @@ pub fn extract_summary(response: &str) -> Option<String> {
}
}
/// Write the codebase report to logs directory
/// Write the codebase report to discovery directory
fn write_code_report(report: &str) -> Result<()> {
// Get logs directory from workspace path or current dir
let logs_dir = if let Ok(workspace_path) = std::env::var("G3_WORKSPACE_PATH") {
std::path::PathBuf::from(workspace_path).join("logs")
// Get discovery directory from workspace path or current dir
let discovery_dir = if let Ok(workspace_path) = std::env::var("G3_WORKSPACE_PATH") {
std::path::PathBuf::from(workspace_path).join(".g3").join("discovery")
} else {
std::env::current_dir().unwrap_or_default().join("logs")
std::env::current_dir().unwrap_or_default().join(".g3").join("discovery")
};
// Ensure logs directory exists
fs::create_dir_all(&logs_dir)?;
// Ensure discovery directory exists
fs::create_dir_all(&discovery_dir)?;
// Generate timestamp in same format as tool_calls log
let timestamp = Local::now().format("%Y%m%d_%H%M%S").to_string();
let filename = logs_dir.join(format!("code_report_{}.log", timestamp));
let filename = discovery_dir.join(format!("code_report_{}.log", timestamp));
// Write the report to file
let mut file = OpenOptions::new()
@@ -223,21 +223,21 @@ fn write_code_report(report: &str) -> Result<()> {
Ok(())
}
/// Write the discovery commands to logs directory
/// Write the discovery commands to discovery directory
fn write_discovery_commands(commands: &[String]) -> Result<()> {
// Get logs directory from workspace path or current dir
let logs_dir = if let Ok(workspace_path) = std::env::var("G3_WORKSPACE_PATH") {
std::path::PathBuf::from(workspace_path).join("logs")
// Get discovery directory from workspace path or current dir
let discovery_dir = if let Ok(workspace_path) = std::env::var("G3_WORKSPACE_PATH") {
std::path::PathBuf::from(workspace_path).join(".g3").join("discovery")
} else {
std::env::current_dir().unwrap_or_default().join("logs")
std::env::current_dir().unwrap_or_default().join(".g3").join("discovery")
};
// Ensure logs directory exists
fs::create_dir_all(&logs_dir)?;
// Ensure discovery directory exists
fs::create_dir_all(&discovery_dir)?;
// Generate timestamp in same format as tool_calls log
let timestamp = Local::now().format("%Y%m%d_%H%M%S").to_string();
let filename = logs_dir.join(format!("discovery_commands_{}.log", timestamp));
let filename = discovery_dir.join(format!("discovery_commands_{}.log", timestamp));
// Write the commands to file
let mut file = OpenOptions::new()

View File

@@ -324,15 +324,13 @@ pub async fn call_refinement_llm_with_tools(
let ui_writer = PlannerUiWriter::new();
// CRITICAL FIX: Use the actual workspace directory, NOT codepath!
// The workspace is where logs should be written (e.g., /tmp/g3_test_workspace)
// The workspace is where session data should be written (e.g., /tmp/g3_test_workspace)
// The codepath is where the source code lives (e.g., ~/RustroverProjects/g3)
// Previous bug: was using codepath as workspace, causing logs to go to wrong location
let workspace_path = std::path::PathBuf::from(workspace);
let project = Project::new(workspace_path.clone());
project.ensure_workspace_exists()?;
project.enter_workspace()?;
project.ensure_logs_dir()?;
// Create agent - not autonomous mode, just regular agent with tools
let mut agent = Agent::new_with_readme_and_quiet(
planner_config,

View File

@@ -777,13 +777,13 @@ pub async fn run_planning_mode(
// Set G3_WORKSPACE_PATH environment variable EARLY for all logging
std::env::set_var("G3_WORKSPACE_PATH", workspace_dir.display().to_string());
// Create logs directory and verify it exists
let logs_dir = workspace_dir.join("logs");
if !logs_dir.exists() {
fs::create_dir_all(&logs_dir)
.context("Failed to create logs directory")?;
// Create .g3 directory and verify it exists
let g3_dir = workspace_dir.join(".g3");
if !g3_dir.exists() {
fs::create_dir_all(&g3_dir)
.context("Failed to create .g3 directory")?;
}
print_msg(&format!("📁 Logs directory: {}", logs_dir.display()));
print_msg(&format!("📁 G3 directory: {}", g3_dir.display()));
// Create the LLM provider for planning
print_msg("🔧 Initializing planner provider...");

View File

@@ -6,22 +6,22 @@ use std::path::Path;
#[test]
fn test_log_files_created() {
// This test verifies that the logging functions work correctly
// by checking that files can be created in the logs directory
// by checking that files can be created in the discovery directory
// Clean up any existing test logs
let _ = fs::remove_dir_all("logs");
// Clean up any existing test discovery dir
let _ = fs::remove_dir_all(".g3/discovery");
// Create logs directory
fs::create_dir_all("logs").expect("Failed to create logs directory");
// Create discovery directory
fs::create_dir_all(".g3/discovery").expect("Failed to create discovery directory");
// Verify directory exists
assert!(Path::new("logs").exists());
assert!(Path::new("logs").is_dir());
assert!(Path::new(".g3/discovery").exists());
assert!(Path::new(".g3/discovery").is_dir());
// Test writing a code report
let test_report = "Test codebase report\nLine 2\nLine 3";
let timestamp = chrono::Local::now().format("%Y%m%d_%H%M%S").to_string();
let report_filename = format!("logs/code_report_{}.log", timestamp);
let report_filename = format!(".g3/discovery/code_report_{}.log", timestamp);
fs::write(&report_filename, test_report).expect("Failed to write code report");
assert!(Path::new(&report_filename).exists());
@@ -30,7 +30,7 @@ fn test_log_files_created() {
assert_eq!(content, test_report);
// Test writing discovery commands
let commands_filename = format!("logs/discovery_commands_{}.log", timestamp);
let commands_filename = format!(".g3/discovery/discovery_commands_{}.log", timestamp);
let test_commands =
"# Discovery Commands\n# Generated by g3-planner\n\nls -la\ncat README.md\n";

View File

@@ -82,7 +82,6 @@ fn test_extracted_feedback_approval_detection() {
fn test_feedback_extraction_config_default() {
let config = FeedbackExtractionConfig::default();
assert!(!config.verbose);
assert!(config.logs_dir.is_none());
assert!(config.default_feedback.contains("review"));
}
@@ -90,14 +89,9 @@ fn test_feedback_extraction_config_default() {
fn test_feedback_extraction_config_custom() {
let config = FeedbackExtractionConfig {
verbose: true,
logs_dir: Some(std::path::PathBuf::from("/tmp/test_logs")),
default_feedback: "Custom fallback message for testing".to_string(),
};
assert!(config.verbose);
assert_eq!(
config.logs_dir,
Some(std::path::PathBuf::from("/tmp/test_logs"))
);
assert!(config.default_feedback.contains("Custom fallback"));
}