config

package
v0.0.78 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 13, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var KnownAgentPreferenceKeys = map[string]bool{
	"provider":             true,
	"model":                true,
	"tools_enabled":        true,
	"tools_disabled":       true,
	"shell_allow":          true,
	"shell_auto_run":       true,
	"spawn_max_parallel":   true,
	"spawn_max_depth":      true,
	"spawn_timeout":        true,
	"spawn_allowed_agents": true,
	"max_turns":            true,
	"search":               true,
}

KnownAgentPreferenceKeys contains valid keys for agent preference configurations

View Source
var KnownKeys = map[string]bool{

	"default_provider": true,
	"providers":        true,
	"diagnostics":      true,
	"debug_logs":       true,
	"exec":             true,
	"ask":              true,
	"chat":             true,
	"edit":             true,
	"image":            true,
	"search":           true,
	"theme":            true,
	"tools":            true,
	"agents":           true,
	"skills":           true,
	"agents_md":        true,

	"diagnostics.enabled": true,
	"diagnostics.dir":     true,

	"debug_logs.enabled": true,
	"debug_logs.dir":     true,

	"sessions":              true,
	"sessions.enabled":      true,
	"sessions.max_age_days": true,
	"sessions.max_count":    true,

	"exec.provider":     true,
	"exec.model":        true,
	"exec.suggestions":  true,
	"exec.instructions": true,

	"ask.provider":     true,
	"ask.model":        true,
	"ask.instructions": true,
	"ask.max_turns":    true,

	"chat.provider":     true,
	"chat.model":        true,
	"chat.instructions": true,
	"chat.max_turns":    true,

	"edit.provider":          true,
	"edit.model":             true,
	"edit.instructions":      true,
	"edit.show_line_numbers": true,
	"edit.context_lines":     true,
	"edit.editor":            true,
	"edit.diff_format":       true,

	"image.provider":           true,
	"image.output_dir":         true,
	"image.gemini":             true,
	"image.gemini.api_key":     true,
	"image.gemini.model":       true,
	"image.openai":             true,
	"image.openai.api_key":     true,
	"image.openai.model":       true,
	"image.xai":                true,
	"image.xai.api_key":        true,
	"image.xai.model":          true,
	"image.flux":               true,
	"image.flux.api_key":       true,
	"image.flux.model":         true,
	"image.openrouter":         true,
	"image.openrouter.api_key": true,
	"image.openrouter.model":   true,
	"image.debug":              true,
	"image.debug.delay":        true,

	"search.provider":       true,
	"search.force_external": true,
	"search.exa":            true,
	"search.exa.api_key":    true,
	"search.brave":          true,
	"search.brave.api_key":  true,
	"search.google":         true,
	"search.google.api_key": true,
	"search.google.cx":      true,

	"theme.primary":   true,
	"theme.secondary": true,
	"theme.success":   true,
	"theme.error":     true,
	"theme.warning":   true,
	"theme.muted":     true,
	"theme.text":      true,
	"theme.spinner":   true,

	"tools.enabled":            true,
	"tools.read_dirs":          true,
	"tools.write_dirs":         true,
	"tools.shell_allow":        true,
	"tools.shell_auto_run":     true,
	"tools.shell_auto_run_env": true,
	"tools.shell_non_tty_env":  true,
	"tools.image_provider":     true,

	"agents.use_builtin":  true,
	"agents.search_paths": true,
	"agents.preferences":  true,

	"skills.enabled":                 true,
	"skills.auto_invoke":             true,
	"skills.metadata_budget_tokens":  true,
	"skills.max_active":              true,
	"skills.include_project_skills":  true,
	"skills.include_ecosystem_paths": true,
	"skills.always_enabled":          true,
	"skills.never_auto":              true,

	"agents_md.enabled": true,
}

KnownKeys contains all valid configuration key paths Dynamic keys like providers.* and image.* have their subkeys validated separately

View Source
var KnownProviderKeys = map[string]bool{
	"type":              true,
	"api_key":           true,
	"model":             true,
	"models":            true,
	"credentials":       true,
	"use_native_search": true,
	"base_url":          true,
	"url":               true,
	"app_url":           true,
	"app_title":         true,
}

KnownProviderKeys contains valid keys for provider configurations

Functions

func ClearAgentPreferences added in v0.0.42

func ClearAgentPreferences(agentName string) error

ClearAgentPreferences removes all preferences for a specific agent.

func Exists

func Exists() bool

Exists returns true if a config file exists

func GetBuiltInProviderNames added in v0.0.29

func GetBuiltInProviderNames() []string

GetBuiltInProviderNames returns a list of all built-in provider type names.

