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

Function format_node_detail

atomic-cli/src/commands/change/command.rs:415–444  ·  view source on GitHub ↗

Extract a human-readable one-liner from a provenance node's detail JSON. Returns `None` if the detail is empty or has no interesting fields.

(detail: &str)

Source from the content-addressed store, hash-verified

413///
414/// Returns `None` if the detail is empty or has no interesting fields.
415pub(super) fn format_node_detail(detail: &str) -> Option<String> {
416 let v: serde_json::Value = serde_json::from_str(detail).ok()?;
417 let obj = v.as_object()?;
418
419 // Command (bash/execution nodes)
420 if let Some(cmd) = obj.get("command").and_then(|v| v.as_str()) {
421 return Some(format!("$ {}", truncate_bytes(cmd, 120)));
422 }
423
424 // File path (read/write/edit nodes)
425 if let Some(file) = obj
426 .get("file")
427 .or_else(|| obj.get("file_path"))
428 .or_else(|| obj.get("target"))
429 .and_then(|v| v.as_str())
430 {
431 let op = obj.get("operation").and_then(|v| v.as_str()).unwrap_or("");
432 if op.is_empty() {
433 return Some(file.to_string());
434 }
435 return Some(format!("{}: {}", op, file));
436 }
437
438 // Output summary (fallback for nodes with only output)
439 if let Some(summary) = obj.get("output_summary").and_then(|v| v.as_str()) {
440 return Some(truncate_bytes(summary, 120));
441 }
442
443 None
444}
445
446impl Default for ChangeCmd {
447 fn default() -> Self {

Callers 1

ledgerFunction · 0.85

Calls 5

truncate_bytesFunction · 0.85
getMethod · 0.65
okMethod · 0.45
as_strMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected