Documentation
¶
Overview ¶
Package xdg provides Neovim-inspired XDG Base Directory path resolution for TaskSmith.
Modeled after Neovim's stdpath() and NVIM_APPNAME conventions, this package resolves user-level directories for configuration, persistent data, local state, cache, and ephemeral runtime files (such as Unix domain sockets and lockfiles).
Application Name (TASKSMITH_APPNAME) ¶
All application directories are scoped by the application name returned by AppName, which defaults to "tasksmith". Users and test harnesses can override this name via the TASKSMITH_APPNAME environment variable (analogous to NVIM_APPNAME in Neovim) to run isolated profiles side by side. Path traversal components ("..") and absolute paths in TASKSMITH_APPNAME are rejected and fall back to "tasksmith".
Directory Types (VarType / stdpath equivalents) ¶
- VarTypeConfig ("config"): User configuration files ($XDG_CONFIG_HOME/<appname>, defaulting to ~/.config/<appname> on Unix or %LOCALAPPDATA%\<appname> on Windows).
- VarTypeData ("data"): Persistent application data and workspace repositories ($XDG_DATA_HOME/<appname>, defaulting to ~/.local/share/<appname> on Unix or %LOCALAPPDATA%\<appname> on Windows).
- VarTypeState ("state"): Persistent local state and logs ($XDG_STATE_HOME/<appname>, defaulting to ~/.local/state/<appname> on Unix or %LOCALAPPDATA%\<appname> on Windows).
- VarTypeCache ("cache"): Non-essential cached data ($XDG_CACHE_HOME/<appname>, defaulting to ~/.cache/<appname> on Unix or %TEMP%\<appname> on Windows).
- VarTypeRuntime ("run"): Ephemeral runtime files such as IPC sockets and lockfiles. When $XDG_RUNTIME_DIR is set, Home resolves to $XDG_RUNTIME_DIR/<appname>. When $XDG_RUNTIME_DIR is unset (common on macOS and headless environments), Home falls back to <StateHome>/run (i.e. $XDG_STATE_HOME/<appname>/run).
Workspace, Log, and Socket Helpers ¶
- WorkspacesHome and WorkspaceDir resolve deterministic per-workspace data directories under <DataHome>/workspaces/<sha256-prefix>.
- LogsDir and LogFilePath resolve log files under <StateHome>/logs (following Neovim's stdpath("log") convention under the state directory).
- SocketPath resolves IPC socket and lockfile paths inside the runtime directory.
Index ¶
- Constants
- func AppName() string
- func BuiltinDir(subdirs ...string) (string, error)
- func ClearCache()
- func GetVar(varType VarType) string
- func HistoryDir() (string, error)
- func HistoryFilePath(filename string) (string, error)
- func Home(key VarType) (string, error)
- func LogFilePath(filename string) (string, error)
- func LogsDir() (string, error)
- func RunWithTestEnv(m *testing.M, appName string)
- func SetTestEnv(tmpDir string, appName string)
- func SocketPath(name string) (string, error)
- func SubCacheDir(subdirs ...string) (string, error)
- func SubConfigDir(subdirs ...string) (string, error)
- func SubDataDir(subdirs ...string) (string, error)
- func SubRuntimeDir(subdirs ...string) (string, error)
- func SubStateDir(subdirs ...string) (string, error)
- func Subdir(key VarType, subdirs ...string) (string, error)
- func UserResourceDirs() []string
- func WorkspaceDir(key string) (string, error)
- func WorkspacesHome() (string, error)
- type VarType
Constants ¶
const DefaultAppName = "tasksmith"
DefaultAppName is the default application directory name when TASKSMITH_APPNAME is unset or invalid.
Variables ¶
This section is empty.
Functions ¶
func AppName ¶
func AppName() string
AppName returns the active application name, defaulting to "tasksmith" unless overridden by a valid TASKSMITH_APPNAME environment variable.
func BuiltinDir ¶
func ClearCache ¶
func ClearCache()
ClearCache clears the cached XDG base directory paths and reloads TASKSMITH_APPNAME.
func GetVar ¶
GetVar returns the base XDG directory path for the given VarType before appending the application name.
func HistoryDir ¶
HistoryDir returns the directory path for persistent history files (<StateHome>/history), mirroring LogsDir() under XDG_STATE_HOME.
func HistoryFilePath ¶
HistoryFilePath returns the full path for a given history filename within HistoryDir().
func Home ¶
Home returns the application's base directory for the given VarType. For VarTypeConfig, VarTypeData, VarTypeState, and VarTypeCache, it returns "<GetVar(key)>/<AppName()>". For VarTypeRuntime, it returns "$XDG_RUNTIME_DIR/<AppName()>" when XDG_RUNTIME_DIR is set, or "<Home(VarTypeState)>/run" when XDG_RUNTIME_DIR is unset.
func LogFilePath ¶
LogFilePath returns the full path for a given log filename within LogsDir().
func LogsDir ¶
LogsDir returns the directory path for application logs (<StateHome>/logs), following Neovim's stdpath("log") convention under XDG_STATE_HOME.
func RunWithTestEnv ¶
RunWithTestEnv executes a test suite within an isolated temporary XDG environment.
func SetTestEnv ¶
SetTestEnv configures all XDG environment variables and TASKSMITH_APPNAME to use a temporary directory and refreshes the cache.
func SocketPath ¶
SocketPath returns the full path for an ephemeral socket or lockfile (such as "brain.sock" or "brain.lock") inside the application's runtime directory.
func SubCacheDir ¶
SubCacheDir returns a subdirectory within the application's cache directory.
func SubConfigDir ¶
SubConfigDir returns a subdirectory within the application's configuration directory.
func SubDataDir ¶
SubDataDir returns a subdirectory within the application's data directory.
func SubRuntimeDir ¶
SubRuntimeDir returns a subdirectory within the application's runtime directory.
func SubStateDir ¶
SubStateDir returns a subdirectory within the application's state directory.
func Subdir ¶
Subdir returns a subdirectory within the application's base directory for the given VarType.
func UserResourceDirs ¶
func UserResourceDirs() []string
func WorkspaceDir ¶
WorkspaceDir returns a deterministic directory path for a given workspace key. The directory is located inside WorkspacesHome() and named after the 16-hex-character prefix (first 8 bytes) of the SHA-256 digest of key.
func WorkspacesHome ¶
WorkspacesHome returns the root directory for all workspaces (<DataHome>/workspaces).
Types ¶
type VarType ¶
type VarType int
VarType represents a category of XDG Base Directory (analogous to Neovim's stdpath types).
const ( // VarTypeConfig represents the XDG_CONFIG_HOME directory. VarTypeConfig VarType = iota // VarTypeData represents the XDG_DATA_HOME directory. VarTypeData // VarTypeState represents the XDG_STATE_HOME directory. VarTypeState // VarTypeCache represents the XDG_CACHE_HOME directory. VarTypeCache // VarTypeRuntime represents the XDG_RUNTIME_DIR directory for ephemeral runtime files. VarTypeRuntime )