func GetConfigDir

func GetConfigDir() (string, error)

GetConfigDir returns the XDG config directory for term-llm. Uses $XDG_CONFIG_HOME if set, otherwise ~/.config

func GetConfigPath

func GetConfigPath() (string, error)

GetConfigPath returns the path where the config file should be located

func GetDebugLogsDir added in v0.0.34

func GetDebugLogsDir() string

GetDebugLogsDir returns the XDG data directory for term-llm debug logs. Uses $XDG_DATA_HOME if set, otherwise ~/.local/share

func GetDefaults added in v0.0.38

func GetDefaults() map[string]any

GetDefaults returns a map of all default configuration values

func GetDiagnosticsDir added in v0.0.11

func GetDiagnosticsDir() string

GetDiagnosticsDir returns the XDG data directory for term-llm diagnostics. Uses $XDG_DATA_HOME if set, otherwise ~/.local/share

func IsKnownKey added in v0.0.38

func IsKnownKey(keyPath string) bool

IsKnownKey checks if a key path is a known configuration key For provider keys (providers.*), validates the sub-keys For agent preference keys (agents.preferences.*), validates the sub-keys

func NeedsSetup

func NeedsSetup() bool

NeedsSetup returns true if config file doesn't exist

func ParseProviderModel added in v0.0.42

func ParseProviderModel(s string) (provider, model string)

ParseProviderModel splits "provider:model" into separate parts. Returns (provider, model). Model will be empty if not specified. This is a simple version that doesn't validate against configured providers.

func ResolveValue added in v0.0.15

func ResolveValue(value string) (string, error)

ResolveValue handles magic URL schemes in config values: - op://vault/item/field -> 1Password secret (via `op read`) - srv://record/path -> DNS SRV lookup + path (always HTTPS) - $(...) -> shell command output - ${VAR} or $VAR -> environment variable - literal string -> returned as-is

func Save

func Save(cfg *Config) error

Save writes the config to disk

func SetAgentPreference added in v0.0.42

func SetAgentPreference(agentName, key, value string) ([]string, error)

SetAgentPreference sets a preference for a specific agent. Uses viper to merge with existing config. Supports "provider:model" format for the provider key (e.g., "chatgpt:gpt-5.2-codex"). Returns a list of keys that were set (may be multiple for provider:model format).

Types

type AgentPreference added in v0.0.42

type AgentPreference struct {
	// Model preferences
	Provider string `mapstructure:"provider,omitempty" yaml:"provider,omitempty"`
	Model    string `mapstructure:"model,omitempty" yaml:"model,omitempty"`

	// Tool configuration
	ToolsEnabled  []string `mapstructure:"tools_enabled,omitempty" yaml:"tools_enabled,omitempty"`
	ToolsDisabled []string `mapstructure:"tools_disabled,omitempty" yaml:"tools_disabled,omitempty"`

	// Shell settings
	ShellAllow   []string `mapstructure:"shell_allow,omitempty" yaml:"shell_allow,omitempty"`
	ShellAutoRun *bool    `mapstructure:"shell_auto_run,omitempty" yaml:"shell_auto_run,omitempty"`

	// Spawn settings
	SpawnMaxParallel   *int     `mapstructure:"spawn_max_parallel,omitempty" yaml:"spawn_max_parallel,omitempty"`
	SpawnMaxDepth      *int     `mapstructure:"spawn_max_depth,omitempty" yaml:"spawn_max_depth,omitempty"`
	SpawnTimeout       *int     `mapstructure:"spawn_timeout,omitempty" yaml:"spawn_timeout,omitempty"`
	SpawnAllowedAgents []string `mapstructure:"spawn_allowed_agents,omitempty" yaml:"spawn_allowed_agents,omitempty"`

	// Behavior
	MaxTurns *int  `mapstructure:"max_turns,omitempty" yaml:"max_turns,omitempty"`
	Search   *bool `mapstructure:"search,omitempty" yaml:"search,omitempty"`
}

AgentPreference allows overriding agent settings via config.yaml. All fields are optional - only set fields override the agent's defaults.

func GetAgentPreference added in v0.0.42

func GetAgentPreference(agentName string) (AgentPreference, bool)

GetAgentPreference returns the preferences for a specific agent.

type AgentsConfig added in v0.0.33

type AgentsConfig struct {
	UseBuiltin  bool                       `mapstructure:"use_builtin"`  // Enable built-in agents (default true)
	SearchPaths []string                   `mapstructure:"search_paths"` // Additional directories to search for agents
	Preferences map[string]AgentPreference `mapstructure:"preferences"`  // Per-agent preference overrides
}

