MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / run

Method run

atomic-cli/src/commands/agent/explain.rs:116–348  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

114
115impl 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 ),

Callers

nothing calls this directly

Calls 15

find_repository_rootFunction · 0.85
RepositoryClass · 0.85
print_errorFunction · 0.85
get_condensed_textFunction · 0.85
print_warningFunction · 0.85
extract_unhashedFunction · 0.85
anchor_to_graphFunction · 0.85
print_reasoningFunction · 0.85
save_reasoning_to_changeFunction · 0.85
print_successFunction · 0.85
context_file_for_agentFunction · 0.85

Tested by

no test coverage detected