cc-switch-tui 0.1.4

All-in-One Assistant for Claude Code, Codex, Gemini, OpenCode, OpenClaw & Hermes
Documentation
use crate::app_config::AppType;

/// Whether we should write/delete "live" config files for a given app.
///
/// Policy: **auto** (safe default)
/// - If the target app looks uninitialized (its config dir / key live file is missing),
///   skip live writes/deletes and do **not** create any directories/files.
pub(crate) fn should_sync_live(app_type: &AppType) -> bool {
    match app_type {
        // Claude is considered initialized if either:
        // - ~/.claude (settings dir) exists, or
        // - ~/.claude.json (MCP file) exists
        AppType::Claude => {
            crate::config::get_claude_config_dir().exists()
                || crate::config::get_claude_mcp_path().exists()
        }
        // Codex is considered initialized if CODEX_HOME / override dir / default dir exists.
        AppType::Codex => crate::codex_config::get_codex_config_dir().exists(),
        // Gemini is considered initialized if ~/.gemini (or override dir) exists.
        AppType::Gemini => crate::gemini_config::get_gemini_dir().exists(),
        // OpenCode is considered initialized if ~/.config/opencode (or override dir) exists.
        AppType::OpenCode => crate::opencode_config::get_opencode_dir().exists(),
        // OpenClaw is considered initialized if ~/.openclaw (or override dir) exists.
        AppType::OpenClaw => get_openclaw_dir().exists(),
        // Hermes is considered initialized if ~/.hermes (or override dir) exists.
        AppType::Hermes => get_hermes_dir().exists(),
    }
}

fn get_openclaw_dir() -> std::path::PathBuf {
    crate::settings::get_openclaw_override_dir()
        .or_else(|| crate::config::home_dir().map(|home| home.join(".openclaw")))
        .unwrap_or_else(|| std::path::PathBuf::from(".openclaw"))
}

fn get_hermes_dir() -> std::path::PathBuf {
    crate::settings::get_hermes_override_dir()
        .or_else(|| crate::config::home_dir().map(|home| home.join(".hermes")))
        .unwrap_or_else(|| std::path::PathBuf::from(".hermes"))
}