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

Method to_json

atomic-cli/src/commands/agent/status.rs:158–258  ·  view source on GitHub ↗

Build the JSON view of the same state the human output describes. Every agent in the registry appears, including ones that are neither detected nor installed: a caller deciding whether to install needs to distinguish "this agent is unknown to Atomic" from "known, and not set up", and an omitted entry cannot say which.

(&self, repo_root: &std::path::Path, registry: &AgentRegistry)

Source from the content-addressed store, hash-verified

156 /// distinguish "this agent is unknown to Atomic" from "known, and not set
157 /// up", and an omitted entry cannot say which.
158 fn to_json(&self, repo_root: &std::path::Path, registry: &AgentRegistry) -> StatusJson {
159 let installed = registry.installed(repo_root);
160 let detected = registry.detect(repo_root);
161
162 let mut agents: Vec<AgentEntry> = registry
163 .list()
164 .into_iter()
165 .map(|name| AgentEntry {
166 display_name: registry
167 .get(name)
168 .map_or_else(|| name.to_string(), |a| a.display_name().to_string()),
169 detected: detected.contains(&name),
170 hooks_installed: installed.contains(&name),
171 name: name.to_string(),
172 })
173 .collect();
174 agents.sort_by(|a, b| a.name.cmp(&b.name));
175
176 let (sessions, sessions_error) =
177 match SessionStore::for_repo(repo_root).and_then(|store| store.list()) {
178 Ok(list) => (list, None),
179 Err(e) => (Vec::new(), Some(e.to_string())),
180 };
181
182 let totals = Totals {
183 sessions: sessions.len(),
184 turns: sessions.iter().map(|s| s.turn_count).sum(),
185 files_touched: sessions.iter().map(|s| s.files_touched.len()).sum(),
186 };
187
188 let (health, hook_health_error) = match super::hook_log::read(repo_root) {
189 Ok(health) => (health, None),
190 Err(error) => (
191 super::hook_log::pending_health(repo_root),
192 Some(error.to_string()),
193 ),
194 };
195 let hook_sessions = health
196 .as_ref()
197 .map(|health| health.sessions.values().cloned().collect())
198 .unwrap_or_default();
199 let hook_health = health
200 .as_ref()
201 .map(super::health::summarize)
202 .filter(|v| !v.is_empty());
203 let hook_errors = super::health::read_errors(repo_root);
204
205 // An agent whose hooks are installed but which has never recorded a
206 // successful dispatch is silently losing every turn. Report it by
207 // name so a caller does not have to correlate the two lists.
208 //
209 // Only when observations exist at all: with no events there is no
210 // evidence either way, and calling a freshly-upgraded repository
211 // "never recorded" would be a false alarm on every machine.
212 let silent_agents: Vec<String> = if health.is_none() || hook_health_error.is_some() {
213 Vec::new()
214 } else {
215 installed

Calls 15

pending_healthFunction · 0.85
read_errorsFunction · 0.85
installedMethod · 0.80
as_refMethod · 0.80
is_noneMethod · 0.80
readFunction · 0.70
getMethod · 0.65
detectMethod · 0.45
collectMethod · 0.45
into_iterMethod · 0.45
listMethod · 0.45