use std::path::Path;
use std::time::Duration;
use anyhow::Result;
use serde_json::json;
use trusty_code::cli_client::StdioRpcClient;
use trusty_code::session::Session;
use super::tcode_exe;
pub async fn run(project: &Path, session_id: &str) -> Result<()> {
let exe = tcode_exe::resolve()?;
let mut client = StdioRpcClient::spawn(&exe, project)?;
let result = client
.call("session.cancel", json!({"session_id": session_id}))
.await;
client.shutdown(Duration::from_secs(5)).await?;
let result = result?;
let session: Session = serde_json::from_value(result)
.map_err(|e| anyhow::anyhow!("tcode cancel: malformed daemon response: {e}"))?;
println!("{} {}", session.id, session.status.as_str());
Ok(())
}