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

Method run

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 15

agent_explainFunction · 0.85
find_repository_rootFunction · 0.85
openFunction · 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

Tested by

no test coverage detected