config

package
v1.1.38 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultSystemPrompt = `You are ggcode, an AI coding assistant running in a terminal.

## Core behavior
- Be precise, concise, and proactive.
- Prefer small, reversible changes over broad rewrites.
- Read before you edit, and inspect results before claiming success.
- Use ` + "`ask_user`" + ` only when a material clarification is needed, the answer will change what you do next, and there is no safe best guess from the current context.
- If something is uncertain or incomplete, say so plainly instead of guessing.

## Tool routing
- For repository inspection, prefer built-in file and search tools first: ` + "`read_file`" + `, ` + "`list_directory`" + `, ` + "`search_files`" + `, and ` + "`glob`" + `. Do not reach for shell commands when a built-in tool is clearer.
- Use ` + "`edit_file`" + ` for targeted edits and ` + "`write_file`" + ` for creating or replacing whole files.
- Use ` + "`run_command`" + ` for one-shot execution such as builds, tests, git commands, and focused repro steps.
- Use the async command tools (` + "`start_command`" + `, ` + "`read_command_output`" + `, ` + "`wait_command`" + `, ` + "`write_command_input`" + `, ` + "`stop_command`" + `, ` + "`list_commands`" + `) for long-running, streaming, or interactive commands.
- Use ` + "`list_mcp_capabilities`" + ` before assuming MCP-backed browser, external service, or prompt/resource capabilities are available.
- Use the ` + "`skill`" + ` tool when a listed skill clearly matches the task; apply the returned workflow and then continue the task.

## Working style
- Prefer the smallest concrete check that proves the requested behavior.
- Batch related inspections or validations into a single assistant turn when the needed tool calls can be chosen together. Avoid one-tool-at-a-time exploration when several checks are obviously needed.
- Compare expected versus actual behavior when debugging; do not stack speculative fixes.
- Do not emit progress-only assistant messages while meaningful work remains. Continue directly to the next useful tool calls when you already know them.
- Treat ` + "`todo_write`" + ` as optional bookkeeping for genuinely multi-step work. Do not update it after every micro-step; only write todos when the task spans multiple meaningful phases or the plan materially changes.
- Keep user-facing summaries short and useful.
- Use ` + "`@mentions`" + ` when referencing files for context.

## Memory
- Use ` + "`save_memory`" + ` for durable patterns and decisions that will matter later.
- Check project memory files such as ` + "`GGCODE.md`" + `, ` + "`AGENTS.md`" + `, ` + "`CLAUDE.md`" + `, and ` + "`COPILOT.md`" + ` for project-specific guidance.
- Learn from stable user preferences across sessions.
`

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, language 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 ExpandEnvRecursiveWithLookup added in v1.0.25

func ExpandEnvRecursiveWithLookup(m map[string]interface{}, lookup envLookupFunc) map[string]interface{}

func ExpandEnvWithLookup added in v1.0.25

func ExpandEnvWithLookup(s string, lookup envLookupFunc) string

func HomeDir

func HomeDir() string

HomeDir returns the user's home directory.

func IgnorePlaintextAPIKeyWarning added in v1.0.25

func IgnorePlaintextAPIKeyWarning(configPath string) error

func IsPlaintextAPIKeyWarningIgnored added in v1.0.25

func IsPlaintextAPIKeyWarningIgnored(configPath string) (bool, error)

func PreferredAPIKeyEnvVar added in v1.1.23

func PreferredAPIKeyEnvVar(vendor, endpoint string, vendorAPIKey, endpointAPIKey string) string

func PreferredEndpointAPIKeyEnvVar added in v1.1.23

func PreferredEndpointAPIKeyEnvVar(vendor, endpoint string) string

func PreferredVendorAPIKeyEnvVar added in v1.1.23

func PreferredVendorAPIKeyEnvVar(vendor string) string

Types

type APIKeyFinding added in v1.0.25

type APIKeyFinding struct {
	Vendor   string
	Endpoint string
	EnvVar   string
}

func DetectPlaintextAPIKeys added in v1.0.25

func DetectPlaintextAPIKeys(path string) ([]APIKeyFinding, error)

type Config

type Config struct {
	Vendor        string                    `yaml:"vendor"`
	Endpoint      string                    `yaml:"endpoint"`
	Model         string                    `yaml:"model"`
	Language      string                    `yaml:"language"`
	UI            UIConfig                  `yaml:"ui,omitempty"`
	IM            IMConfig                  `yaml:"im,omitempty"`
	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"`
	Impersonation ImpersonationConfig       `yaml:"impersonation,omitempty"`
	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) AddIMAdapter added in v1.1.32

func (c *Config) AddIMAdapter(name string, adapter IMAdapterConfig) error

func (*Config) AddIMTarget added in v1.1.32

func (c *Config) AddIMTarget(adapterName string, target IMTargetConfig) error

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) RemoveIMAdapter added in v1.1.34

func (c *Config) RemoveIMAdapter(name string) error

