bot-forge 1.0.2

Rust CLI for installing agent skills and developer tools from configurable forms.
Documentation
//! Platform-aware locations used for configuration and managed state.

use std::env;
use std::path::PathBuf;

use crate::constants::{CONFIG_FILE, REGISTRY_FILE};
use crate::util::home_dir;

/// Return the application data directory, honoring `BOT_FORGE_HOME` and platform conventions.
pub(crate) fn app_home() -> PathBuf {
    if let Ok(path) = env::var("BOT_FORGE_HOME") {
        return PathBuf::from(path);
    }
    if cfg!(windows)
        && let Ok(path) = env::var("LOCALAPPDATA")
    {
        return PathBuf::from(path).join("bot-forge");
    }
    if cfg!(target_os = "macos") {
        return home_dir()
            .join("Library")
            .join("Application Support")
            .join("bot-forge");
    }
    if let Ok(path) = env::var("XDG_DATA_HOME") {
        return PathBuf::from(path).join("bot-forge");
    }
    home_dir().join(".local").join("share").join("bot-forge")
}

/// Return the configuration directory, honoring `BOT_FORGE_CONFIG_DIR` and platform conventions.
pub(crate) fn config_dir() -> PathBuf {
    if let Ok(path) = env::var("BOT_FORGE_CONFIG_DIR") {
        return PathBuf::from(path);
    }
    if cfg!(windows)
        && let Ok(path) = env::var("APPDATA")
    {
        return PathBuf::from(path).join("bot-forge");
    }
    if cfg!(target_os = "macos") {
        return home_dir()
            .join("Library")
            .join("Application Support")
            .join("bot-forge")
            .join("config");
    }
    if let Ok(path) = env::var("XDG_CONFIG_HOME") {
        return PathBuf::from(path).join("bot-forge");
    }
    home_dir().join(".config").join("bot-forge")
}

/// Return the repository configuration template shipped with this build.
pub(crate) fn manifest_config_path() -> PathBuf {
    PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(CONFIG_FILE)
}

/// Return the directory where managed executable activations are placed.
pub(crate) fn managed_bin_dir() -> PathBuf {
    env::var("BOT_FORGE_BIN_DIR")
        .map(PathBuf::from)
        .unwrap_or_else(|_| app_home().join("bin"))
}

/// Return the path of the persistent installation registry.
pub(crate) fn registry_path() -> PathBuf {
    app_home().join(REGISTRY_FILE)
}

/// Return the directory containing resumable transaction journals.
pub(crate) fn journal_dir() -> PathBuf {
    app_home().join("journals")
}