Documentation
¶
Index ¶
- Constants
- func AtomicWriteFile(path string, data []byte, defaultMode os.FileMode) error
- func ConfigDir() string
- func FirstNonEmpty(values ...string) string
- func FormatToolDetail(text, baseDir string) string
- func HomeDir() string
- func InsecureMode() bool
- func IsProcessAlive(pid int) bool
- func IsProcessAliveProc(proc *os.Process) bool
- func NewInsecureAwareClient(timeout time.Duration) *http.Client
- func ReadAll(r io.Reader, limit int64) ([]byte, error)
- func RelativizePaths(text, baseDir string) string
- func SafeSymlink(oldname, newname string) error
- func Truncate(s string, maxRunes int) string
- func WrapTransport(base *http.Transport) *http.Transport
- type ShellSpec
Constants ¶
const ( // ReadLimitAuth is the max bytes for OAuth/token/OIDC HTTP responses. ReadLimitAuth int64 = 1 * 1024 * 1024 // 1 MB // ReadLimitAPI is the max bytes for non-streaming LLM API responses. ReadLimitAPI int64 = 50 * 1024 * 1024 // 50 MB // ReadLimitMCP is the max bytes for MCP JSON-RPC messages. ReadLimitMCP int64 = 100 * 1024 * 1024 // 100 MB // ReadLimitWebSocket is the max bytes for WebSocket messages. ReadLimitWebSocket int64 = 10 * 1024 * 1024 // 10 MB // ReadLimitGeneral is the default max bytes for generic HTTP responses. ReadLimitGeneral int64 = 10 * 1024 * 1024 // 10 MB )
Variables ¶
This section is empty.
Functions ¶
func AtomicWriteFile ¶ added in v1.1.45
AtomicWriteFile writes data to path via a temp file in the same directory, fsync's it, and renames it into place. If path already exists, the existing file's mode is preserved; otherwise defaultMode is used.
This avoids two failure modes of os.WriteFile(path, data, mode):
- A crash between O_TRUNC and the final write leaves the user's source file truncated/empty.
- The hard-coded mode silently downgrades 0755 scripts and 0600 secrets to 0644.
See locks.md S4.
func ConfigDir ¶ added in v1.3.8
func ConfigDir() string
ConfigDir returns the path to the ggcode config directory (~/.ggcode). Returns empty string if home directory cannot be determined.
func FirstNonEmpty ¶ added in v1.2.4
FirstNonEmpty returns the first non-empty string from the given values. Strings that are empty or contain only whitespace are skipped. Returns the trimmed value of the first match, or "" if all values are empty.
func FormatToolDetail ¶ added in v1.1.91
FormatToolDetail prepares a tool detail string for display. It relativizes absolute paths under baseDir. No truncation — the rendering layer handles width (TUI auto-wraps, IM sends as-is).
func HomeDir ¶ added in v1.3.8
func HomeDir() string
HomeDir returns the user's home directory. It checks $HOME first (respecting overrides), then falls back to os.UserHomeDir (which handles $HOME on Unix, $USERPROFILE on Windows). Finally checks %USERPROFILE% directly (for edge cases on Windows). Returns empty string if neither is available.
func InsecureMode ¶ added in v1.3.61
func InsecureMode() bool
InsecureMode returns true when the GGCODE_INSECURE environment variable is set to a truthy value ("1", "true", "yes"). When true, all outbound HTTP transports created through WrapTransport or NewInsecureAwareClient will skip TLS certificate verification.
The result is cached after the first call so the env var is only read once.
func IsProcessAlive ¶ added in v1.3.8
IsProcessAlive checks if a process with the given PID is still running. On Unix, it sends signal 0 (no signal, just permission/existence check).
func IsProcessAliveProc ¶ added in v1.3.8
IsProcessAliveProc checks if the given os.Process is still running.
func NewInsecureAwareClient ¶ added in v1.3.61
NewInsecureAwareClient returns an *http.Client with the given timeout. If GGCODE_INSECURE is set, the client's transport will skip TLS verification.
func ReadAll ¶ added in v1.2.9
ReadAll reads from r with a size limit. Returns the data and an error if the reader exceeds limit. This prevents unbounded memory allocation from malicious or broken HTTP responses.
Usage:
data, err := util.ReadAll(resp.Body, util.ReadLimitAuth)
func RelativizePaths ¶ added in v1.1.34
RelativizePaths replaces absolute paths under baseDir with relative paths ("./"). It handles two cases:
- baseDir + separator + suffix → "./" + suffix
- baseDir as an exact standalone token → "."
The second case uses boundary checking to avoid false matches (e.g. "/Users/proj" should not match inside "/Users/proj-backup").
func SafeSymlink ¶ added in v1.3.8
SafeSymlink creates a symbolic link from oldname to newname. On non-Windows platforms, this is a direct wrapper around os.Symlink.