use ggen_ai::{AiConfig, GenAiClient, LlmClient};
use ggen_utils::{bail, error::Error, error::Result};
pub async fn analyze_code(code: &str) -> Result<String> {
if code.is_empty() {
bail!("Code cannot be empty");
}
let config = AiConfig::from_env().unwrap_or_else(|_| AiConfig::new()).llm;
let client = GenAiClient::new(config)
.map_err(|e| Error::new(&format!("Failed to create LLM client: {e}")))?;
let prompt = format!(
"You are a senior Rust engineer. Analyze the following code and provide concise findings (risks, improvements, tests).\n\nCode:\n```rust\n{}\n```",
code
);
let resp = client
.complete(&prompt)
.await
.map_err(|e| Error::new(&format!("LLM analysis failed: {e}")))?;
Ok(resp.content)
}
pub async fn analyze_project(path: &std::path::Path) -> Result<String> {
if !path.exists() {
bail!("Path does not exist: {}", path.display());
}
let config = AiConfig::from_env().unwrap_or_else(|_| AiConfig::new()).llm;
let client = GenAiClient::new(config)
.map_err(|e| Error::new(&format!("Failed to create LLM client: {e}")))?;
let prompt = format!(
"You are a senior Rust engineer. Provide a quick review and risk assessment for the project at path: {}. Focus on likely hotspots to inspect (testing gaps, performance, security). Respond succinctly.",
path.display()
);
let resp = client
.complete(&prompt)
.await
.map_err(|e| Error::new(&format!("LLM project analysis failed: {e}")))?;
Ok(resp.content)
}