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