soma-core 2.0.2

World's first production-ready self-aware development system with meta-cognitive capabilities and cognitive reasoning engine for intelligent development platforms
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
use std::io::{self, Write};
use crossterm::{
    event::{self, Event, KeyCode},
    execute,
    style::{Color, Print, ResetColor, SetForegroundColor},
    terminal::{self, Clear, ClearType},
    cursor,
};
use crate::git_integration::{
    GitIntegrationSystem, GitOperationResult, ConflictStrategy
};
use crate::edit_control::ModifiableEdit;
use crate::classification::ClassifiedEdit;

/// Interactive Git Integration CLI Interface
/// Provides comprehensive Git workflow management for SOMA-CORE
pub struct GitIntegrationCLI {
    /// Git integration system
    pub git_system: GitIntegrationSystem,
    /// Current view mode
    pub view_mode: GitViewMode,
    /// Active panel in the interface
    pub active_panel: GitPanel,
    /// Status message for user feedback
    pub status_message: String,
    /// Show help panel
    pub show_help: bool,
    /// Session edits pending Git operations
    pub pending_edits: Vec<(ModifiableEdit, ClassifiedEdit)>,
}

/// Git interface view modes
#[derive(Debug, Clone, PartialEq)]
pub enum GitViewMode {
    /// Session overview with status and controls
    SessionOverview,
    /// Branch management interface
    BranchManagement,
    /// Commit history and operations
    CommitHistory,
    /// Conflict resolution interface
    ConflictResolution,
    /// Backup and restore interface
    BackupManagement,
}

/// Active panels in Git interface
#[derive(Debug, Clone, PartialEq)]
pub enum GitPanel {
    /// Session status panel
    SessionStatus,
    /// Git operations panel
    Operations,
    /// File changes panel
    FileChanges,
    /// Configuration panel
    Configuration,
}

impl GitIntegrationCLI {
    /// Create new Git integration CLI
    pub fn new(repository_path: std::path::PathBuf) -> Result<Self, String> {
        let git_system = GitIntegrationSystem::new(repository_path)?;
        
        Ok(GitIntegrationCLI {
            git_system,
            view_mode: GitViewMode::SessionOverview,
            active_panel: GitPanel::SessionStatus,
            status_message: "Git Integration ready".to_string(),
            show_help: false,
            pending_edits: Vec::new(),
        })
    }

    /// Start interactive Git workflow session
    pub fn start_interactive_session(&mut self) -> Result<(), String> {
        // Initialize terminal
        terminal::enable_raw_mode().map_err(|e| format!("Failed to enable raw mode: {}", e))?;
        
        let result = self.run_interactive_loop();
        
        // Restore terminal
        terminal::disable_raw_mode().map_err(|e| format!("Failed to disable raw mode: {}", e))?;
        execute!(io::stdout(), Clear(ClearType::All), cursor::MoveTo(0, 0)).ok();
        
        result
    }

    /// Main interactive loop
    fn run_interactive_loop(&mut self) -> Result<(), String> {
        loop {
            // Render interface
            self.render_interface()?;
            
            // Handle user input
            if let Ok(Event::Key(key_event)) = event::read() {
                match key_event.code {
                    KeyCode::Char('q') | KeyCode::Esc => {
                        break;
                    }
                    KeyCode::Char('h') => {
                        self.show_help = !self.show_help;
                    }
                    KeyCode::Char('s') => {
                        self.handle_start_session()?;
                    }
                    KeyCode::Char('e') => {
                        self.handle_end_session()?;
                    }
                    KeyCode::Char('c') => {
                        self.handle_commit_changes()?;
                    }
                    KeyCode::Char('b') => {
                        self.handle_create_backup()?;
                    }
                    KeyCode::Char('m') => {
                        self.handle_merge_session()?;
                    }
                    KeyCode::Tab => {
                        self.cycle_panels();
                    }
                    KeyCode::F(1) => {
                        self.view_mode = GitViewMode::SessionOverview;
                    }
                    KeyCode::F(2) => {
                        self.view_mode = GitViewMode::BranchManagement;
                    }
                    KeyCode::F(3) => {
                        self.view_mode = GitViewMode::CommitHistory;
                    }
                    KeyCode::F(4) => {
                        self.view_mode = GitViewMode::ConflictResolution;
                    }
                    KeyCode::F(5) => {
                        self.view_mode = GitViewMode::BackupManagement;
                    }
                    KeyCode::Char('1') => {
                        self.active_panel = GitPanel::SessionStatus;
                    }
                    KeyCode::Char('2') => {
                        self.active_panel = GitPanel::Operations;
                    }
                    KeyCode::Char('3') => {
                        self.active_panel = GitPanel::FileChanges;
                    }
                    KeyCode::Char('4') => {
                        self.active_panel = GitPanel::Configuration;
                    }
                    _ => {}
                }
            }
        }
        
        Ok(())
    }

