osutils

package
v0.1.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

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

View Source
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 FindFileCaseInsensitive(dir, name string) (string, error)

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 GetAllFiles(dir string) ([]string, error)

func Getenv

func Getenv(key string, defaultValue string) string

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

func Getwd() (string, error)

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

func InstallHint(packageName string, osPackageNames map[string]string) string

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

func SanitizeForFilename(name string) string

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

func ToolNotFoundError(toolName string, osPackageNames map[string]string) error

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")

func ValidateToolAvailability

func ValidateToolAvailability(toolName string, osPackageNames map[string]string) error

ValidateToolAvailability checks if a tool is available on the system. If not, it returns an error recommending installation.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL