Documentation
¶
Overview ¶
Package osutils provides OS and path helpers used by Genie.
It solves the problem of standardizing paths and environment checks (e.g. GenieDir for ~/.genie, home resolution) so that config, audit, DB, and other components use the same base directory and behavior across platforms. Without it, each package would duplicate home-dir and path logic.
Index ¶
- Constants
- func FindFileCaseInsensitive(dir, name string) (string, error)
- func GenieDir() string
- func GetAllFiles(dir string) ([]string, error)
- func Getenv(key string, defaultValue string) string
- func Getwd() (string, error)
- func InstallHint(packageName string, osPackageNames map[string]string) string
- func SanitizeForFilename(name string) string
- func ToolNotFoundError(toolName string, osPackageNames map[string]string) error
- func ValidateToolAvailability(toolName string, osPackageNames map[string]string) error
Constants ¶
const ( Brew = "brew" Apt = "apt" Dnf = "dnf" Pacman = "pacman" Apk = "apk" )
Package manager keys for use in osPackageNames maps.
Variables ¶
This section is empty.
Functions ¶
func FindFileCaseInsensitive ¶
func GenieDir ¶
func GenieDir() string
GenieDir returns the path to the Genie directory in the user's home directory. It creates the directory if it does not exist.
func GetAllFiles ¶
func Getenv ¶
Getenv returns the value of the environment variable named by key. If the variable is not set, defaultValue is returned. Without this function, callers would need to manually check for empty env vars and provide fallback values throughout the codebase.
func Getwd ¶
Getwd returns the current working directory as an absolute path. Unlike os.Getwd, this returns a clean error instead of panicking when the directory cannot be determined.
func InstallHint ¶
InstallHint returns a platform-appropriate installation command. osPackageNames maps package manager names to their package names. If a manager-specific name is missing, packageName is used as fallback.
Example:
InstallHint("tesseract", map[string]string{"apt": "tesseract-ocr"})
// macOS → "brew install tesseract"
// Linux → "apt-get install tesseract-ocr (Debian/Ubuntu) or ..."
func SanitizeForFilename ¶
SanitizeForFilename returns a filesystem-safe version of the given name: lowercase, alphanumeric and underscore only; spaces and hyphens become underscore. Other characters are dropped. Empty input yields an empty string. Used for agent names, report names, and similar identifiers in paths (e.g. ~/.genie/reports/<agent>/<date>_<report>.md). Without this function, user-supplied names could produce invalid or unsafe filenames.
func ToolNotFoundError ¶
ToolNotFoundError returns an error recommending installation of a missing CLI tool.
Example:
ToolNotFoundError("tesseract", map[string]string{"apt": "tesseract-ocr"})
// → error("tesseract not found: install with: brew install tesseract")
Types ¶
This section is empty.