"use strict";
/* Socket Lib - Built with rolldown */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_node_os = require('../node/os.js');
const require_paths_normalize = require('./normalize.js');
const require_node_path = require('../node/path.js');
const require_env_socket = require('../env/socket.js');
const require_constants_github = require('../constants/github.js');
const require_constants_socket = require('../constants/socket.js');
const require_env_home = require('../env/home.js');
const require_env_windows = require('../env/windows.js');
const require_paths_dirnames = require('./dirnames.js');
const require_paths_rewire = require('./rewire.js');

//#region src/paths/socket.ts
/**
* @file Path utilities for Socket ecosystem directories. Provides
*   platform-aware path resolution for Socket tools' shared directory
*   structure. Directory Structure: ~/.socket/ ├── _cacache/ #
*   Content-addressable cache for npm packages ├── _dlx/ # DLX installations
*   (content-addressed by hash) │ ├── <hash>/ # npm package installs
*   (dlx-package) │ └── <hash>/ # binary downloads (dlx-binary) ├── _socket/ #
*   Socket CLI app directory ├── _registry/ # Socket Registry app directory └──
*   _sfw/ # Socket Firewall app directory.
*/
/**
* Get the OS home directory. Can be overridden in tests using
* setPath('homedir', ...) from paths/rewire.
*/
function getOsHomeDir() {
	return require_paths_rewire.getPathValue("homedir", () => (/* @__PURE__ */ require_node_os.getNodeOs()).homedir());
}
/**
* Get the OS temporary directory. Can be overridden in tests using
* setPath('tmpdir', ...) from paths/rewire.
*/
/**
* Get the OS temporary directory. Can be overridden in tests using
* setPath('tmpdir', ...) from paths/rewire.
*/
function getOsTmpDir() {
	return require_paths_rewire.getPathValue("tmpdir", () => (/* @__PURE__ */ require_node_os.getNodeOs()).tmpdir());
}
/**
* Get a Socket app cache directory (~/.socket/_<appName>/cache).
*/
/**
* Get a Socket app cache directory (~/.socket/_<appName>/cache).
*/
function getSocketAppCacheDir(appName) {
	return /* @__PURE__ */ require_paths_normalize.normalizePath((/* @__PURE__ */ require_node_path.getNodePath()).join(getSocketAppDir(appName), require_paths_dirnames.CACHE_DIR));
}
/**
* Get a Socket app TTL cache directory (~/.socket/_<appName>/cache/ttl).
*/
/**
* Get a Socket app TTL cache directory (~/.socket/_<appName>/cache/ttl).
*/
function getSocketAppCacheTtlDir(appName) {
	return /* @__PURE__ */ require_paths_normalize.normalizePath((/* @__PURE__ */ require_node_path.getNodePath()).join(getSocketAppCacheDir(appName), "ttl"));
}
/**
* Get a Socket app directory (~/.socket/_<appName>).
*/
/**
* Get a Socket app directory (~/.socket/_<appName>).
*/
function getSocketAppDir(appName) {
	return /* @__PURE__ */ require_paths_normalize.normalizePath((/* @__PURE__ */ require_node_path.getNodePath()).join(getSocketUserDir(), `${"_"}${appName}`));
}
/**
* Get the Socket cacache directory (~/.socket/_cacache). Can be overridden with
* SOCKET_CACACHE_DIR environment variable or via setPath() for testing. Result
* is cached via getPathValue for performance.
*
* Priority order:
*
* 1. Test override via setPath('socket-cacache-dir', ...)
* 2. SOCKET_CACACHE_DIR - Full override of cacache directory
* 3. Default: $SOCKET_HOME/_cacache or $HOME/.socket/_cacache
*/
/**
* Get the Socket cacache directory (~/.socket/_cacache). Can be overridden with
* SOCKET_CACACHE_DIR environment variable or via setPath() for testing. Result
* is cached via getPathValue for performance.
*
* Priority order:
*
* 1. Test override via setPath('socket-cacache-dir', ...)
* 2. SOCKET_CACACHE_DIR - Full override of cacache directory
* 3. Default: $SOCKET_HOME/_cacache or $HOME/.socket/_cacache
*/
function getSocketCacacheDir() {
	return require_paths_rewire.getPathValue("socket-cacache-dir", () => {
		if (/* @__PURE__ */ require_env_socket.getSocketCacacheDirEnv()) return /* @__PURE__ */ require_paths_normalize.normalizePath(/* @__PURE__ */ require_env_socket.getSocketCacacheDirEnv());
		return /* @__PURE__ */ require_paths_normalize.normalizePath((/* @__PURE__ */ require_node_path.getNodePath()).join(getSocketUserDir(), `${"_"}cacache`));
	});
}
/**
* Get the Socket CLI directory (~/.socket/_socket).
*/
/**
* Get the Socket CLI directory (~/.socket/_socket).
*/
function getSocketCliDir() {
	return getSocketAppDir(require_constants_socket.SOCKET_CLI_APP_NAME);
}
/**
* Get the Socket DLX directory (~/.socket/_dlx). Can be overridden with
* SOCKET_DLX_DIR environment variable or via setPath() for testing. Result is
* cached via getPathValue for performance.
*
* Priority order:
*
* 1. Test override via setPath('socket-dlx-dir', ...)
* 2. SOCKET_DLX_DIR - Full override of DLX cache directory
* 3. SOCKET_HOME/_dlx - Base directory override (inherits from getSocketUserDir)
* 4. Default: $HOME/.socket/_dlx
* 5. Fallback: /tmp/.socket/_dlx (Unix) or %TEMP%.socket_dlx (Windows)
*/
/**
* Get the Socket DLX directory (~/.socket/_dlx). Can be overridden with
* SOCKET_DLX_DIR environment variable or via setPath() for testing. Result is
* cached via getPathValue for performance.
*
* Priority order:
*
* 1. Test override via setPath('socket-dlx-dir', ...)
* 2. SOCKET_DLX_DIR - Full override of DLX cache directory
* 3. SOCKET_HOME/_dlx - Base directory override (inherits from getSocketUserDir)
* 4. Default: $HOME/.socket/_dlx
* 5. Fallback: /tmp/.socket/_dlx (Unix) or %TEMP%.socket_dlx (Windows)
*/
function getSocketDlxDir() {
	return require_paths_rewire.getPathValue("socket-dlx-dir", () => {
		if (/* @__PURE__ */ require_env_socket.getSocketDlxDirEnv()) return /* @__PURE__ */ require_paths_normalize.normalizePath(/* @__PURE__ */ require_env_socket.getSocketDlxDirEnv());
		return /* @__PURE__ */ require_paths_normalize.normalizePath((/* @__PURE__ */ require_node_path.getNodePath()).join(getSocketUserDir(), `${"_"}${"dlx"}`));
	});
}
/**
* Get the Socket home directory (~/.socket). Alias for getSocketUserDir() for
* consistency across Socket projects.
*/
/**
* Get the Socket home directory (~/.socket). Alias for getSocketUserDir() for
* consistency across Socket projects.
*/
function getSocketHomePath() {
	return getSocketUserDir();
}
/**
* Get the Socket Registry directory (~/.socket/_registry).
*/
/**
* Get the Socket Registry directory (~/.socket/_registry).
*/
function getSocketRegistryDir() {
	return getSocketAppDir(require_constants_socket.SOCKET_REGISTRY_APP_NAME);
}
/**
* Get the Socket Registry GitHub cache directory
* (~/.socket/_registry/cache/ttl/github).
*/
/**
* Get the Socket Registry GitHub cache directory
* (~/.socket/_registry/cache/ttl/github).
*/
function getSocketRegistryGithubCacheDir() {
	return /* @__PURE__ */ require_paths_normalize.normalizePath((/* @__PURE__ */ require_node_path.getNodePath()).join(getSocketAppCacheTtlDir(require_constants_socket.SOCKET_REGISTRY_APP_NAME), require_constants_github.CACHE_GITHUB_DIR));
}
/**
* Get the Socket Wheelhouse directory (~/.socket/_wheelhouse). Shared
* cross-fleet location for binaries that every fleet member can reach without
* each one re-downloading and re-extracting per-repo. Tool installers (janus,
* sfw, etc.) drop their resolved executables under
* `<wheelhouse>/<tool>/<version>/<platform-arch>/`; consumers add the
* appropriate `bin/` to PATH or invoke the binary by absolute path.
*
* Priority order:
*
* 1. Test override via setPath('socket-wheelhouse-dir', ...)
* 2. SOCKET_HOME/_wheelhouse - Base directory override (inherits from
*    getSocketUserDir)
* 3. Default: $HOME/.socket/_wheelhouse
*/
/**
* Get the Socket user directory (~/.socket). Can be overridden with SOCKET_HOME
* environment variable or via setPath() for testing. Result is cached via
* getPathValue for performance.
*
* Priority order:
*
* 1. Test override via setPath('socket-user-dir', ...)
* 2. SOCKET_HOME - Base directory override
* 3. Default: $HOME/.socket
* 4. Fallback: /tmp/.socket (Unix) or %TEMP%.socket (Windows)
*/
function getSocketUserDir() {
	return require_paths_rewire.getPathValue("socket-user-dir", () => {
		const socketHome = /* @__PURE__ */ require_env_socket.getSocketHome();
		if (socketHome) return /* @__PURE__ */ require_paths_normalize.normalizePath(socketHome);
		return /* @__PURE__ */ require_paths_normalize.normalizePath((/* @__PURE__ */ require_node_path.getNodePath()).join(getUserHomeDir(), require_paths_dirnames.DOT_SOCKET_DIR));
	});
}
/**
* Get the user's home directory. Uses environment variables directly to support
* test mocking. Falls back to temporary directory if home is not available.
*
* Priority order: 1. HOME environment variable (Unix) 2. USERPROFILE
* environment variable (Windows) 3. getNodeOs().homedir() 4. Fallback:
* getNodeOs().tmpdir() (rarely used, for restricted environments)
*/
/**
* Get the Socket Wheelhouse directory (~/.socket/_wheelhouse). Shared
* cross-fleet location for binaries that every fleet member can reach without
* each one re-downloading and re-extracting per-repo. Tool installers (janus,
* sfw, etc.) drop their resolved executables under
* `<wheelhouse>/<tool>/<version>/<platform-arch>/`; consumers add the
* appropriate `bin/` to PATH or invoke the binary by absolute path.
*
* Priority order:
*
* 1. Test override via setPath('socket-wheelhouse-dir', ...)
* 2. SOCKET_HOME/_wheelhouse - Base directory override (inherits from
*    getSocketUserDir)
* 3. Default: $HOME/.socket/_wheelhouse
*/
function getSocketWheelhouseDir() {
	return require_paths_rewire.getPathValue("socket-wheelhouse-dir", () => {
		return /* @__PURE__ */ require_paths_normalize.normalizePath((/* @__PURE__ */ require_node_path.getNodePath()).join(getSocketUserDir(), `${"_"}${require_constants_socket.SOCKET_WHEELHOUSE_APP_NAME}`));
	});
}
/**
* Get the Socket user directory (~/.socket). Can be overridden with SOCKET_HOME
* environment variable or via setPath() for testing. Result is cached via
* getPathValue for performance.
*
* Priority order:
*
* 1. Test override via setPath('socket-user-dir', ...)
* 2. SOCKET_HOME - Base directory override
* 3. Default: $HOME/.socket
* 4. Fallback: /tmp/.socket (Unix) or %TEMP%.socket (Windows)
*/
/**
* Get the user's home directory. Uses environment variables directly to support
* test mocking. Falls back to temporary directory if home is not available.
*
* Priority order: 1. HOME environment variable (Unix) 2. USERPROFILE
* environment variable (Windows) 3. getNodeOs().homedir() 4. Fallback:
* getNodeOs().tmpdir() (rarely used, for restricted environments)
*/
function getUserHomeDir() {
	const home = /* @__PURE__ */ require_env_home.getHome();
	if (home) return home;
	const userProfile = /* @__PURE__ */ require_env_windows.getUserprofile();
	if (userProfile) return userProfile;
	try {
		const osHome = getOsHomeDir();
		if (osHome) return osHome;
	} catch {}
	/* c8 ignore next 2 - Triple-fallback only fires when HOME +
	USERPROFILE + os.homedir() all fail; not reachable in tests. */
	return getOsTmpDir();
}

//#endregion
exports.getOsHomeDir = getOsHomeDir;
exports.getOsTmpDir = getOsTmpDir;
exports.getSocketAppCacheDir = getSocketAppCacheDir;
exports.getSocketAppCacheTtlDir = getSocketAppCacheTtlDir;
exports.getSocketAppDir = getSocketAppDir;
exports.getSocketCacacheDir = getSocketCacacheDir;
exports.getSocketCliDir = getSocketCliDir;
exports.getSocketDlxDir = getSocketDlxDir;
exports.getSocketHomePath = getSocketHomePath;
exports.getSocketRegistryDir = getSocketRegistryDir;
exports.getSocketRegistryGithubCacheDir = getSocketRegistryGithubCacheDir;
exports.getSocketUserDir = getSocketUserDir;
exports.getSocketWheelhouseDir = getSocketWheelhouseDir;
exports.getUserHomeDir = getUserHomeDir;