use super::DaemonClient;
use super::types::ConfigRecommendation;
impl DaemonClient {
pub async fn analyze_config(&self, project: &str) -> anyhow::Result<Vec<ConfigRecommendation>> {
let url = "/claude-config".to_string();
let body: serde_json::Value = self
.get(&url)
.query(&[("project", project)])
.send()
.await?
.json()
.await?;
let recs = body["recommendations"]
.as_array()
.cloned()
.unwrap_or_default();
Ok(recs
.iter()
.map(|r| ConfigRecommendation {
id: r
.get("id")
.and_then(|v| v.as_str())
.unwrap_or("")
.to_string(),
message: r
.get("message")
.and_then(|v| v.as_str())
.or_else(|| r.as_str())
.unwrap_or("?")
.to_string(),
})
.collect())
}
pub async fn apply_recommendation(
&self,
project: &str,
recommendation_id: &str,
) -> anyhow::Result<String> {
let url = "/claude-config/apply".to_string();
let body: serde_json::Value = self
.post(&url)
.json(&serde_json::json!({
"project": project,
"recommendation_id": recommendation_id,
}))
.send()
.await?
.error_for_status()?
.json()
.await?;
Ok(body
.get("checkpoint_id")
.and_then(|v| v.as_str())
.unwrap_or("")
.to_string())
}
pub async fn list_checkpoints(&self, project: &str) -> anyhow::Result<Vec<serde_json::Value>> {
let url = "/claude-config/checkpoints".to_string();
let body: serde_json::Value = self
.get(&url)
.query(&[("project", project)])
.send()
.await?
.json()
.await?;
Ok(body["checkpoints"].as_array().cloned().unwrap_or_default())
}
pub async fn deploy_profile(
&self,
project: &str,
profile_name: &str,
) -> anyhow::Result<String> {
let url = "/claude-config/deploy".to_string();
let body: serde_json::Value = self
.post(&url)
.json(&serde_json::json!({
"project": project,
"profile_name": profile_name,
}))
.send()
.await?
.error_for_status()?
.json()
.await?;
Ok(body
.get("checkpoint_id")
.and_then(|v| v.as_str())
.unwrap_or("")
.to_string())
}
}