Documentation
¶
Index ¶
- func HumanTimeElapsedSince(d time.Duration) string
- func InputFromEditor(placeholder string, pattern string, content string) (string, error)
- func IsPathContained(directory string, path string) (bool, error)
- func IsPathWithinCWD(path string) (bool, string)
- func ParseSince(s string) (time.Time, error)
- func ReadFileContents(file string) (string, error)
- func ResolveDir(path string) string
- func SetStructDefaults(data any) bool
- func ShortPath(path string) string
- func TryExtractJSONObject(s string, target any) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HumanTimeElapsedSince ¶
HumanTimeElapsedSince returns a human-friendly "in the past" representation of the given duration.
func InputFromEditor ¶
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
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
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
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 ¶
ReadFileContents returns the string contents of the given file.
func ResolveDir ¶ added in v0.8.0
ResolveDir returns the directory bane of a filesystem path
func SetStructDefaults ¶
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 TryExtractJSONObject ¶
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.