util

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HumanTimeElapsedSince

func HumanTimeElapsedSince(d time.Duration) string

HumanTimeElapsedSince returns a human-friendly "in the past" representation of the given duration.

func InputFromEditor

func InputFromEditor(placeholder string, pattern string, content string) (string, error)

InputFromEditor retrieves user input by opening an editor (one specified by $EDITOR or 'vim' if $EDITOR is not set) on a temporary file. Once the editor closes, the contents of the file are read and the file is deleted. If the contents of the file exactly match the value of placeholder (no edits to the file were made), then an empty string is returned. Otherwise, the contents are returned. Example patten: message.*.md

func IsPathContained added in v0.8.0

func IsPathContained(directory string, path string) (bool, error)

IsPathContained attempts to verify whether `path` is the same as or contained within `directory`. It is overly cautious, returning false even if `path` IS contained within `directory`, but the two paths use different casing, and we happen to be on a case-insensitive filesystem. This is ultimately to attempt to stop an LLM from going outside of where I tell it to. Additional layers of security should be considered.. run in a VM/container.

func IsPathWithinCWD added in v0.8.0

func IsPathWithinCWD(path string) (bool, string)

IsPathWithinCWD checks whether the given path is within the current working directory. Returns true and an empty string when it is; false and a reason when it is not or when the check fails.

func ParseSince added in v0.8.0

func ParseSince(s string) (time.Time, error)

ParseSince parses a --since value. It accepts either a relative duration (e.g. "1w", "7d", "24h") or an absolute date in YYYY-MM-DD format.

func ReadFileContents

func ReadFileContents(file string) (string, error)

ReadFileContents returns the string contents of the given file.

func ResolveDir added in v0.8.0

func ResolveDir(path string) string

ResolveDir returns the directory bane of a filesystem path

func SetStructDefaults

func SetStructDefaults(data any) bool

SetStructDefaultValues checks for any nil ptr fields within the passed struct, and sets the values of those fields to the value that is defined by their "default" struct tag. Handles setting string, int, and bool values. Returns whether any changes were made to the struct.

func ShortPath

func ShortPath(path string) string

ShortPath replaces the user's home directory with ~.

func TryExtractJSONObject

func TryExtractJSONObject(s string, target any) error

TryExtractJSONObject finds the first '{' in s and the first '}' after it, then unmarshals the enclosed substring into target. Useful for extracting a JSON object from an LLM response that may contain surrounding text or markdown fences. Does not handle nested objects

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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