    /// Render the complete Git interface
    fn render_interface(&self) -> Result<(), String> {
        execute!(io::stdout(), Clear(ClearType::All), cursor::MoveTo(0, 0))
            .map_err(|e| format!("Failed to clear screen: {}", e))?;

        // Render header
        self.render_header()?;
        
        // Render main content based on view mode
        match self.view_mode {
            GitViewMode::SessionOverview => self.render_session_overview()?,
            GitViewMode::BranchManagement => self.render_branch_management()?,
            GitViewMode::CommitHistory => self.render_commit_history()?,
            GitViewMode::ConflictResolution => self.render_conflict_resolution()?,
            GitViewMode::BackupManagement => self.render_backup_management()?,
        }

        // Render footer
        self.render_footer()?;
        
        // Render help if enabled
        if self.show_help {
            self.render_help_panel()?;
        }

        io::stdout().flush().map_err(|e| format!("Failed to flush stdout: {}", e))?;
        Ok(())
    }

    /// Render interface header
    fn render_header(&self) -> Result<(), String> {
        execute!(io::stdout(), 
            SetForegroundColor(Color::Cyan),
            Print("╔══════════════════════════════════════════════════════════════════════════════╗\n"),
            Print("║                    🔧 SOMA-CORE Git Integration Interface                    ║\n"),
            Print("╚══════════════════════════════════════════════════════════════════════════════╝\n"),
            ResetColor
        ).map_err(|e| format!("Failed to render header: {}", e))?;

        // Session status line
        execute!(io::stdout(),
            SetForegroundColor(Color::Yellow),
            Print(&format!("Session: {} | Branch: {} | View: {:?}\n", 
                self.git_system.session_state.session_id,
                self.git_system.session_state.current_branch,
                self.view_mode
            )),
            ResetColor,
            Print("\n")
        ).map_err(|e| format!("Failed to render session status: {}", e))?;

        Ok(())
    }

