Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,13 @@ enum Commands {
#[arg(long)]
cache_dir: Option<String>,
},
/// 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<String>,
},
/// Remove stria from agent configurations
Remove {
Expand Down Expand Up @@ -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 } => {
Expand Down
42 changes: 42 additions & 0 deletions src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Loading