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
use crateSnapshotManager;
use crate;
use ;
use ;
/// State manager for MCP refactoring sessions with persistence and recovery.
///
/// This component manages the lifecycle of refactoring sessions in the MCP server,
/// providing state persistence, snapshot management, and session isolation.
/// Critical for maintaining session consistency and preventing state drift across
/// MCP protocol interactions.
///
/// # Features
///
/// - **Session Management**: Start, stop, and track refactoring sessions
/// - **State Persistence**: Automatic snapshots for crash recovery
/// - **Session Isolation**: Each session has unique ID and isolated state
/// - **State Machine Control**: Advance through refactoring phases
/// - **Error Recovery**: Graceful handling of state transition failures
///
/// # Session Lifecycle
///
/// ```text
/// New StateManager → start_session() → Active Session → advance() → Complete
/// ↓ ↑
/// └─── stop_session() ──┘
/// ```ignore
///
/// # State Machine Phases
///
/// 1. **Scan**: Discover files and build initial analysis
/// 2. **Analyze**: Compute complexity and quality metrics
/// 3. **Plan**: Generate refactoring operations
/// 4. **Refactor**: Apply transformations
/// 5. **Complete**: Finalize and cleanup
///
/// # Examples
///
/// ```rust,no_run
/// use pmat::mcp_server::state_manager::StateManager;
/// use pmat::models::refactor::RefactorConfig;
/// use std::path::PathBuf;
///
/// // Create state manager
/// let mut manager = StateManager::new();
///
/// // Start refactoring session
/// let targets = vec![PathBuf::from("/tmp/test.rs")];
/// let config = RefactorConfig::default();
/// let result = manager.start_session(targets, config);
/// assert!(result.is_ok());
///
/// // Get session info
/// let session_id = manager.get_session_id();
/// assert!(session_id.starts_with("refactor-session-"));
///
/// // Session state is available
/// let state = manager.get_state();
/// assert!(state.is_ok());
///
/// // Stop session
/// let stop_result = manager.stop_session();
/// assert!(stop_result.is_ok());
/// ```
// Core implementation: constructors, session lifecycle, snapshots, ID generation
include!;
// Tests: property tests and coverage tests
include!;