    /// Render session overview
    fn render_session_overview(&self) -> Result<(), String> {
        let session = &self.git_system.session_state;
        
        execute!(io::stdout(),
            SetForegroundColor(Color::Green),
            Print("📊 Session Overview\n"),
            Print("═══════════════════\n"),
            ResetColor,
            Print(&format!("Session ID: {}\n", session.session_id)),
            Print(&format!("Start Time: {:?}\n", session.start_time)),
            Print(&format!("Current Branch: {}\n", session.current_branch)),
            Print(&format!("Original Branch: {}\n", session.original_branch)),
            Print(&format!("Edits Applied: {}\n", session.edits_applied.len())),
            Print(&format!("Commits: {}\n", session.commit_history.len())),
            Print(&format!("Backup Points: {}\n", session.backup_points.len())),
            Print("\n"),
            
            SetForegroundColor(Color::Cyan),
            Print("🔧 Git Configuration\n"),
            Print("═══════════════════\n"),
            ResetColor,
            Print(&format!("Auto Commit: {}\n", self.git_system.config.auto_commit)),
            Print(&format!("Session Branches: {}\n", self.git_system.config.session_branches)),
            Print(&format!("Backup Frequency: {} minutes\n", self.git_system.config.backup_frequency_minutes)),
            Print(&format!("CI/CD Integration: {}\n", self.git_system.config.cicd_integration)),
            Print(&format!("Conflict Strategy: {:?}\n", self.git_system.config.conflict_strategy)),
            Print("\n")
        ).map_err(|e| format!("Failed to render session overview: {}", e))?;

        // Render pending edits if any
        if !self.pending_edits.is_empty() {
            execute!(io::stdout(),
                SetForegroundColor(Color::Yellow),
                Print("📝 Pending Edits\n"),
                Print("════════════════\n"),
                ResetColor
            ).map_err(|e| format!("Failed to render pending edits header: {}", e))?;

            for (i, (edit, classification)) in self.pending_edits.iter().enumerate() {
                let classification_color = match &classification.category {
                    crate::classification::EditCategory::Critical { .. } => Color::Red,
                    crate::classification::EditCategory::Experimental { .. } => Color::Yellow,
                    crate::classification::EditCategory::Safe { .. } => Color::Green,
                    crate::classification::EditCategory::Cosmetic { .. } => Color::Blue,
                };

                execute!(io::stdout(),
                    SetForegroundColor(classification_color),
                    Print(&format!("{}. {} - {:?}\n", 
                        i + 1, 
                        edit.base_edit.file,
                        classification.category
                    )),
                    ResetColor
                ).map_err(|e| format!("Failed to render pending edit: {}", e))?;
            }
            execute!(io::stdout(), Print("\n")).ok();
        }

        Ok(())
    }

    /// Render branch management interface
    fn render_branch_management(&self) -> Result<(), String> {
        execute!(io::stdout(),
            SetForegroundColor(Color::Green),
            Print("🌿 Branch Management\n"),
            Print("══════════════════\n"),
            ResetColor,
            Print(&format!("Current Branch: {}\n", self.git_system.session_state.current_branch)),
            Print(&format!("Original Branch: {}\n", self.git_system.session_state.original_branch)),
            Print(&format!("Branch Strategy: {:?}\n", self.git_system.branch_manager.naming_strategy)),
            Print(&format!("Auto Cleanup: {}\n", self.git_system.branch_manager.auto_cleanup)),
            Print("\n"),
            
            SetForegroundColor(Color::Cyan),
            Print("Available Operations:\n"),
            ResetColor,
            Print("• Create new session branch\n"),
            Print("• Switch branch\n"),
            Print("• Merge session to main\n"),
            Print("• Delete session branch\n"),
            Print("\n")
        ).map_err(|e| format!("Failed to render branch management: {}", e))?;

        Ok(())
    }

    /// Render commit history
    fn render_commit_history(&self) -> Result<(), String> {
        execute!(io::stdout(),
            SetForegroundColor(Color::Green),
            Print("📚 Commit History\n"),
            Print("═══════════════\n"),
            ResetColor
        ).map_err(|e| format!("Failed to render commit history header: {}", e))?;

        if self.git_system.session_state.commit_history.is_empty() {
            execute!(io::stdout(),
                SetForegroundColor(Color::Yellow),
                Print("No commits in current session\n"),
                ResetColor
            ).map_err(|e| format!("Failed to render no commits message: {}", e))?;
        } else {
            for (i, commit) in self.git_system.session_state.commit_history.iter().enumerate() {
                execute!(io::stdout(),
                    SetForegroundColor(Color::Cyan),
                    Print(&format!("{}. {}\n", i + 1, &commit.hash[..8])),
                    ResetColor,
                    Print(&format!("   Message: {}\n", commit.message)),
                    Print(&format!("   Files: {}\n", commit.files_changed.join(", "))),
                    Print(&format!("   Time: {:?}\n", commit.timestamp)),
                    Print("\n")
                ).map_err(|e| format!("Failed to render commit: {}", e))?;
            }
        }

        Ok(())
    }