AgentsConfig configures the agent system

type AgentsMdConfig added in v0.0.37

type AgentsMdConfig struct {
	Enabled bool `mapstructure:"enabled"` // Load AGENTS.md into system prompt
}

AgentsMdConfig configures optional AGENTS.md loading

type AskConfig

type AskConfig struct {
	Provider     string `mapstructure:"provider"`     // Override provider for ask only
	Model        string `mapstructure:"model"`        // Override model for ask only
	Instructions string `mapstructure:"instructions"` // Custom system prompt for ask
	MaxTurns     int    `mapstructure:"max_turns"`    // Max agentic turns (default 20)
}

type ChatConfig added in v0.0.29

type ChatConfig struct {
	Provider     string `mapstructure:"provider"`     // Override provider for chat only
	Model        string `mapstructure:"model"`        // Override model for chat only
	Instructions string `mapstructure:"instructions"` // Custom system prompt for chat
	MaxTurns     int    `mapstructure:"max_turns"`    // Max agentic turns (default 200)
}

type Config

type Config struct {
	DefaultProvider string                    `mapstructure:"default_provider"`
	Providers       map[string]ProviderConfig `mapstructure:"providers"`
	Diagnostics     DiagnosticsConfig         `mapstructure:"diagnostics"`
	DebugLogs       DebugLogsConfig           `mapstructure:"debug_logs"`
	Sessions        SessionsConfig            `mapstructure:"sessions"`
	Exec            ExecConfig                `mapstructure:"exec"`
	Ask             AskConfig                 `mapstructure:"ask"`
	Chat            ChatConfig                `mapstructure:"chat"`
	Edit            EditConfig                `mapstructure:"edit"`
	Image           ImageConfig               `mapstructure:"image"`
	Search          SearchConfig              `mapstructure:"search"`
	Theme           ThemeConfig               `mapstructure:"theme"`
	Tools           ToolsConfig               `mapstructure:"tools"`
	Agents          AgentsConfig              `mapstructure:"agents"`
	Skills          SkillsConfig              `mapstructure:"skills"`
	AgentsMd        AgentsMdConfig            `mapstructure:"agents_md"`
}

func Load

func Load() (*Config, error)

func (*Config) ApplyOverrides added in v0.0.6

func (c *Config) ApplyOverrides(provider, model string)

ApplyOverrides applies provider and model overrides to the config. If provider is non-empty, it overrides the global provider. If model is non-empty, it overrides the model for the active provider.

func (*Config) GetActiveProviderConfig added in v0.0.15

func (c *Config) GetActiveProviderConfig() *ProviderConfig

GetActiveProviderConfig returns the config for the default provider. Returns nil if the default provider is not configured.

func (*Config) GetProviderConfig added in v0.0.15

func (c *Config) GetProviderConfig(name string) *ProviderConfig

GetProviderConfig returns the config for the specified provider name. Returns nil if the provider is not configured.

type DebugLogsConfig added in v0.0.34

type DebugLogsConfig struct {
	Enabled bool   `mapstructure:"enabled"` // Enable debug logging
	Dir     string `mapstructure:"dir"`     // Override default directory (defaults to ~/.local/share/term-llm/debug/)
}

DebugLogsConfig configures debug logging of LLM requests and responses

type DiagnosticsConfig added in v0.0.11

type DiagnosticsConfig struct {
	Enabled bool   `mapstructure:"enabled"` // Enable diagnostic data collection
	Dir     string `mapstructure:"dir"`     // Override default directory
}

DiagnosticsConfig configures diagnostic data collection

type EditConfig added in v0.0.5

type EditConfig struct {
	Provider        string `mapstructure:"provider"`          // Override provider for edit
	Model           string `mapstructure:"model"`             // Override model for edit
	Instructions    string `mapstructure:"instructions"`      // Custom instructions for edits
	ShowLineNumbers bool   `mapstructure:"show_line_numbers"` // Show line numbers in diff
	ContextLines    int    `mapstructure:"context_lines"`     // Lines of context in diff
	Editor          string `mapstructure:"editor"`            // Override $EDITOR
	DiffFormat      string `mapstructure:"diff_format"`       // "auto", "udiff", or "replace" (default: auto)
}

type ExecConfig

type ExecConfig struct {
	Provider     string `mapstructure:"provider"`     // Override provider for exec
	Model        string `mapstructure:"model"`        // Override model for exec
	Suggestions  int    `mapstructure:"suggestions"`  // Number of command suggestions (default 3)
	Instructions string `mapstructure:"instructions"` // Custom context for suggestions
}

