From 68a795bacdab1382f95be0ca3884ec1c16f7af6f Mon Sep 17 00:00:00 2001 From: Elijah Voigt Date: Sun, 29 Mar 2026 22:15:33 -0700 Subject: [PATCH] feat(sessions): add Sub-agents count column to sessions list Call discover_agents_for_session for each session and show the real count in a new Sub-agents column. JSON and XML output updated to include the subagents field. Closes claudbg-xpzp Co-Authored-By: Claude Sonnet 4.6 --- ...ist-should-show-sub-agent-run-count-per.md | 8 +++-- src/commands/sessions.rs | 35 ++++++++++++++----- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/.beans/claudbg-xpzp--sessions-list-should-show-sub-agent-run-count-per.md b/.beans/claudbg-xpzp--sessions-list-should-show-sub-agent-run-count-per.md index af39bdf..9e5620d 100644 --- a/.beans/claudbg-xpzp--sessions-list-should-show-sub-agent-run-count-per.md +++ b/.beans/claudbg-xpzp--sessions-list-should-show-sub-agent-run-count-per.md @@ -1,11 +1,11 @@ --- # claudbg-xpzp title: '`sessions list` should show sub-agent run count per session' -status: todo +status: completed type: bug priority: normal created_at: 2026-03-30T04:40:53Z -updated_at: 2026-03-30T04:43:26Z +updated_at: 2026-03-30T05:15:27Z parent: claudbg-tci9 blocked_by: - claudbg-33n0 @@ -40,3 +40,7 @@ The existing `discover_agents_for_session(session_file)` function currently look - `src/commands/sessions.rs` — `list()` function - `src/parser/discovery.rs` — `discover_agents_for_session` + +## Summary of Changes + +In sessions.rs list(): built a session_id->file_path map from discovered sessions, then for each DB row called discover_agents_for_session to get the real count. Added 'Sub-agents' column to table headers and row data. Updated JSON and XML output to include the subagents field. diff --git a/src/commands/sessions.rs b/src/commands/sessions.rs index 55038de..f2d89ed 100644 --- a/src/commands/sessions.rs +++ b/src/commands/sessions.rs @@ -161,6 +161,12 @@ pub async fn list(opts: &crate::cli::GlobalOpts) -> Result<()> { crate::db::sync::ensure_synced(&db, session_ref).await?; } + // Build a map from session_id -> file_path for agent discovery. + let session_file_map: std::collections::HashMap = sessions + .into_iter() + .map(|sr| (sr.session_id, sr.file_path)) + .collect(); + // Query DB for display. let conn = db .connect() @@ -206,37 +212,50 @@ pub async fn list(opts: &crate::cli::GlobalOpts) -> Result<()> { project_path }; + // Count sub-agents for this session. + let agent_count = if let Some(file_path) = session_file_map.get(&session_id) { + crate::parser::discovery::discover_agents_for_session(file_path) + .unwrap_or_default() + .len() + } else { + 0 + }; + rows.push(vec![ display_id, last_msg_at, display_path, model, message_count.to_string(), + agent_count.to_string(), ]); } let output = match opts.output { crate::cli::OutputFormat::Table => { - crate::output::render_table(&["ID", "Date", "Project", "Model", "Messages"], &rows)? + crate::output::render_table( + &["ID", "Date", "Project", "Model", "Messages", "Sub-agents"], + &rows, + )? } crate::cli::OutputFormat::Json => { let objects: Vec = rows .iter() .map(|r| { serde_json::json!({ - "id": r[0], - "date": r[1], - "project": r[2], - "model": r[3], - "messages": r[4], - "subagents": 0, + "id": r[0], + "date": r[1], + "project": r[2], + "model": r[3], + "messages": r[4], + "subagents": r[5], }) }) .collect(); crate::output::render_json(&objects)? } crate::cli::OutputFormat::Xml => crate::output::render_xml_rows( - &["session_id", "date", "project", "model", "messages"], + &["session_id", "date", "project", "model", "messages", "subagents"], &rows, )?, };