Documentation
¶
Overview ¶
Package config loads and validates gitl configuration.
Two config levels are merged by priority flag > env > .gitl.yaml (repo, cwd) > ~/.config/gitl/config.yaml (personal), via a per-call viper instance → struct Config. The personal path comes from os.UserConfigDir() (never a hardcoded ~/.config; on Windows → %AppData%\gitl). An empty api_key selects offline mode (a warning is printed to stderr by the caller — Load does not fail).
The cost:/output:/policy:/diff: blocks and provider branching (openai / ollama / azure_openai) are all wired into behavior as of Этап 2 (см. docs/TECHNICAL_PLAN.md §5–§8). digest:/required_changelog_categories are wired into changelog/digest as of Этап 3 (§9.3, §10.4/§10.6).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PersonalConfigPath ¶
PersonalConfigPath returns the default personal config file path, derived from os.UserConfigDir() so it is correct across platforms.
Types ¶
type AzureOpenAIConfig ¶
type AzureOpenAIConfig struct {
Endpoint string `mapstructure:"endpoint"`
Deployment string `mapstructure:"deployment"`
APIVersion string `mapstructure:"api_version"`
}
AzureOpenAIConfig holds the Azure OpenAI endpoint coordinates. The request URL is {endpoint}/openai/deployments/{deployment}/chat/completions?api-version={api_version}, with auth via the "api-key" header (not "Authorization: Bearer").
type CacheConfig ¶ added in v0.3.0
type CacheConfig struct {
Enabled bool `mapstructure:"enabled"`
TTLHours int `mapstructure:"ttl_hours"`
}
CacheConfig controls the on-disk LLM response cache (Item 5). Enabled toggles the cache; TTLHours <= 0 also disables it. Only used for network reviews — offline mode never consults or writes the cache.
type Config ¶
type Config struct {
LLM LLMConfig `mapstructure:"llm"`
Cost CostConfig `mapstructure:"cost"`
Output OutputConfig `mapstructure:"output"`
Diff DiffConfig `mapstructure:"diff"`
Policy PolicyConfig `mapstructure:"policy"`
Digest DigestConfig `mapstructure:"digest"`
Prompt PromptConfig `mapstructure:"prompt"`
Cache CacheConfig `mapstructure:"cache"`
}
Config is the fully merged, validated configuration for one gitl invocation.
func Load ¶
Load builds the merged configuration for one invocation.
Priority (lowest → highest): built-in defaults → personal config file → repo-level .gitl.yaml → environment (GITL_* / GITL_API_KEY) → flags. A fresh viper instance is used per call so tests never share global state.
Missing config files are not an error — the file layers are simply skipped.
func (*Config) OfflineMode ¶
OfflineMode reports whether gitl should use the deterministic offline provider instead of the network client (i.e. no API key is configured).
type CostConfig ¶
type CostConfig struct {
MaxCostUSD float64 `mapstructure:"max_cost_usd"`
WarnAtUSD float64 `mapstructure:"warn_at_usd"`
PricePer1MInput float64 `mapstructure:"price_per_1m_input"`
PricePer1MOutput float64 `mapstructure:"price_per_1m_output"`
}
CostConfig holds cost-guard thresholds and optional pricing overrides. When PricePer1MInput/Output are 0 the built-in pricing table (internal/llm) is used (§8.2). max_cost_usd <= 0 disables the guard entirely (§8.4).
type DiffConfig ¶
type DiffConfig struct {
MaxDiffBytes int `mapstructure:"max_diff_bytes"`
ExcludeGlobs []string `mapstructure:"exclude_globs"`
}
DiffConfig bounds the diff sent to the LLM: max_diff_bytes is the truncation limit, exclude_globs skip matching changed files before building the diff.
type DigestConfig ¶
type DigestConfig struct {
Repos []RepoRef `mapstructure:"repos"`
}
DigestConfig holds the repo-level multi-repo digest.repos list (§10.4/§10.6). A --repos flag, when set, replaces this list wholesale rather than merging with it (§10.4) — unlike exclude_globs, which adds.
type LLMConfig ¶
type LLMConfig struct {
Provider string `mapstructure:"provider"`
APIKey string `mapstructure:"api_key"`
BaseURL string `mapstructure:"base_url"`
Model string `mapstructure:"model"`
MaxTokens int `mapstructure:"max_tokens"`
Temperature float64 `mapstructure:"temperature"`
TimeoutSeconds int `mapstructure:"timeout_seconds"`
MaxRetries int `mapstructure:"max_retries"`
// AzureOpenAI is required only when Provider == "azure_openai".
AzureOpenAI AzureOpenAIConfig `mapstructure:"azure_openai"`
}
LLMConfig configures the LLM provider and request parameters.
type Options ¶
type Options struct {
// RepoDir is the directory searched for the repo-level ".gitl.yaml".
// Empty means the current working directory.
RepoDir string
// PersonalPath overrides the personal config file path. Empty means
// "<os.UserConfigDir()>/gitl/config.yaml".
PersonalPath string
// Flags, when non-nil, are bound so that explicitly-set flags win over
// env and files. Only flags present in the set are considered.
Flags *pflag.FlagSet
}
Options controls how Load discovers config files.
type OutputConfig ¶
type OutputConfig struct {
Format string `mapstructure:"format"`
Color bool `mapstructure:"color"`
// TemplateFile is an optional custom text/template file for the md format
// (Item 3). Empty means the built-in Markdown rendering; it is ignored for
// the text/json formats.
TemplateFile string `mapstructure:"template_file"`
// Stream enables token-by-token SSE streaming for `review` when stdout is a
// terminal and the format is md/text (Item 1). Disabled by --no-stream or in
// offline/json/non-TTY contexts.
Stream bool `mapstructure:"stream"`
}
OutputConfig holds output settings. All three formats (md/text/json) are rendered as of Этап 2.
type PolicyConfig ¶
type PolicyConfig struct {
FailOn string `mapstructure:"fail_on"`
RequiredChangelogCategories []string `mapstructure:"required_changelog_categories"`
ExcludeGlobs []string `mapstructure:"exclude_globs"`
}
PolicyConfig is the repo-level governance policy. fail_on is the CI gating threshold wired into `review` as of Этап 2; required_changelog_categories is wired into `changelog` as of Этап 3 (warn-only, see docs/TECHNICAL_PLAN.md §9.3).
type PromptConfig ¶ added in v0.2.1
type PromptConfig struct {
SystemTemplateFile string `mapstructure:"system_template_file"`
}
PromptConfig holds custom prompt template overrides (Item 3). When SystemTemplateFile is empty the embedded default review system prompt is used (identical to prior behavior); otherwise it is parsed as a text/template and executed with the review data.
type RepoRef ¶
type RepoRef struct {
Path string `mapstructure:"path"`
}
RepoRef is one entry of digest.repos: a filesystem path to another git repository, resolved relative to the directory containing the repo-level .gitl.yaml that declared it (or the current working directory if none was found) — see §10.4.