use std::path::Path;
use anyhow::{Context, Result};
use serde_json::json;
use trusty_code::cli_client::render::render_session_table;
use trusty_code::session::Session;
use super::daemon_client;
pub async fn list(project: &Path) -> Result<()> {
let client = daemon_client::connect(project).await?;
let result = client.call("session.list", json!({})).await?;
let sessions: Vec<Session> = serde_json::from_value(
result
.get("sessions")
.cloned()
.context("tcode session list: daemon response carried no `sessions` field")?,
)
.map_err(|e| anyhow::anyhow!("tcode session list: malformed daemon response: {e}"))?;
println!("{}", render_session_table(&sessions));
Ok(())
}
pub async fn status(project: &Path, session_id: &str) -> Result<()> {
let client = daemon_client::connect(project).await?;
let result = client
.call("session.status", json!({"session_id": session_id}))
.await?;
let session: Session = serde_json::from_value(result)
.map_err(|e| anyhow::anyhow!("tcode session status: malformed daemon response: {e}"))?;
println!(
"{} {} agent={} task={}",
session.id,
session.status.as_str(),
session.agent.as_deref().unwrap_or("-"),
session.task
);
Ok(())
}