Skip to main content

claude_utils/turbo/
mod.rs

1pub mod proxy;
2pub mod executor;
3pub mod rollback;
4pub mod checkpoint_store;
5
6use serde::{Deserialize, Serialize};
7use std::sync::Arc;
8use tokio::sync::RwLock;
9use tracing::{error, warn};
10
11#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct TurboConfig {
13    pub enabled: bool,
14    pub full_yolo: bool,
15    pub parallel_limit: usize,
16    pub auto_retry: bool,
17    pub retry_count: u32,
18    pub rollback_enabled: bool,
19}
20
21impl Default for TurboConfig {
22    fn default() -> Self {
23        Self {
24            enabled: false,
25            full_yolo: false,
26            parallel_limit: 4,
27            auto_retry: true,
28            retry_count: 3,
29            rollback_enabled: true,
30        }
31    }
32}
33
34impl TurboConfig {
35    pub fn validate(&self) -> Result<(), String> {
36        if self.parallel_limit == 0 {
37            return Err("Parallel limit must be at least 1".to_string());
38        }
39        if self.parallel_limit > 32 {
40            return Err("Parallel limit should not exceed 32 for system stability".to_string());
41        }
42        if self.retry_count > 10 {
43            return Err("Retry count should not exceed 10".to_string());
44        }
45        Ok(())
46    }
47}
48
49pub struct TurboMode {
50    pub config: Arc<RwLock<TurboConfig>>,
51    pub executor: Arc<executor::ParallelExecutor>,
52    pub rollback_manager: Arc<rollback::RollbackManager>,
53}
54
55impl TurboMode {
56    pub async fn new(config: TurboConfig) -> crate::Result<Self> {
57        let config = Arc::new(RwLock::new(config));
58        let executor = Arc::new(executor::ParallelExecutor::new(
59            config.read().await.parallel_limit,
60        ));
61        let rollback_manager = Arc::new(rollback::RollbackManager::new().await?);
62
63        Ok(Self {
64            config,
65            executor,
66            rollback_manager,
67        })
68    }
69
70    pub async fn is_yolo(&self) -> bool {
71        self.config.read().await.full_yolo
72    }
73
74    pub async fn enable_yolo(&self) {
75        self.config.write().await.full_yolo = true;
76        self.display_safety_warning();
77    }
78    
79    pub fn display_safety_warning(&self) {
80        warn!("╔══════════════════════════════════════════════════════════════╗");
81        warn!("║                    ⚠️  TURBO MODE WARNING ⚠️                    ║");
82        warn!("╠══════════════════════════════════════════════════════════════╣");
83        warn!("║                                                              ║");
84        warn!("║  🚀 FULL YOLO MODE ACTIVATED - EXTREME CAUTION REQUIRED!    ║");
85        warn!("║                                                              ║");
86        warn!("║  This mode BYPASSES ALL SAFETY CHECKS:                      ║");
87        warn!("║  • ALL file operations are AUTO-APPROVED                    ║");
88        warn!("║  • ALL command executions are AUTO-APPROVED                 ║");
89        warn!("║  • NO permission prompts will be shown                      ║");
90        warn!("║  • Claude can DELETE, MODIFY, or CREATE any files           ║");
91        warn!("║                                                              ║");
92        warn!("║  ⚡ RECOMMENDATIONS:                                         ║");
93        warn!("║  • Ensure you have BACKUPS of important files               ║");
94        warn!("║  • Use VERSION CONTROL (git) for safety                     ║");
95        warn!("║  • Create a CHECKPOINT before major operations              ║");
96        warn!("║  • Monitor Claude's actions carefully                       ║");
97        warn!("║                                                              ║");
98        warn!("║  🛡️  SAFETY FEATURES ACTIVE:                                ║");
99        warn!("║  • Automatic checkpoints before major operations            ║");
100        warn!("║  • Instant rollback with: claude-utils turbo rollback       ║");
101        warn!("║  • Git stash integration for recovery                       ║");
102        warn!("║                                                              ║");
103        warn!("║  Press Ctrl+C to abort if you're not ready!                 ║");
104        warn!("╚══════════════════════════════════════════════════════════════╝");
105    }
106    
107    pub async fn create_safety_checkpoint(&self, description: &str) -> crate::Result<()> {
108        if self.config.read().await.rollback_enabled {
109            match self.rollback_manager.create_checkpoint(description.to_string()).await {
110                Ok(_) => {
111                    warn!("✅ Safety checkpoint created: {}", description);
112                    Ok(())
113                }
114                Err(e) => {
115                    error!("❌ Failed to create safety checkpoint: {}", e);
116                    Err(e)
117                }
118            }
119        } else {
120            Ok(())
121        }
122    }
123}