Documentation
¶
Overview ¶
Package globalconfig loads and validates the user-level dark-factory configuration from ~/.config/dark-factory/config.yaml (XDG) with fallback to ~/.dark-factory/config.yaml (legacy).
Index ¶
Constants ¶
const DefaultMaxContainers = 3
DefaultMaxContainers is the system-wide container limit when no config is set.
const ModelPattern = `^[a-zA-Z0-9._:/[\]-]{1,256}$`
ModelPattern is the regex source string. Exported so callers can include it in error messages.
Square brackets are allowed for provider-side variant suffixes (e.g. `claude-sonnet-4-5[1m]` for the 1M context window variant, `deepseek-v4-flash[1m]`). They are NOT shell metacharacters in the docker-run context — model flows as a single argv element via `exec.Command(name, args...)`, never through `sh -c`, so the shell glob meaning never applies.
Variables ¶
var ModelRegex = regexp.MustCompile(ModelPattern)
ModelRegex validates model identifiers at every config layer (global, project, CLI arg). Permits Anthropic IDs (claude-opus-4-7), variant suffixes (claude-sonnet-4-5[1m]), other-provider IDs (qwen3.6:35b-a3b, deepseek-v4-flash[1m]), namespaced paths (local/qwen3.6:35b-a3b), and Docker image refs (docker.io/bborbe/claude-yolo:v0.6.1). Blocks true shell metacharacters (`;`, `&`, `|`, `$`, backticks, quotes, etc.). EXPORTED so pkg/config and main.go reuse the SAME compiled regex — do not duplicate the pattern.
Functions ¶
func FileExists ¶ added in v0.111.0
FileExists reports whether the global config file exists. Callers use this only to distinguish "global file present" from "using built-in defaults" in diagnostic logs. - Config file missing → (false, nil) - Config dir lookup fails → (false, wrapped error) - Any other stat error → (false, wrapped error) - File present (any size) → (true, nil)
func FindConfigDir ¶ added in v0.191.0
FindConfigDir returns the absolute path to the configuration directory for the given tool name, following the XDG Base Directory Specification with legacy fallback.
Resolution order:
- If ~/.config/<tool>/ exists (stat success) → returns ~/.config/<tool/>
- If ~/.<tool>/ exists (stat success) → returns ~/.<tool>/ (legacy path)
- Neither exists → returns ~/.config/<tool>/ (XDG default; not created)
Returns an error only if the home directory lookup fails. Stat failures on missing directories are swallowed (they trigger fallthrough, not error).
Types ¶
type GlobalConfig ¶
type GlobalConfig struct {
MaxContainers int `yaml:"maxContainers"`
HideGit *bool `yaml:"hideGit,omitempty"`
AutoRelease *bool `yaml:"autoRelease,omitempty"`
DirtyFileThreshold *int `yaml:"dirtyFileThreshold,omitempty"`
Model *string `yaml:"model,omitempty"`
AutoApprovePrompts *bool `yaml:"autoApprovePrompts,omitempty"`
AutoGeneratePrompts *bool `yaml:"autoGeneratePrompts,omitempty"`
Backend *string `yaml:"backend,omitempty"`
Env map[string]string `yaml:"env,omitempty"`
}
GlobalConfig holds the user-level dark-factory configuration. It is loaded from ~/.config/dark-factory/config.yaml (XDG) with fallback to ~/.dark-factory/config.yaml (legacy) once at daemon startup. When the file does not exist or the field is omitted, defaults apply.