config

package
v1.0.21 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultSystemPrompt = `` /* 1386-byte string literal not displayed */

DefaultSystemPrompt is the built-in system prompt used when no custom system_prompt is set.

Variables

This section is empty.

Functions

func BuildSystemPrompt

func BuildSystemPrompt(basePrompt, workingDir string, toolNames []string, gitStatus string, customCmds []string) string

BuildSystemPrompt enhances the base system prompt with runtime context.

func ConfigDir

func ConfigDir() string

ConfigDir returns ~/.ggcode

func ConfigPath

func ConfigPath() string

ConfigPath returns the default config file path.

func ExpandEnv

func ExpandEnv(s string) string

ExpandEnv replaces ${VAR} patterns in a string with environment variable values. If the variable is not set, the pattern is left unchanged.

func ExpandEnvRecursive

func ExpandEnvRecursive(m map[string]interface{}) map[string]interface{}

ExpandEnvRecursive expands ${VAR} in all string values of a map recursively.

func HomeDir

func HomeDir() string

HomeDir returns the user's home directory.

Types

type Config

type Config struct {
	Vendor        string                    `yaml:"vendor"`
	Endpoint      string                    `yaml:"endpoint"`
	Model         string                    `yaml:"model"`
	Language      string                    `yaml:"language"`
	SystemPrompt  string                    `yaml:"system_prompt"`
	Vendors       map[string]VendorConfig   `yaml:"vendors"`
	AllowedDirs   []string                  `yaml:"allowed_dirs"`
	MaxIterations int                       `yaml:"max_iterations"`
	ToolPerms     map[string]ToolPermission `yaml:"tool_permissions"`
	Plugins       []PluginConfigEntry       `yaml:"plugins"`
	MCPServers    []MCPServerConfig         `yaml:"mcp_servers"`
	Hooks         hooks.HookConfig          `yaml:"hooks"`
	DefaultMode   string                    `yaml:"default_mode"`
	SubAgents     SubAgentConfig            `yaml:"subagents"`
	FilePath      string                    `yaml:"-"`
	FirstRun      bool                      `yaml:"-"`
}

Config is the top-level configuration.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a config with sensible defaults.

func Load

func Load(path string) (*Config, error)

Load reads config from the given path. If the file doesn't exist, returns defaults.

func (*Config) ActiveEndpointConfig

func (c *Config) ActiveEndpointConfig() *EndpointConfig

ActiveEndpointConfig returns a copy of the active endpoint config.

func (*Config) EndpointNames

func (c *Config) EndpointNames(vendor string) []string

EndpointNames returns configured endpoints for the given vendor in a stable order.

func (*Config) ExpandAllowedDirs

func (c *Config) ExpandAllowedDirs(baseDir string) []string

ExpandAllowedDirs resolves allowed_dirs entries relative to baseDir.

func (*Config) RemoveMCPServer

func (c *Config) RemoveMCPServer(name string) bool

func (*Config) ResolveActiveEndpoint

func (c *Config) ResolveActiveEndpoint() (*ResolvedEndpoint, error)

ResolveActiveEndpoint resolves the selected vendor + endpoint into runtime settings.

func (*Config) ResolveEndpoint added in v1.0.12

func (c *Config) ResolveEndpoint(vendor, endpoint string) (*ResolvedEndpoint, error)

ResolveEndpoint resolves the given vendor + endpoint into runtime settings.

func (*Config) Save

func (c *Config) Save() error

Save persists the config to its configured file path.

func (*Config) SaveLanguagePreference

func (c *Config) SaveLanguagePreference(lang string) error

func (*Config) SetActiveSelection

func (c *Config) SetActiveSelection(vendor, endpoint, model string) error

SetActiveSelection updates the current vendor, endpoint, and model.

func (*Config) SetEndpointAPIKey

func (c *Config) SetEndpointAPIKey(vendor, endpoint, apiKey string, vendorScoped bool) error