    /// Render conflict resolution interface
    fn render_conflict_resolution(&self) -> Result<(), String> {
        execute!(io::stdout(),
            SetForegroundColor(Color::Red),
            Print("⚠️  Conflict Resolution\n"),
            Print("═════════════════════\n"),
            ResetColor,
            Print("Conflict Resolution Strategies:\n"),
            Print("• Prefer Local Changes\n"),
            Print("• Prefer Remote Changes\n"),
            Print("• Interactive Resolution\n"),
            Print("• Classification-Based Resolution\n"),
            Print("• Cognitive Operator Resolution\n"),
            Print("\n"),
            
            SetForegroundColor(Color::Yellow),
            Print("Current Strategy: "),
            ResetColor,
            Print(&format!("{:?}\n", self.git_system.conflict_resolver.strategies.first().unwrap_or(&ConflictStrategy::Interactive))),
            Print("\n")
        ).map_err(|e| format!("Failed to render conflict resolution: {}", e))?;

        Ok(())
    }

    /// Render backup management interface
    fn render_backup_management(&self) -> Result<(), String> {
        execute!(io::stdout(),
            SetForegroundColor(Color::Green),
            Print("💾 Backup Management\n"),
            Print("══════════════════\n"),
            ResetColor
        ).map_err(|e| format!("Failed to render backup management header: {}", e))?;

        if self.git_system.session_state.backup_points.is_empty() {
            execute!(io::stdout(),
                SetForegroundColor(Color::Yellow),
                Print("No backup points created\n"),
                ResetColor
            ).map_err(|e| format!("Failed to render no backups message: {}", e))?;
        } else {
            for (i, backup) in self.git_system.session_state.backup_points.iter().enumerate() {
                execute!(io::stdout(),
                    SetForegroundColor(Color::Cyan),
                    Print(&format!("{}. Backup: {}\n", i + 1, backup.id)),
                    ResetColor,
                    Print(&format!("   Description: {}\n", backup.description)),
                    Print(&format!("   State Hash: {}\n", &backup.state_hash[..8])),
                    Print(&format!("   Time: {:?}\n", backup.timestamp)),
                    Print("\n")
                ).map_err(|e| format!("Failed to render backup: {}", e))?;
            }
        }

        execute!(io::stdout(),
            SetForegroundColor(Color::Cyan),
            Print("Backup Configuration:\n"),
            ResetColor,
            Print(&format!("Compression: {}\n", self.git_system.backup_manager.compress_backups)),
            Print(&format!("Incremental: {}\n", self.git_system.backup_manager.incremental)),
            Print("\n")
        ).map_err(|e| format!("Failed to render backup config: {}", e))?;

        Ok(())
    }

    /// Render footer with keyboard shortcuts
    fn render_footer(&self) -> Result<(), String> {
        execute!(io::stdout(),
            SetForegroundColor(Color::Cyan),
            Print("".repeat(80)),
            Print("\n"),
            Print("Commands: [s]tart session | [e]nd session | [c]ommit | [b]ackup | [m]erge | [h]elp | [q]uit\n"),
            Print("Views: F1-Overview | F2-Branches | F3-Commits | F4-Conflicts | F5-Backups | Tab-Cycle Panels\n"),
            ResetColor
        ).map_err(|e| format!("Failed to render footer: {}", e))?;

        // Status message
        if !self.status_message.is_empty() {
            execute!(io::stdout(),
                SetForegroundColor(Color::Yellow),
                Print(&format!("Status: {}\n", self.status_message)),
                ResetColor
            ).map_err(|e| format!("Failed to render status: {}", e))?;
        }

        Ok(())
    }

