use crate::agent::cmd::{cmd_stdout, log};
use crate::agent::launch::log_resolved_agent_launch;
use crate::agent::process::emit_event;
use crate::agent::run::run_agent_with_env;
use crate::agent::tracker::build_generate_aiignore_prompt;
use crate::agent::types::{AgentEvent, Config};
use std::path::Path;
pub fn run_generate_aiignore(cfg: &Config) {
log("Generating .aiignore to optimize the AI snapshot token budget...");
let file_listing = cmd_stdout("git", &["-C", &cfg.root, "ls-files"]).unwrap_or_default();
let existing =
std::fs::read_to_string(Path::new(&cfg.root).join(".aiignore")).unwrap_or_default();
let prompt =
build_generate_aiignore_prompt(&cfg.project_name, &cfg.root, &file_listing, &existing);
if cfg.dry_run {
log_resolved_agent_launch(cfg, &[]);
log("[dry-run] Would ask the agent to explore the project and write .aiignore");
emit_event(AgentEvent::Done);
return;
}
run_agent_with_env(cfg, &prompt, &[]);
emit_event(AgentEvent::Done);
}