SetEndpointAPIKey updates the active endpoint or vendor-level API key.

func (*Config) SetEndpointModels added in v1.0.12

func (c *Config) SetEndpointModels(vendor, endpoint string, models []string) error

SetEndpointModels replaces the known models for a configured endpoint while preserving active selections.

func (*Config) UpsertMCPServer

func (c *Config) UpsertMCPServer(server MCPServerConfig) (replaced bool)

func (*Config) Validate

func (c *Config) Validate() error

Validate checks for invalid core configuration values that should fail fast.

func (*Config) VendorNames

func (c *Config) VendorNames() []string

VendorNames returns configured vendors in a stable order.

type EndpointConfig

type EndpointConfig struct {
	DisplayName   string   `yaml:"display_name"`
	Protocol      string   `yaml:"protocol"`
	BaseURL       string   `yaml:"base_url"`
	APIKey        string   `yaml:"api_key,omitempty"`
	ContextWindow int      `yaml:"context_window,omitempty"`
	MaxTokens     int      `yaml:"max_tokens"`
	DefaultModel  string   `yaml:"default_model,omitempty"`
	SelectedModel string   `yaml:"selected_model,omitempty"`
	Models        []string `yaml:"models,omitempty"`
	Tags          []string `yaml:"tags,omitempty"`
}

EndpointConfig describes a concrete vendor endpoint that maps to one protocol.

type MCPServerConfig

type MCPServerConfig struct {
	Name       string            `yaml:"name"`
	Type       string            `yaml:"type,omitempty"`
	Command    string            `yaml:"command,omitempty"`
	Args       []string          `yaml:"args,omitempty"`
	Env        map[string]string `yaml:"env,omitempty"`
	URL        string            `yaml:"url,omitempty"`
	Headers    map[string]string `yaml:"headers,omitempty"`
	Source     string            `yaml:"-"`
	OriginPath string            `yaml:"-"`
	Migrated   bool              `yaml:"-"`
}

MCPServerConfig defines an MCP server to connect to.

type PluginCommandConfig

type PluginCommandConfig struct {
	Name        string   `yaml:"name"`
	Description string   `yaml:"description"`
	Execute     string   `yaml:"execute"`
	Args        []string `yaml:"args"`
}

PluginCommandConfig describes a single command tool within a plugin.

type PluginConfigEntry

type PluginConfigEntry struct {
	Name     string                 `yaml:"name"`
	Path     string                 `yaml:"path"`
	Type     string                 `yaml:"type"`
	Commands []PluginCommandConfig  `yaml:"commands"`
	Extra    map[string]interface{} `yaml:",inline"`
}

PluginConfigEntry describes a single plugin from the config file.

type ResolvedEndpoint

type ResolvedEndpoint struct {
	VendorID      string
	VendorName    string
	EndpointID    string
	EndpointName  string
	Protocol      string
	BaseURL       string
	APIKey        string
	Model         string
	ContextWindow int
	MaxTokens     int
	Models        []string
	Tags          []string
}

ResolvedEndpoint is the runtime selection after config inheritance is applied.

type SubAgentConfig

type SubAgentConfig struct {
	MaxConcurrent int           `yaml:"max_concurrent"`
	Timeout       time.Duration `yaml:"timeout"`
	ShowOutput    bool          `yaml:"show_output"`
}

SubAgentConfig holds sub-agent configuration.

type ToolPermission

type ToolPermission string

ToolPermission defines per-tool permission level in config.

const (
	ToolPermAsk   ToolPermission = "ask"
	ToolPermAllow ToolPermission = "allow"
	ToolPermDeny  ToolPermission = "deny"
)

type VendorConfig

type VendorConfig struct {
	DisplayName string                    `yaml:"display_name"`
	APIKey      string                    `yaml:"api_key,omitempty"`
	Endpoints   map[string]EndpointConfig `yaml:"endpoints"`
}

VendorConfig holds a real supplier plus its available endpoints.

Jump to

Keyboard shortcuts

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