    /// Render help panel
    fn render_help_panel(&self) -> Result<(), String> {
        execute!(io::stdout(),
            cursor::MoveTo(20, 8),
            SetForegroundColor(Color::White),
            Print("╔═══════════════════════════════════════╗\n"),
            cursor::MoveTo(20, 9),
            Print("║            🔧 Git Help                ║\n"),
            cursor::MoveTo(20, 10),
            Print("╠═══════════════════════════════════════╣\n"),
            cursor::MoveTo(20, 11),
            Print("║ s - Start new Git session            ║\n"),
            cursor::MoveTo(20, 12),
            Print("║ e - End current session              ║\n"),
            cursor::MoveTo(20, 13),
            Print("║ c - Commit current changes           ║\n"),
            cursor::MoveTo(20, 14),
            Print("║ b - Create backup point              ║\n"),
            cursor::MoveTo(20, 15),
            Print("║ m - Merge session to main            ║\n"),
            cursor::MoveTo(20, 16),
            Print("║ F1-F5 - Switch view modes            ║\n"),
            cursor::MoveTo(20, 17),
            Print("║ Tab - Cycle through panels           ║\n"),
            cursor::MoveTo(20, 18),
            Print("║ h - Toggle this help                 ║\n"),
            cursor::MoveTo(20, 19),
            Print("║ q/Esc - Quit                         ║\n"),
            cursor::MoveTo(20, 20),
            Print("╚═══════════════════════════════════════╝\n"),
            ResetColor
        ).map_err(|e| format!("Failed to render help panel: {}", e))?;

        Ok(())
    }

    /// Cycle through panels
    fn cycle_panels(&mut self) {
        self.active_panel = match self.active_panel {
            GitPanel::SessionStatus => GitPanel::Operations,
            GitPanel::Operations => GitPanel::FileChanges,
            GitPanel::FileChanges => GitPanel::Configuration,
            GitPanel::Configuration => GitPanel::SessionStatus,
        };
    }

    /// Handle start session command
    fn handle_start_session(&mut self) -> Result<(), String> {
        match self.git_system.start_session(None) {
            Ok(message) => {
                self.status_message = message;
            }
            Err(e) => {
                self.status_message = format!("Error starting session: {}", e);
            }
        }
        Ok(())
    }

    /// Handle end session command
    fn handle_end_session(&mut self) -> Result<(), String> {
        match self.git_system.end_session(false) {
            Ok(message) => {
                self.status_message = message;
            }
            Err(e) => {
                self.status_message = format!("Error ending session: {}", e);
            }
        }
        Ok(())
    }

    /// Handle commit changes command
    fn handle_commit_changes(&mut self) -> Result<(), String> {
        let message = "SOMA Interactive Commit";
        match self.git_system.commit_current_changes(message) {
            Ok(hash) => {
                self.status_message = format!("Committed successfully: {}", &hash[..8]);
            }
            Err(e) => {
                self.status_message = format!("Commit error: {}", e);
            }
        }
        Ok(())
    }

    /// Handle create backup command
    fn handle_create_backup(&mut self) -> Result<(), String> {
        match self.git_system.backup_manager.create_backup_point("Interactive backup".to_string()) {
            Ok(backup) => {
                self.status_message = format!("Backup created: {}", backup.id);
                // Add to session state
                let mut session_state = self.git_system.session_state.clone();
                session_state.backup_points.push(backup);
                self.git_system.session_state = session_state;
            }
            Err(e) => {
                self.status_message = format!("Backup error: {}", e);
            }
        }
        Ok(())
    }

    /// Handle merge session command
    fn handle_merge_session(&mut self) -> Result<(), String> {
        match self.git_system.merge_session_to_main() {
            Ok(()) => {
                self.status_message = "Session merged to main successfully".to_string();
            }
            Err(e) => {
                self.status_message = format!("Merge error: {}", e);
            }
        }
        Ok(())
    }

    /// Add pending edits for Git processing
    pub fn add_pending_edits(&mut self, edits: Vec<(ModifiableEdit, ClassifiedEdit)>) {
        self.pending_edits.extend(edits);
    }

    /// Process all pending edits with Git integration
    pub fn process_pending_edits(&mut self) -> Result<Vec<GitOperationResult>, String> {
        if self.pending_edits.is_empty() {
            return Ok(Vec::new());
        }

        let (edits, classifications): (Vec<_>, Vec<_>) = self.pending_edits.drain(..).unzip();
        
        let results = self.git_system.apply_edits_with_git(edits, classifications)?;
        
        self.status_message = format!("Processed {} edits with Git integration", results.len());
        
        Ok(results)
    }
}