type ImageConfig added in v0.0.3

type ImageConfig struct {
	Provider   string                `mapstructure:"provider"`   // default image provider: gemini, openai, xai, flux, openrouter, debug
	OutputDir  string                `mapstructure:"output_dir"` // default save directory
	Gemini     ImageGeminiConfig     `mapstructure:"gemini"`
	OpenAI     ImageOpenAIConfig     `mapstructure:"openai"`
	XAI        ImageXAIConfig        `mapstructure:"xai"`
	Flux       ImageFluxConfig       `mapstructure:"flux"`
	OpenRouter ImageOpenRouterConfig `mapstructure:"openrouter"`
	Debug      ImageDebugConfig      `mapstructure:"debug"`
}

ImageConfig configures image generation settings

type ImageDebugConfig added in v0.0.39

type ImageDebugConfig struct {
	Delay float64 `mapstructure:"delay"` // delay in seconds before returning (e.g., 1.5)
}

ImageDebugConfig configures the debug image provider (local random images)

type ImageFluxConfig added in v0.0.3

type ImageFluxConfig struct {
	APIKey string `mapstructure:"api_key"`
	Model  string `mapstructure:"model"` // flux-2-pro for generation, flux-kontext-pro for editing
}

ImageFluxConfig configures Flux (Black Forest Labs) image generation

type ImageGeminiConfig added in v0.0.3

type ImageGeminiConfig struct {
	APIKey string `mapstructure:"api_key"`
	Model  string `mapstructure:"model"`
}

ImageGeminiConfig configures Gemini image generation

type ImageOpenAIConfig added in v0.0.3

type ImageOpenAIConfig struct {
	APIKey string `mapstructure:"api_key"`
	Model  string `mapstructure:"model"`
}

ImageOpenAIConfig configures OpenAI image generation

type ImageOpenRouterConfig added in v0.0.24

type ImageOpenRouterConfig struct {
	APIKey string `mapstructure:"api_key"`
	Model  string `mapstructure:"model"` // e.g., google/gemini-2.5-flash-image
}

ImageOpenRouterConfig configures OpenRouter image generation

type ImageXAIConfig added in v0.0.31

type ImageXAIConfig struct {
	APIKey string `mapstructure:"api_key"`
	Model  string `mapstructure:"model"` // grok-2-image or grok-2-image-1212
}

ImageXAIConfig configures xAI (Grok) image generation

type ProviderConfig added in v0.0.15

type ProviderConfig struct {
	// Type of provider - inferred from key name for built-ins, required for custom
	Type ProviderType `mapstructure:"type"`

	// Common fields
	APIKey      string   `mapstructure:"api_key"`
	Model       string   `mapstructure:"model"`
	Models      []string `mapstructure:"models"`      // Available models for autocomplete
	Credentials string   `mapstructure:"credentials"` // "api_key", "codex", "gemini-cli"

	// Search behavior - nil means auto (use native if available)
	UseNativeSearch *bool `mapstructure:"use_native_search"`

	// OpenAI-compatible specific
	BaseURL string `mapstructure:"base_url"` // Base URL - /chat/completions is appended
	URL     string `mapstructure:"url"`      // Full URL - used as-is without appending endpoint

	// OpenRouter specific
	AppURL   string `mapstructure:"app_url"`
	AppTitle string `mapstructure:"app_title"`

	// Runtime fields (populated after credential resolution)
	ResolvedAPIKey string                              `mapstructure:"-"`
	AccountID      string                              `mapstructure:"-"`
	OAuthCreds     *credentials.GeminiOAuthCredentials `mapstructure:"-"`
	ResolvedURL    string                              `mapstructure:"-"` // Resolved URL (after srv:// lookup)
	// contains filtered or unexported fields
}

ProviderConfig is a unified configuration for any provider

func (*ProviderConfig) ResolveForInference added in v0.0.15

func (cfg *ProviderConfig) ResolveForInference() error