RemoveIMAdapter removes an IM adapter from the configuration.

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) SaveDefaultModePreference added in v1.1.18

func (c *Config) SaveDefaultModePreference(mode string) error

func (*Config) SaveImpersonation added in v1.1.34

func (c *Config) SaveImpersonation(imp ImpersonationConfig) error

SaveImpersonation persists impersonation settings to the config file.

func (*Config) SaveLanguagePreference

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

func (*Config) SaveSidebarPreference added in v1.1.6

func (c *Config) SaveSidebarPreference(visible bool) 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. The key is stored as an environment variable reference (e.g. ${ZAI_API_KEY}) rather than plaintext, and the caller should set the actual value in the shell environment (os.Setenv) so the current session can use it immediately.

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) SetIMAdapterEnabled added in v1.1.34

func (c *Config) SetIMAdapterEnabled(name string, enabled bool) error

SetIMAdapterEnabled toggles the enabled state of an IM adapter.

func (*Config) SetIMAdapterExtra added in v1.1.34

func (c *Config) SetIMAdapterExtra(name, key, value string) error

SetIMAdapterExtra sets a single key in the adapter's Extra map.

func (*Config) SidebarVisible added in v1.1.6

func (c *Config) SidebarVisible() bool

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"`
	AuthType       string   `yaml:"auth_type,omitempty"`
	APIKey         string   `yaml:"api_key,omitempty"`
	ContextWindow  int      `yaml:"context_window,omitempty"`
	MaxTokens      int      `yaml:"max_tokens"`
	SupportsVision *bool    `yaml:"supports_vision,omitempty"`
	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 IMAdapterConfig added in v1.1.32

type IMAdapterConfig struct {
	Enabled   bool                   `yaml:"enabled,omitempty"`
	Platform  string                 `yaml:"platform,omitempty"`
	Transport string                 `yaml:"transport,omitempty"`
	Command   string                 `yaml:"command,omitempty"`
	Args      []string               `yaml:"args,omitempty"`
	Env       map[string]string      `yaml:"env,omitempty"`
	AllowFrom []string               `yaml:"allow_from,omitempty"`
	Targets   []IMTargetConfig       `yaml:"targets,omitempty"`
	Extra     map[string]interface{} `yaml:"extra,omitempty"`
}

type IMConfig added in v1.1.32

type IMConfig struct {
	Enabled             bool                       `yaml:"enabled,omitempty"`
	ActiveSessionPolicy string                     `yaml:"active_session_policy,omitempty"`
	RequireLocalSession *bool                      `yaml:"require_local_session,omitempty"`
	Streaming           IMStreamingConfig          `yaml:"streaming,omitempty"`
	STT                 IMSTTConfig                `yaml:"stt,omitempty"`
	Adapters            map[string]IMAdapterConfig `yaml:"adapters,omitempty"`
}

type IMSTTConfig added in v1.1.32

type IMSTTConfig struct {
	Provider string `yaml:"provider,omitempty"`
	BaseURL  string `yaml:"base_url,omitempty"`
	APIKey   string `yaml:"api_key,omitempty"`
	Model    string `yaml:"model,omitempty"`
}

type IMStreamingConfig added in v1.1.32

type IMStreamingConfig struct {
	Enabled         bool    `yaml:"enabled,omitempty"`
	Transport       string  `yaml:"transport,omitempty"`
	EditIntervalSec float64 `yaml:"edit_interval_sec,omitempty"`
	BufferThreshold int     `yaml:"buffer_threshold,omitempty"`
	Cursor          string  `yaml:"cursor,omitempty"`
}

type IMTargetConfig added in v1.1.32

type IMTargetConfig struct {
	ID       string            `yaml:"id,omitempty"`
	Label    string            `yaml:"label,omitempty"`
	Channel  string            `yaml:"channel,omitempty"`
	Thread   string            `yaml:"thread,omitempty"`
	Metadata map[string]string `yaml:"metadata,omitempty"`
}

type ImpersonationConfig added in v1.1.34

type ImpersonationConfig struct {
	Preset        string            `yaml:"preset,omitempty"`
	CustomVersion string            `yaml:"custom_version,omitempty"`
	CustomHeaders map[string]string `yaml:"custom_headers,omitempty"`
}

ImpersonationConfig holds persisted impersonation settings.

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"`
	OAuthClientID     string            `yaml:"oauth_client_id,omitempty" json:"oauth_client_id,omitempty"`
	OAuthClientSecret string            `yaml:"oauth_client_secret,omitempty" json:"oauth_client_secret,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
	AuthType       string
	BaseURL        string
	APIKey         string
	EnterpriseURL  string
	Model          string
	ContextWindow  int
	MaxTokens      int
	SupportsVision bool
	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 UIConfig added in v1.1.6

type UIConfig struct {
	SidebarVisible *bool `yaml:"sidebar_visible,omitempty"`
}

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