Skip to main content

seher/kiro/
client.rs

1use super::types::KiroUsageInfo;
2
3pub struct KiroClient;
4
5impl KiroClient {
6    /// # Errors
7    ///
8    /// Returns an error if the kiro-cli subprocess fails or its output cannot be parsed.
9    pub async fn fetch_usage() -> Result<KiroUsageInfo, Box<dyn std::error::Error>> {
10        let output = tokio::task::spawn_blocking(|| {
11            let output = std::process::Command::new("kiro-cli")
12                .args(["chat", "--no-interactive", "/usage"])
13                .output()?;
14            if !output.status.success() {
15                let stderr = String::from_utf8_lossy(&output.stderr);
16                return Err::<String, std::io::Error>(std::io::Error::other(format!(
17                    "kiro-cli exited with {}: {stderr}",
18                    output.status
19                )));
20            }
21            String::from_utf8(output.stdout)
22                .map_err(|e| std::io::Error::other(format!("invalid UTF-8 in kiro output: {e}")))
23        })
24        .await??;
25
26        KiroUsageInfo::parse(&output)
27    }
28}