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

Function session_show

atomic-cli/src/commands/rpc.rs:2926–3006  ·  view source on GitHub ↗

`atomic session show` over the session RPCs. The listing rides ListSessions (with its ledgers bundle + vault-derived intent counts); the detail rides GetSession (ledger bundle, turn→intent resolution, and the session manifest data). Both renders are the SAME functions the local path uses — the wire carries the domain data.

(args: &super::session::SessionShow)

Source from the content-addressed store, hash-verified

2924/// and the session manifest data). Both renders are the SAME functions
2925/// the local path uses — the wire carries the domain data.
2926pub fn session_show(args: &super::session::SessionShow) -> CliResult<bool> {
2927 use atomic_core::change::session::{SessionRecord, SessionTurn};
2928
2929 let Some(session) = Service::open()? else {
2930 return Ok(false);
2931 };
2932 let target = args.session_id.clone();
2933 if target.is_none() {
2934 // The recent-session listing.
2935 let response = session.list_sessions(pb::ListSessionsRequest {
2936 repository: Some(session.reference.clone()),
2937 limit: args.limit as u32,
2938 })?;
2939 let Some(bundle) = response.ledgers_bundle else {
2940 // The same-build service always carries the bundle; a missing
2941 // one is a protocol violation, not a fallback path.
2942 return Err(CliError::Internal(anyhow::anyhow!(
2943 "the service returned no ledgers bundle"
2944 )));
2945 };
2946 if args.json {
2947 // The bundle IS the domain serialization of the ledgers —
2948 // print it verbatim (byte-parity with the local JSON).
2949 print!("{}", String::from_utf8_lossy(&bundle.payload));
2950 return Ok(true);
2951 }
2952 let ledgers: Vec<(SessionRecord, Vec<SessionTurn>)> =
2953 serde_json::from_slice(&bundle.payload)
2954 .map_err(|error| CliError::Internal(anyhow::anyhow!("ledgers bundle: {error}")))?;
2955 let intent_counts = response
2956 .intent_counts
2957 .into_iter()
2958 .map(|count| count as usize)
2959 .collect();
2960 super::session::render_recent_sessions(ledgers, intent_counts, false)?;
2961 return Ok(true);
2962 }
2963 let session_id = target.expect("checked");
2964 let response = session.get_session(pb::GetSessionRequest {
2965 repository: Some(session.reference.clone()),
2966 session_id,
2967 from_turn: None,
2968 to_turn: None,
2969 })?;
2970 let Some(bundle) = response.ledger_bundle else {
2971 return Err(CliError::Internal(anyhow::anyhow!(
2972 "the service returned no ledger bundle"
2973 )));
2974 };
2975 let (record, turns): (SessionRecord, Vec<SessionTurn>) =
2976 serde_json::from_slice(&bundle.payload)
2977 .map_err(|error| CliError::Internal(anyhow::anyhow!("ledger bundle: {error}")))?;
2978 if args.json {
2979 // Byte-parity: the bundle is the domain serialization of the pair.
2980 print!("{}", String::from_utf8_lossy(&bundle.payload));
2981 return Ok(true);
2982 }
2983 let turn_intents = response

Callers 1

runMethod · 0.85

Calls 10

openFunction · 0.85
render_recent_sessionsFunction · 0.85
render_session_detailFunction · 0.85
is_noneMethod · 0.80
cloneMethod · 0.45
list_sessionsMethod · 0.45
collectMethod · 0.45
into_iterMethod · 0.45
get_sessionMethod · 0.45
okMethod · 0.45

Tested by

no test coverage detected