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
//! Git worktree management for parallel MMM sessions
//!
//! This module provides sophisticated git worktree management capabilities that enable
//! multiple MMM sessions to run concurrently without interfering with each other.
//! Each session runs in its own isolated git worktree with its own branch.
//!
//! # Key Features
//!
//! - **Parallel Sessions**: Multiple improvement sessions can run simultaneously
//! - **Isolation**: Each session has its own working directory and branch
//! - **State Management**: Persistent session state with recovery support
//! - **Automatic Cleanup**: Manages worktree lifecycle and cleanup
//! - **Conflict Resolution**: Smart merging and conflict detection
//!
//! # Architecture
//!
//! The worktree system consists of:
//! - [`WorktreeManager`] - High-level worktree operations and lifecycle management
//! - [`WorktreeSession`] - Represents an active worktree session
//! - [`WorktreeState`] - Persistent state tracking for sessions
//! - [`WorktreeStatus`] - Current status of a worktree session
//!
//! # Examples
//!
//! ## Creating a Worktree Session
//!
//! ```rust
//! use prodigy::worktree::WorktreeManager;
//! use prodigy::subprocess::SubprocessManager;
//! use std::path::PathBuf;
//!
//! # async fn example() -> anyhow::Result<()> {
//! let subprocess = SubprocessManager::production();
//! let manager = WorktreeManager::new(PathBuf::from("/repo"), subprocess)?;
//!
//! let session = manager.create_session().await?;
//! println!("Created session: {}", session.name);
//! # Ok(())
//! # }
//! ```
//!
//! ## Managing Session Lifecycle
//!
//! ```rust
//! # use prodigy::worktree::WorktreeManager;
//! # use prodigy::subprocess::SubprocessManager;
//! # use std::path::PathBuf;
//! # async fn example() -> anyhow::Result<()> {
//! # let subprocess = SubprocessManager::production();
//! # let manager = WorktreeManager::new(PathBuf::from("/repo"), subprocess)?;
//! // List active sessions
//! let sessions = manager.list_sessions().await?;
//!
//! // Merge completed session
//! manager.merge_session("feature-improvement").await?;
//!
//! // Cleanup session
//! manager.cleanup_session("feature-improvement", false).await?;
//! # Ok(())
//! # }
//! ```
use ;
use PathBuf;
pub use ;
pub use ;
pub use ;
pub use ;
/// Represents an active git worktree session for MMM operations
///
/// A `WorktreeSession` encapsulates all the information needed to manage
/// an isolated MMM improvement session running in its own git worktree.
/// Each session has its own branch and working directory, allowing multiple
/// sessions to run concurrently without conflicts.
///
/// # Fields
///
/// - `name`: Unique identifier for the session
/// - `branch`: Git branch name for this session
/// - `path`: File system path to the worktree directory
/// - `created_at`: Timestamp when the session was created
///
/// # Examples
///
/// ```rust
/// use prodigy::worktree::WorktreeSession;
/// use std::path::PathBuf;
///
/// let session = WorktreeSession::new(
/// "performance-improvements".to_string(),
/// "prodigy/performance-123".to_string(),
/// PathBuf::from("/tmp/prodigy-worktrees/performance-improvements")
/// );
///
/// println!("Session {} created at {}", session.name, session.created_at);
/// ```