Documentation
¶
Index ¶
- Constants
- func CleanFileName(name string) string
- func DetectImageFormat(data []byte) string
- func DetectMIMEType(path string) string
- func IsRasterImage(mimeType string) bool
- func MergeJSONFile(path string, keys map[string]any, perm os.FileMode) error
- func NormalizeID(raw string) string
- func ReadJSONFile[T any](path string) (*T, error)
- func ShortID() string
- func TempDir() string
- func TempFileRegex() *regexp.Regexp
- func TempFileRule() string
- func TempPath(name, ext string) string
- func TempPathRandom(ext string) string
- func UnmergeJSONFile(path string, keyPaths ...[]string)
- func WriteJSONFile[T any](path string, v *T, perm os.FileMode) error
- type SyncQueue
- type SyncValue
Constants ¶
const TempPrefix = "gua-"
TempPrefix is the filename prefix for all gua temp files.
Variables ¶
This section is empty.
Functions ¶
func CleanFileName ¶
CleanFileName strips the "gua-{uuid}." prefix from temp file names.
func DetectImageFormat ¶
DetectImageFormat checks magic bytes to determine image format.
func DetectMIMEType ¶
DetectMIMEType returns the MIME type for a file path based on extension.
func IsRasterImage ¶
IsRasterImage returns true for MIME types supported as images by most platforms.
func MergeJSONFile ¶
MergeJSONFile reads an existing JSON file, deep-merges the provided keys into it, and writes back. If the file does not exist or is invalid JSON, starts fresh. Nested maps are recursively merged; other types are overwritten.
func NormalizeID ¶
NormalizeID replaces @, ., and : with - for filesystem safety.
func ReadJSONFile ¶
ReadJSONFile reads a JSON file and unmarshals it into a value of type T.
func ShortID ¶
func ShortID() string
ShortID returns a short random hex identifier (8 chars from UUID).
func TempFileRegex ¶
TempFileRegex returns a compiled regex matching gua temp file paths. Used by server/formatter to extract file paths from agent responses.
func TempFileRule ¶
func TempFileRule() string
TempFileRule returns the file naming rule for agent prompts.
func TempPathRandom ¶
TempPathRandom returns a unique temp file path with a random ID.
func UnmergeJSONFile ¶
UnmergeJSONFile removes the specified keys from a JSON file. Keys are paths like ["mcpServers", "gua"] meaning delete existing["mcpServers"]["gua"]. If the parent map becomes empty after removal, it is also removed. If the file becomes empty or doesn't exist, the file is deleted.
Types ¶
type SyncQueue ¶
type SyncQueue[T any] struct { // contains filtered or unexported fields }
SyncQueue is a thread-safe FIFO queue.
func (*SyncQueue[T]) Drain ¶
func (q *SyncQueue[T]) Drain() []T
Drain removes all items and returns them.
func (*SyncQueue[T]) Peek ¶
Peek returns the front item without removing it. Returns zero value and false if the queue is empty.
func (*SyncQueue[T]) Pop ¶
Pop removes and returns the front item. Returns zero value and false if the queue is empty.