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

Function session_show

atomic-cli/src/commands/rpc.rs:2927–3007  ·  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

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

Callers 1

runMethod · 0.85

Calls 10

render_recent_sessionsFunction · 0.85
render_session_detailFunction · 0.85
is_noneMethod · 0.80
openFunction · 0.50
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