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

Function render_recent_sessions

atomic-cli/src/commands/session.rs:161–230  ·  view source on GitHub ↗

The listing render, over the gathered data — the repository path and the routed path (ListSessions' ledger bundle + intent counts) share it.

(
    ledgers: Vec<(SessionRecord, Vec<SessionTurn>)>,
    intent_counts: Vec<usize>,
    json: bool,
)

Source from the content-addressed store, hash-verified

159/// The listing render, over the gathered data — the repository path and the
160/// routed path (ListSessions' ledger bundle + intent counts) share it.
161pub(crate) fn render_recent_sessions(
162 ledgers: Vec<(SessionRecord, Vec<SessionTurn>)>,
163 intent_counts: Vec<usize>,
164 json: bool,
165) -> CliResult<()> {
166 if json {
167 println!(
168 "{}",
169 serde_json::to_string_pretty(&ledgers).map_err(|e| {
170 CliError::Internal(anyhow::anyhow!("failed to encode session list: {}", e))
171 })?
172 );
173 return Ok(());
174 }
175 if ledgers.is_empty() {
176 println!("No sessions recorded.");
177 return Ok(());
178 }
179
180 // Compute column width for SESSION: at least the header width, but wide enough
181 // to show full session IDs so they can be copied for `atomic session show <id>`.
182 let ses_width = ledgers
183 .iter()
184 .map(|(r, _)| r.session_id.len())
185 .max()
186 .unwrap_or(0)
187 .max("SESSION".len());
188
189 println!("Recent sessions ({}):", ledgers.len());
190 println!(
191 " {:<sw$} {:<22} {:<8} {:>5} {:>7} LAST ACTIVITY",
192 "SESSION",
193 "VIEW",
194 "STATUS",
195 "TURNS",
196 "INTENTS",
197 sw = ses_width,
198 );
199 for ((record, turns), intent_count) in ledgers.into_iter().zip(intent_counts) {
200 let status = record.status.label();
201 let activity = turns
202 .last()
203 .map(|turn| turn.timestamp)
204 .or(record.ended_at)
205 .unwrap_or(record.started_at);
206 let activity = record
207 .activity_datetime(&turns)
208 .map(|time| time.format("%Y-%m-%d %H:%M").to_string())
209 .unwrap_or_else(|| activity.to_string());
210 let intents_display = if intent_count > 0 {
211 intent_count.to_string()
212 } else {
213 "—".to_string()
214 };
215 println!(
216 " {:<sw$} {:<22} {:<8} {:>5} {:>7} {}",
217 record.session_id,
218 truncate_column(record.view_name.as_deref().unwrap_or("—"), 22),

Callers 2

session_showFunction · 0.85
show_recent_sessionsFunction · 0.85

Calls 8

lastMethod · 0.80
activity_datetimeMethod · 0.80
is_emptyMethod · 0.45
iterMethod · 0.45
lenMethod · 0.45
into_iterMethod · 0.45
labelMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected