/**
 * Central OS platform path resolution using env-paths.
 *
 * Provides OS-appropriate paths for CLEO's global directories using
 * XDG conventions on Linux, standard conventions on macOS/Windows.
 * Results are cached for the process lifetime. Env vars take precedence.
 *
 * Platform path defaults (no env vars set):
 *   data:   ~/.local/share/cleo  | ~/Library/Application Support/cleo | %LOCALAPPDATA%\cleo\Data
 *   config: ~/.config/cleo       | ~/Library/Preferences/cleo          | %APPDATA%\cleo\Config
 *   cache:  ~/.cache/cleo        | ~/Library/Caches/cleo               | %LOCALAPPDATA%\cleo\Cache
 *   log:    ~/.local/state/cleo  | ~/Library/Logs/cleo                 | %LOCALAPPDATA%\cleo\Log
 *   temp:   /tmp/<user>/cleo     | /var/folders/.../cleo               | %TEMP%\cleo
 *
 * CLEO_HOME env var overrides the data path for backward compatibility
 * with existing ~/.cleo installations.
 */
import { arch, hostname, platform, release } from 'node:os';
import envPaths from 'env-paths';
const APP_NAME = 'cleo';
let _paths = null;
let _sysInfo = null;
let _lastCleoHome;
/**
 * Get OS-appropriate paths for CLEO's global directories.
 * Cached after first call. CLEO_HOME env var overrides the data path.
 *
 * The cache is automatically invalidated when CLEO_HOME changes,
 * so test code can set process.env['CLEO_HOME'] without calling
 * _resetPlatformPathsCache() manually.
 */
export function getPlatformPaths() {
    const currentCleoHome = process.env['CLEO_HOME'];
    // Invalidate if CLEO_HOME changed since last cache build
    if (_paths && currentCleoHome !== _lastCleoHome) {
        _paths = null;
        _sysInfo = null;
    }
    if (_paths)
        return _paths;
    const ep = envPaths(APP_NAME, { suffix: '' });
    _lastCleoHome = currentCleoHome;
    _paths = {
        data: currentCleoHome ?? ep.data,
        config: ep.config,
        cache: ep.cache,
        log: ep.log,
        temp: ep.temp,
    };
    return _paths;
}
/**
 * Get a cached system information snapshot.
 * Captured once and reused for the process lifetime.
 * Useful for diagnostics, issue reports, and log enrichment.
 */
export function getSystemInfo() {
    if (_sysInfo)
        return _sysInfo;
    const paths = getPlatformPaths();
    _sysInfo = {
        platform: platform(),
        arch: arch(),
        release: release(),
        hostname: hostname(),
        nodeVersion: process.version,
        paths,
    };
    return _sysInfo;
}
/**
 * Invalidate the path and system info caches.
 * Use in tests after mutating CLEO_HOME env var.
 * @internal
 */
export function _resetPlatformPathsCache() {
    _paths = null;
    _sysInfo = null;
}
//# sourceMappingURL=platform-paths.js.map