use anyhow::Result;
use std::fs;
use std::path::{Path, PathBuf};
use crate::adapters::templates;
use crate::environment::Environment;
const ADAPTER_DIR: &str = ".gemini";
const CONTEXT_FILE: &str = "GEMINI.md";
pub fn init_project(
project_path: &Path,
project_name: &str,
environment: &Environment,
) -> Result<()> {
templates::copy_to_project("gemini", project_path)?;
let gemini_path = project_path.join(ADAPTER_DIR);
let content = generate_minimal_context(project_name, environment);
fs::write(gemini_path.join(CONTEXT_FILE), content)?;
Ok(())
}
pub fn get_context_file_path(project_path: &Path) -> PathBuf {
project_path.join(ADAPTER_DIR).join(CONTEXT_FILE)
}
fn generate_minimal_context(project_name: &str, environment: &Environment) -> String {
let mut content = String::new();
content.push_str(&format!("# {project_name} - Gemini Context\n\n"));
content.push_str("Project context for Gemini AI.\n");
content.push_str("See root `GEMINI.md` or `README.md` for project instructions.\n\n");
content.push_str("## Environment\n\n");
content.push_str(&format!(
"- **Platform**: {} ({})\n",
environment.os, environment.arch
));
content.push_str(&format!("- **Directory**: {}\n", environment.current_dir));
let tools = ["cargo", "git", "docker", "python"];
let available: Vec<_> = tools
.iter()
.filter_map(|&tool| {
environment
.tools
.get(tool)
.filter(|info| info.available)
.map(|_| tool)
})
.collect();
if !available.is_empty() {
content.push_str(&format!("- **Tools**: {}\n", available.join(", ")));
}
content.push('\n');
content.push_str("## Patterns\n\n");
content.push_str("See files in `layer/` directory for patterns and documentation.\n\n");
content.push_str(&format!(
"---\n*Generated by Patina v{}*\n",
env!("CARGO_PKG_VERSION")
));
content
}