(&self)
| 114 | |
| 115 | impl Command for Explain { |
| 116 | fn run(&self) -> CliResult<()> { |
| 117 | let repo_root = find_repository_root()?; |
| 118 | |
| 119 | // Load the session to get the view name |
| 120 | let session_store = |
| 121 | SessionStore::for_repo(&repo_root).map_err(|e| CliError::InvalidRepository { |
| 122 | reason: format!("Failed to open session store: {}", e), |
| 123 | })?; |
| 124 | |
| 125 | let session = session_store |
| 126 | .load(&self.session_id) |
| 127 | .map_err(|e| CliError::Internal(anyhow::anyhow!("Failed to load session: {}", e)))? |
| 128 | .ok_or_else(|| CliError::InvalidArgument { |
| 129 | message: format!( |
| 130 | "Session '{}' not found. Use 'atomic agent status' to see available sessions.", |
| 131 | self.session_id |
| 132 | ), |
| 133 | })?; |
| 134 | |
| 135 | // Open the repository |
| 136 | let repo = Repository::open(&repo_root)?; |
| 137 | |
| 138 | // Get the changes on the agent view |
| 139 | let history_options = HistoryOptions::with_headers().view(&session.view_name); |
| 140 | |
| 141 | let entries = repo.log(history_options).map_err(|e| match e { |
| 142 | atomic_repository::RepositoryError::ViewNotFound { name } => { |
| 143 | CliError::ViewNotFound { name } |
| 144 | } |
| 145 | other => CliError::Repository(other), |
| 146 | })?; |
| 147 | |
| 148 | if entries.is_empty() { |
| 149 | println!( |
| 150 | "Session '{}' has no recorded turns on view '{}'.", |
| 151 | self.session_id, session.view_name, |
| 152 | ); |
| 153 | return Ok(()); |
| 154 | } |
| 155 | |
| 156 | // Determine which turns to explain |
| 157 | let turns_to_explain: Vec<usize> = if self.all { |
| 158 | (0..entries.len()).collect() |
| 159 | } else if let Some(turn_num) = self.turn { |
| 160 | let idx = |
| 161 | (turn_num as usize) |
| 162 | .checked_sub(1) |
| 163 | .ok_or_else(|| CliError::InvalidArgument { |
| 164 | message: "Turn number must be >= 1".to_string(), |
| 165 | })?; |
| 166 | if idx >= entries.len() { |
| 167 | return Err(CliError::InvalidArgument { |
| 168 | message: format!( |
| 169 | "Turn {} not found. Session has {} turn{}.", |
| 170 | turn_num, |
| 171 | entries.len(), |
| 172 | if entries.len() == 1 { "" } else { "s" } |
| 173 | ), |
nothing calls this directly
no test coverage detected