/// Interactive Git workflow decision integration
pub fn interactive_git_workflow_decision(
    edits: Vec<ModifiableEdit>,
    classifications: Vec<ClassifiedEdit>,
    repository_path: std::path::PathBuf
) -> Result<bool, String> {
    println!("🔧 Git Integration Available");
    println!("════════════════════════════");
    println!("Would you like to use Git integration for these edits?");
    println!();
    println!("Git integration provides:");
    println!("• Automatic session branching");
    println!("• Intelligent commit strategies based on edit classification");
    println!("• Conflict resolution with cognitive operators");
    println!("• Automated backup points");
    println!("• CI/CD pipeline integration");
    println!();
    print!("Use Git integration? [y/N]: ");
    io::stdout().flush().map_err(|e| format!("Failed to flush stdout: {}", e))?;

    let mut input = String::new();
    io::stdin().read_line(&mut input).map_err(|e| format!("Failed to read input: {}", e))?;

    if input.trim().to_lowercase().starts_with('y') {
        // Launch interactive Git CLI
        let mut git_cli = GitIntegrationCLI::new(repository_path)?;
        git_cli.add_pending_edits(edits.into_iter().zip(classifications).collect());
        
        println!("Launching Git Integration interface...");
        git_cli.start_interactive_session()?;
        
        // Process any pending edits
        let results = git_cli.process_pending_edits()?;
        
        println!("Git integration completed with {} operations", results.len());
        Ok(true)
    } else {
        println!("Proceeding without Git integration");
        Ok(false)
    }
}

// Tests
#[cfg(test)]
mod tests {
    use super::*;
    use tempfile::TempDir;
    use std::process::Command;

    fn create_test_git_repo() -> (TempDir, std::path::PathBuf) {
        let temp_dir = TempDir::new().unwrap();
        let repo_path = temp_dir.path().to_path_buf();
        
        // Initialize git repository
        Command::new("git")
            .arg("init")
            .current_dir(&repo_path)
            .output()
            .unwrap();
            
        // Configure git user for tests
        Command::new("git")
            .args(&["config", "user.name", "SOMA Test"])
            .current_dir(&repo_path)
            .output()
            .unwrap();
            
        Command::new("git")
            .args(&["config", "user.email", "soma@test.com"])
            .current_dir(&repo_path)
            .output()
            .unwrap();

        (temp_dir, repo_path)
    }

    #[test]
    fn test_git_integration_cli_creation() {
        let (_temp_dir, repo_path) = create_test_git_repo();
        
        let git_cli = GitIntegrationCLI::new(repo_path);
        assert!(git_cli.is_ok());
    }

    #[test]
    fn test_view_mode_cycling() {
        let (_temp_dir, repo_path) = create_test_git_repo();
        
        let mut git_cli = GitIntegrationCLI::new(repo_path).unwrap();
        
        // Test panel cycling
        assert_eq!(git_cli.active_panel, GitPanel::SessionStatus);
        git_cli.cycle_panels();
        assert_eq!(git_cli.active_panel, GitPanel::Operations);
        git_cli.cycle_panels();
        assert_eq!(git_cli.active_panel, GitPanel::FileChanges);
    }

    #[test]
    fn test_session_operations() {
        let (_temp_dir, repo_path) = create_test_git_repo();
        
        let mut git_cli = GitIntegrationCLI::new(repo_path).unwrap();
        
        // Test session start
        let start_result = git_cli.handle_start_session();
        assert!(start_result.is_ok());
        
        // Test backup creation
        let backup_result = git_cli.handle_create_backup();
        assert!(backup_result.is_ok());
        
        // Test session end
        let end_result = git_cli.handle_end_session();
        assert!(end_result.is_ok());
    }

    #[test]
    fn test_pending_edits_management() {
        let (_temp_dir, repo_path) = create_test_git_repo();
        
        let git_cli = GitIntegrationCLI::new(repo_path).unwrap();
        
        // Initially no pending edits
        assert_eq!(git_cli.pending_edits.len(), 0);
        
        // Add pending edits would require creating test ModifiableEdit and EditClassificationResult
        // This test demonstrates the structure without requiring full object creation
    }
}