ResolveForInference performs lazy resolution of expensive config values (op://, srv://, $()). Call this before creating a provider for inference.

type ProviderType added in v0.0.15

type ProviderType string

ProviderType defines the supported provider implementations

const (
	ProviderTypeAnthropic    ProviderType = "anthropic"
	ProviderTypeOpenAI       ProviderType = "openai"
	ProviderTypeChatGPT      ProviderType = "chatgpt"
	ProviderTypeCopilot      ProviderType = "copilot"
	ProviderTypeGemini       ProviderType = "gemini"
	ProviderTypeGeminiCLI    ProviderType = "gemini-cli"
	ProviderTypeOpenRouter   ProviderType = "openrouter"
	ProviderTypeZen          ProviderType = "zen"
	ProviderTypeClaudeBin    ProviderType = "claude-bin"
	ProviderTypeOpenAICompat ProviderType = "openai_compatible"
	ProviderTypeXAI          ProviderType = "xai"
)

func InferProviderType added in v0.0.15

func InferProviderType(name string, explicit ProviderType) ProviderType

InferProviderType returns the provider type for a given provider name Explicit type takes precedence, then built-in names, then defaults to openai_compatible

type SearchBraveConfig added in v0.0.22

type SearchBraveConfig struct {
	APIKey string `mapstructure:"api_key"`
}

SearchBraveConfig configures Brave search

type SearchConfig added in v0.0.22

type SearchConfig struct {
	Provider      string             `mapstructure:"provider"`       // exa, brave, google, duckduckgo (default)
	ForceExternal bool               `mapstructure:"force_external"` // force external search for all providers
	Exa           SearchExaConfig    `mapstructure:"exa"`
	Brave         SearchBraveConfig  `mapstructure:"brave"`
	Google        SearchGoogleConfig `mapstructure:"google"`
}

SearchConfig configures web search providers

type SearchExaConfig added in v0.0.22

type SearchExaConfig struct {
	APIKey string `mapstructure:"api_key"`
}

SearchExaConfig configures Exa search

type SearchGoogleConfig added in v0.0.22

type SearchGoogleConfig struct {
	APIKey string `mapstructure:"api_key"`
	CX     string `mapstructure:"cx"` // Custom Search Engine ID
}

SearchGoogleConfig configures Google Custom Search

type SessionsConfig added in v0.0.39

type SessionsConfig struct {
	Enabled    bool `mapstructure:"enabled"`      // Master switch - set to false to disable all session storage
	MaxAgeDays int  `mapstructure:"max_age_days"` // Auto-delete sessions older than N days (0=never)
	MaxCount   int  `mapstructure:"max_count"`    // Keep at most N sessions, delete oldest (0=unlimited)
}

SessionsConfig configures session storage

type SkillsConfig added in v0.0.37

type SkillsConfig struct {
	Enabled              bool `mapstructure:"enabled"`                // Enable the skills system
	AutoInvoke           bool `mapstructure:"auto_invoke"`            // Allow model-driven activation
	MetadataBudgetTokens int  `mapstructure:"metadata_budget_tokens"` // Max tokens for skill metadata
	MaxActive            int  `mapstructure:"max_active"`             // Max skills in metadata injection

	IncludeProjectSkills  bool `mapstructure:"include_project_skills"`  // Discover from project-local paths
	IncludeEcosystemPaths bool `mapstructure:"include_ecosystem_paths"` // Include ~/.codex/skills, ~/.claude/skills, ~/.gemini/skills, .skills/

	AlwaysEnabled []string `mapstructure:"always_enabled"` // Always include in metadata
	NeverAuto     []string `mapstructure:"never_auto"`     // Must be explicit activation
}

SkillsConfig configures the Agent Skills system

type ThemeConfig

type ThemeConfig struct {
	Primary   string `mapstructure:"primary"`   // main accent (commands, highlights)
	Secondary string `mapstructure:"secondary"` // secondary accent (headers, borders)
	Success   string `mapstructure:"success"`   // success states
	Error     string `mapstructure:"error"`     // error states
	Warning   string `mapstructure:"warning"`   // warnings
	Muted     string `mapstructure:"muted"`     // dimmed text
	Text      string `mapstructure:"text"`      // primary text
	Spinner   string `mapstructure:"spinner"`   // loading spinner
}

ThemeConfig allows customization of UI colors Colors can be ANSI color numbers (0-255) or hex codes (#RRGGBB)

type ToolsConfig added in v0.0.25

type ToolsConfig struct {
	Enabled         []string `mapstructure:"enabled"`            // Enabled tool names (CLI names)
	ReadDirs        []string `mapstructure:"read_dirs"`          // Directories for read operations
	WriteDirs       []string `mapstructure:"write_dirs"`         // Directories for write operations
	ShellAllow      []string `mapstructure:"shell_allow"`        // Shell command patterns
	ShellAutoRun    bool     `mapstructure:"shell_auto_run"`     // Auto-approve matching shell
	ShellAutoRunEnv string   `mapstructure:"shell_auto_run_env"` // Env var required for auto-run
	ShellNonTTYEnv  string   `mapstructure:"shell_non_tty_env"`  // Env var for non-TTY execution
	ImageProvider   string   `mapstructure:"image_provider"`     // Override for image provider
}

ToolsConfig configures the local tool system

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL