/**
 * GROK_HOME - Centralized configuration directory management
 *
 * Supports the GROK_HOME environment variable to customize the location
 * of Grok CLI configuration files and data (like VIBE_HOME in Mistral Vibe).
 *
 * Default: ~/.codebuddy/
 *
 * Usage:
 *   export GROK_HOME="/path/to/custom/home"
 *   grok "your prompt"
 *
 * Directory structure:
 *   $GROK_HOME/
 *   ├── config.toml          # Configuration file
 *   ├── user-settings.json   # User settings
 *   ├── .env                 # API keys
 *   ├── codebuddy.db              # SQLite database
 *   ├── agents/              # Custom agents
 *   ├── prompts/             # Custom system prompts
 *   ├── commands/            # Custom slash commands
 *   ├── themes/              # Custom themes
 *   ├── personas/            # AI personas
 *   ├── memory/              # Persistent memory
 *   ├── sessions/            # Session data
 *   ├── checkpoints/         # File checkpoints
 *   ├── tasks/               # Background tasks
 *   ├── branches/            # Conversation branches
 *   ├── cache/               # Cache data
 *   └── logs/                # Log files
 */
import os from 'os';
import path from 'path';
import fs from 'fs';
/**
 * Get the GROK_HOME directory path
 *
 * Priority:
 * 1. GROK_HOME environment variable
 * 2. ~/.codebuddy/ (default)
 */
export function getCodeBuddyHome() {
    return process.env.GROK_HOME || path.join(os.homedir(), '.codebuddy');
}
/**
 * Get a path within GROK_HOME
 *
 * @param relativePath - Path relative to GROK_HOME (e.g., 'agents', 'config.toml')
 * @returns Absolute path
 */
export function getGrokPath(...relativePath) {
    return path.join(getCodeBuddyHome(), ...relativePath);
}
/**
 * Get the agents directory path
 */
export function getAgentsDir() {
    return getGrokPath('agents');
}
/**
 * Get the prompts directory path
 */
export function getPromptsDir() {
    return getGrokPath('prompts');
}
/**
 * Get the commands directory path
 */
export function getCommandsDir() {
    return getGrokPath('commands');
}
/**
 * Get the themes directory path
 */
export function getThemesDir() {
    return getGrokPath('themes');
}
/**
 * Get the database path
 */
export function getDatabasePath() {
    return getGrokPath('codebuddy.db');
}
/**
 * Get the user settings path
 */
export function getUserSettingsPath() {
    return getGrokPath('user-settings.json');
}
/**
 * Get the sessions directory path
 */
export function getSessionsDir() {
    return getGrokPath('sessions');
}
/**
 * Get the memory directory path
 */
export function getMemoryDir() {
    return getGrokPath('memory');
}
/**
 * Get the checkpoints directory path
 */
export function getCheckpointsDir() {
    return getGrokPath('checkpoints');
}
/**
 * Get the cache directory path
 */
export function getCacheDir() {
    return getGrokPath('cache');
}
/**
 * Get the tasks directory path
 */
export function getTasksDir() {
    return getGrokPath('tasks');
}
/**
 * Get the branches directory path
 */
export function getBranchesDir() {
    return getGrokPath('branches');
}
/**
 * Get the personas directory path
 */
export function getPersonasDir() {
    return getGrokPath('personas');
}
/**
 * Get the offline data directory path
 */
export function getOfflineDir() {
    return getGrokPath('offline');
}
/**
 * Ensure GROK_HOME directory exists
 */
export function ensureCodeBuddyHome() {
    const codebuddyHome = getCodeBuddyHome();
    if (!fs.existsSync(codebuddyHome)) {
        fs.mkdirSync(codebuddyHome, { recursive: true });
    }
}
/**
 * Ensure a subdirectory exists within GROK_HOME
 */
export function ensureGrokDir(...relativePath) {
    const dir = getGrokPath(...relativePath);
    if (!fs.existsSync(dir)) {
        fs.mkdirSync(dir, { recursive: true });
    }
    return dir;
}
/**
 * Check if custom GROK_HOME is set
 */
export function isCustomCodeBuddyHome() {
    return !!process.env.GROK_HOME;
}
/**
 * Format GROK_HOME info for display
 */
export function formatCodeBuddyHomeInfo() {
    const codebuddyHome = getCodeBuddyHome();
    const isCustom = isCustomCodeBuddyHome();
    return `GROK_HOME: ${codebuddyHome}${isCustom ? ' (custom)' : ' (default)'}`;
}
//# sourceMappingURL=codebuddy-home.js.map