use std::path::Path;
use std::time::Duration;
use anyhow::Result;
use serde_json::json;
use trusty_code::cli_client::StdioRpcClient;
use trusty_code::cli_client::render::render_transcript_human;
use trusty_code::session::TranscriptRecord;
use super::tcode_exe;
pub async fn run(project: &Path, session_id: &str, json_output: bool) -> Result<()> {
let exe = tcode_exe::resolve()?;
let mut client = StdioRpcClient::spawn(&exe, project)?;
let result = client
.call("session.get_transcript", json!({"session_id": session_id}))
.await;
client.shutdown(Duration::from_secs(5)).await?;
let result = result?;
if json_output {
println!(
"{}",
serde_json::to_string_pretty(&result)
.map_err(|e| anyhow::anyhow!("tcode transcript: failed to render JSON: {e}"))?
);
return Ok(());
}
let record: TranscriptRecord = serde_json::from_value(result)
.map_err(|e| anyhow::anyhow!("tcode transcript: malformed daemon response: {e}"))?;
println!("{}", render_transcript_human(&record));
Ok(())
}