diff --git a/src/main.rs b/src/main.rs index b9b430a..7bc86f9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -51,10 +51,13 @@ enum Commands { #[arg(long)] cache_dir: Option, }, - /// Detect agents and add stria MCP server entry + /// Detect agents and add stria MCP server entry; optionally add .stria/ to .gitignore Setup { #[arg(long, default_value = "false")] yes: bool, + /// Repo root for .gitignore update. Skips .gitignore if not set. + #[arg(long)] + repo: Option, }, /// Remove stria from agent configurations Remove { @@ -143,7 +146,10 @@ fn main() { eprintln!("Watch error: {}", e); } } - Commands::Setup { yes } => { + Commands::Setup { yes, repo } => { + if let Some(r) = &repo { + setup::add_to_gitignore(r); + } setup::run_setup(yes); } Commands::Remove { yes } => { diff --git a/src/setup.rs b/src/setup.rs index 9a8bead..91561b7 100644 --- a/src/setup.rs +++ b/src/setup.rs @@ -131,6 +131,48 @@ pub fn find_configured_agents() -> Vec<(&'static str, String)> { found } +/// Add .stria/ to .gitignore for a repo. +/// Returns true if .gitignore was modified. +pub fn add_to_gitignore(repo_path: &str) -> bool { + let gitignore_path = std::path::Path::new(repo_path).join(".gitignore"); + let stria_dir = ".stria"; + + // Read existing or start fresh + let mut content = if gitignore_path.exists() { + match std::fs::read_to_string(&gitignore_path) { + Ok(c) => c, + Err(_) => return false, + } + } else { + String::new() + }; + + // Check if .stria/ is already listed + for line in content.lines() { + if line.trim() == stria_dir { + return false; // already present + } + } + + // Append + if !content.is_empty() && !content.ends_with('\n') { + content.push('\n'); + } + content.push_str(stria_dir); + content.push('\n'); + + match std::fs::write(&gitignore_path, content) { + Ok(_) => { + eprintln!(" Added {} to .gitignore", stria_dir); + true + } + Err(e) => { + eprintln!(" Warning: could not write .gitignore: {}", e); + false + } + } +} + pub fn run_setup(yes: bool) { let found = detect_agents_without_stria(); if found.is_empty() {