//! Example demonstrating the git integration module //! //! Run with: cargo run -p agent-core --example git_demo use agent_core::{detect_git_state, format_git_status, is_safe_git_command, is_destructive_git_command}; use std::env; fn main() -> color_eyre::Result<()> { color_eyre::install()?; // Get current working directory let cwd = env::current_dir()?; println!("Detecting git state in: {}\n", cwd.display()); // Detect git state let state = detect_git_state(&cwd)?; // Display formatted status println!("{}\n", format_git_status(&state)); // Show detailed file status if there are changes if !state.status.is_empty() { println!("Detailed file status:"); for status in &state.status { match status { agent_core::GitFileStatus::Modified { path } => { println!(" M {}", path); } agent_core::GitFileStatus::Added { path } => { println!(" A {}", path); } agent_core::GitFileStatus::Deleted { path } => { println!(" D {}", path); } agent_core::GitFileStatus::Renamed { from, to } => { println!(" R {} -> {}", from, to); } agent_core::GitFileStatus::Untracked { path } => { println!(" ? {}", path); } } } println!(); } // Test command safety checking println!("Command safety checks:"); let test_commands = vec![ "git status", "git log --oneline", "git diff HEAD", "git commit -m 'test'", "git push --force origin main", "git reset --hard HEAD~1", "git rebase main", "git branch -D feature", ]; for cmd in test_commands { let is_safe = is_safe_git_command(cmd); let (is_destructive, warning) = is_destructive_git_command(cmd); print!(" {} - ", cmd); if is_safe { println!("SAFE (read-only)"); } else if is_destructive { println!("DESTRUCTIVE: {}", warning); } else { println!("UNSAFE (modifies state)"); } } Ok(()) }