use crate::core::db::DbManager;
use crate::core::{db_path, ensure_initialized};
use anyhow::Result;
use colored::Colorize;
pub async fn execute() -> Result<()> {
let project_root = ensure_initialized()?;
let db_file = db_path(&project_root);
let db = DbManager::open(&db_file)?;
let sessions = db.get_sessions()?;
if sessions.is_empty() {
println!("{}", "No sessions captured yet.".yellow());
println!("Run 'agentlog run <agent>' to start capturing AI sessions.");
return Ok(());
}
println!("{}", "Captured Sessions".bold().underline());
println!();
for summary in sessions {
let short_id = &summary.session_id[..8];
let duration_ms = summary
.end_time
.signed_duration_since(summary.start_time)
.num_milliseconds() as u64;
let duration_secs = duration_ms as f64 / 1000.0;
let status = if summary.exit_code == 0 {
"✓".green()
} else {
"✗".red()
};
let agent = summary.agent_name.as_deref().unwrap_or("unknown");
println!("{} Session {}", status, short_id.cyan());
println!(" Agent: {}", agent);
println!(
" Duration: {:.2}s | Files: {} | Exit: {}",
duration_secs, summary.files_changed, summary.exit_code
);
println!(" Run: agentlog replay {}", short_id);
println!();
}
Ok(())
}