vibe-action 0.1.4

Command router — execute shell commands and LLM prompts via simple YAML actions.
//! Refresh command handler.
//! Manages refreshing actions cache and resetting context.

use crate::{output::output::OutputKind, print_template, print_text, utils};

/// Execute the `refresh` command.
pub async fn execute() {
    let cache_dir = utils::path::cache_dir();
    let actions_dir = utils::path::actions_dir();

    // Clean actions cache
    if let Err(e) = vibe_fs::clean(&actions_dir, Some(&cache_dir)) {
        print_template!(
            OutputKind::Error,
            "Failed to clean actions cache: {error}",
            "error" => e.to_string()
        );
    } else {
        print_text!(OutputKind::Info, "Actions cache cleaned");
    }

    // Clean temp files created by load modifier
    match std::fs::read_dir(std::env::temp_dir()) {
        Ok(entries) => {
            let mut count = 0;
            for entry in entries.flatten() {
                let name = entry.file_name();
                let name_str = name.to_string_lossy();
                if name_str.starts_with("vibe-") {
                    if std::fs::remove_file(entry.path()).is_ok() {
                        count += 1;
                    }
                }
            }
            if count > 0 {
                print_template!(
                    OutputKind::Info,
                    "Temp files cleaned: {count}",
                    "count" => count
                );
            }
        }
        Err(_) => {}
    }
}