use std::path::PathBuf; /// Resolve asset path at runtime (not compile-time). /// /// Priority: /// 1. Explicit environment variable (e.g., MOMENTRY_SCRIPTS_DIR) /// 2. Sibling of current_exe (same directory as running binary) /// 3. Relative path fallback (dev machine) /// /// This avoids CARGO_MANIFEST_DIR being baked into the binary at compile time, /// which breaks on binary-only release hosts. pub fn resolve_asset_path(env_var: &str, fallback_relative: &str) -> PathBuf { std::env::var_os(env_var) .map(PathBuf::from) .filter(|p| p.exists()) .or_else(|| { std::env::current_exe() .ok() .and_then(|p| p.parent().map(|d| d.join(fallback_relative))) .filter(|p| p.exists()) }) .unwrap_or_else(|| PathBuf::from(fallback_relative)) } /// Get scripts directory. pub fn scripts_dir() -> PathBuf { resolve_asset_path("MOMENTRY_SCRIPTS_DIR", "scripts") } /// Get CLI tools directory. pub fn cli_dir() -> PathBuf { resolve_asset_path("MOMENTRY_CLI_DIR", "tools/cli") } /// Get config directory. pub fn config_dir() -> PathBuf { resolve_asset_path("MOMENTRY_CONFIG_DIR", "config") } /// Get models directory. pub fn models_dir() -> PathBuf { resolve_asset_path("MOMENTRY_MODELS_DIR", "models") }