config

package
v0.34.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package config implements centralized configuration management for GoDoctor. It defines typed schemas, provides built-in defaults, discovers and loads .godoctor.yaml files hierarchically, and performs schema validation.

Index

Constants

View Source
const (
	ToolGolangCILint = "golangci-lint"
	ToolModernize    = "modernize"
	ToolDeadcode     = "deadcode"
	ToolSelene       = "selene"
	ToolTestQuery    = "testquery"

	VersionLatest = "latest"

	DefaultTestQueryDB      = ".godoctor/testquery.db"
	DefaultWildcardPackages = "./..."
	DefaultTestLevel        = "basic"
	DefaultOutputText       = "text"
	DefaultFormatMarkdown   = "markdown"
	DefaultFormatTable      = "table"
	DefaultFormatJSON       = "json"
	DefaultListenAddr       = ":8080"
	AutofixTidy             = "tidy"
	ToolVet                 = "vet"
	ToolMutation            = "mutation"
	ToolStrict              = "strict"
	ToolGolangCILintKey     = "golangci_lint"
)

Tool binary names and default constants

Variables

This section is empty.

Functions

func FindConfigFile added in v0.34.0

func FindConfigFile(startDir string) string

FindConfigFile searches for a GoDoctor configuration file in the following order: 1. startDir and its ancestor hierarchy until a project boundary (.git or go.mod) or root is reached. 2. User home directory (~/.godoctor.yaml, ~/.godoctor.yml, ~/.config/godoctor/config.yaml). Returns empty string if no config file is found.

Types

type AutofixConfig added in v0.34.0

type AutofixConfig struct {
	Enabled   bool     `mapstructure:"enabled" yaml:"enabled" json:"enabled"`
	DryRun    bool     `mapstructure:"dry_run" yaml:"dry_run" json:"dry_run"`
	Order     []string `mapstructure:"order,omitempty" yaml:"order,omitempty"`
	ModTidy   bool     `mapstructure:"mod_tidy,omitempty" yaml:"mod_tidy,omitempty"`
	Modernize bool     `mapstructure:"modernize,omitempty" yaml:"modernize,omitempty"`
	Gofmt     bool     `mapstructure:"gofmt,omitempty" yaml:"gofmt,omitempty"`
	Deadcode  bool     `mapstructure:"deadcode,omitempty" yaml:"deadcode,omitempty"`
}

AutofixConfig configures automated remediation phases.

type BuildConfig added in v0.34.0

type BuildConfig struct {
	DefaultPackages string        `mapstructure:"default_packages" yaml:"default_packages"`
	Output          string        `mapstructure:"output,omitempty" yaml:"output,omitempty"`
	Tags            []string      `mapstructure:"tags,omitempty" yaml:"tags,omitempty"`
	Race            bool          `mapstructure:"race" yaml:"race" json:"race"`
	Trimpath        bool          `mapstructure:"trimpath" yaml:"trimpath" json:"trimpath"`
	Timeout         time.Duration `mapstructure:"timeout" yaml:"timeout" json:"timeout"`
	Flags           []string      `mapstructure:"flags,omitempty" yaml:"flags,omitempty"`
	AutoTidy        bool          `mapstructure:"auto_tidy,omitempty" yaml:"auto_tidy,omitempty"`
	AutoFormat      bool          `mapstructure:"auto_format,omitempty" yaml:"auto_format,omitempty"`
	AutoModernize   bool          `mapstructure:"auto_modernize,omitempty" yaml:"auto_modernize,omitempty"`
	RunLinter       bool          `mapstructure:"run_linter,omitempty" yaml:"run_linter,omitempty"`
	RunDeadcode     bool          `mapstructure:"run_deadcode,omitempty" yaml:"run_deadcode,omitempty"`
	RunTests        bool          `mapstructure:"run_tests,omitempty" yaml:"run_tests,omitempty"`
}

BuildConfig configures the smart_build pipeline.

type CLIConfig added in v0.34.0

type CLIConfig struct {
	Timeout       time.Duration `mapstructure:"timeout" yaml:"timeout" json:"timeout"`
	OutputFormat  string        `mapstructure:"output_format" yaml:"output_format" json:"output_format"`
	Color         bool          `mapstructure:"color" yaml:"color" json:"color"`
	LogLevel      string        `mapstructure:"log_level" yaml:"log_level" json:"log_level"`
	DefaultOutput string        `mapstructure:"default_output,omitempty" yaml:"default_output,omitempty"`
	Quiet         bool          `mapstructure:"quiet,omitempty" yaml:"quiet,omitempty"`
}

CLIConfig holds CLI-specific configuration settings.

type Config

type Config struct {
	Version      string             `mapstructure:"version" yaml:"version" json:"version"`
	CLI          CLIConfig          `mapstructure:"cli" yaml:"cli" json:"cli"`
	Server       ServerConfig       `mapstructure:"server" yaml:"server" json:"server"`
	SafeShell    SafeShellConfig    `mapstructure:"safeshell" yaml:"safeshell" json:"safeshell"`
	Instructions InstructionsConfig `mapstructure:"instructions" yaml:"instructions" json:"instructions"`
	Tools        ToolsConfig        `mapstructure:"tools" yaml:"tools" json:"tools"`
	Features     FeaturesConfig     `mapstructure:"features" yaml:"features" json:"features"`
	Build        BuildConfig        `mapstructure:"build" yaml:"build" json:"build"`
	Autofix      AutofixConfig      `mapstructure:"autofix" yaml:"autofix" json:"autofix"`
	Edit         EditConfig         `mapstructure:"edit" yaml:"edit" json:"edit"`
	Matching     MatchingConfig     `mapstructure:"matching" yaml:"matching" json:"matching"`
	Diagnostics  DiagnosticsConfig  `mapstructure:"diagnostics" yaml:"diagnostics" json:"diagnostics"`
	Test         TestConfig         `mapstructure:"test" yaml:"test" json:"test"`
	TestQuery    TestQueryConfig    `mapstructure:"testquery" yaml:"testquery" json:"testquery"`
	Docs         DocsConfig         `mapstructure:"docs" yaml:"docs" json:"docs"`
	LoadedFrom   string             `mapstructure:"-" yaml:"-" json:"-"`
}

Config represents the master configuration schema for GoDoctor.

func Load

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

Load reads and parses a configuration file from the given path. If configFile is empty, it returns the default configuration.

func LoadFromWorkspace added in v0.34.0

func LoadFromWorkspace(workspaceDir string) (*Config, error)

LoadFromWorkspace discovers and loads a configuration file for the given workspace directory. If no configuration file is found, it returns the default configuration without error.

func NewDefaultConfig added in v0.34.0

func NewDefaultConfig() *Config

NewDefaultConfig returns a fully populated Config struct with built-in production defaults matching RFC-0001.

func (*Config) GetLinterConfigPath added in v0.34.0

func (c *Config) GetLinterConfigPath(workspaceDir string) string

GetLinterConfigPath returns the resolved .golangci configuration file path for the workspace.

func (*Config) GetSeleneDBPath added in v0.34.0

func (c *Config) GetSeleneDBPath(workspaceDir string) string

GetSeleneDBPath returns the resolved database path for Selene testquery integration.

func (*Config) GetSeleneWorkers added in v0.34.0

func (c *Config) GetSeleneWorkers() int

GetSeleneWorkers returns the configured workers or runtime.GOMAXPROCS(0) if 0 or negative.

func (*Config) GetTestQueryDBPath added in v0.34.0

func (c *Config) GetTestQueryDBPath(workspaceDir string) string

GetTestQueryDBPath returns the resolved database path for testquery.db in the workspace.

func (*Config) GetTool added in v0.34.0

func (c *Config) GetTool(name string) ToolSpec

GetTool returns the ToolSpec for a given tool name or alias (case-insensitive). If the tool is not found, an empty ToolSpec is returned.

func (*Config) IsFeatureEnabled added in v0.34.0

func (c *Config) IsFeatureEnabled(featureName string) bool

IsFeatureEnabled queries whether a given feature flag is active.

func (*Config) IsSeleneTestQueryCompat added in v0.34.0

func (c *Config) IsSeleneTestQueryCompat() bool

IsSeleneTestQueryCompat returns whether testquery compatibility mode is enabled for Selene.

func (*Config) LookupTool added in v0.34.0

func (c *Config) LookupTool(name string) (ToolSpec, bool)

LookupTool returns the ToolSpec and a boolean indicating if the tool was found.

func (*Config) Validate added in v0.34.0

func (c *Config) Validate() error

Validate checks internal consistency and parameter bounds across all configuration sections.

type DiagnosticsConfig added in v0.34.0

type DiagnosticsConfig struct {
	CollectOnEdit          bool          `mapstructure:"collect_on_edit" yaml:"collect_on_edit"`
	VerificationScope      string        `mapstructure:"verification_scope" yaml:"verification_scope"`
	CheckCommand           []string      `mapstructure:"check_command" yaml:"check_command"`
	Timeout                time.Duration `mapstructure:"timeout" yaml:"timeout" json:"timeout"`
	EnableSuggestions      bool          `mapstructure:"enable_suggestions" yaml:"enable_suggestions"`
	LevenshteinSuggestions bool          `mapstructure:"levenshtein_suggestions" yaml:"levenshtein_suggestions"`
	MaxLevenshteinDistance int           `mapstructure:"max_levenshtein_distance" yaml:"max_levenshtein_distance"`
	MaxDistance            int           `mapstructure:"max_distance,omitempty" yaml:"max_distance,omitempty"`
	MaxSuggestions         int           `mapstructure:"max_suggestions" yaml:"max_suggestions"`
	SuggestionsLimit       int           `mapstructure:"suggestions_limit,omitempty" yaml:"suggestions_limit,omitempty"`
	SnippetContextLines    int           `mapstructure:"snippet_context_lines" yaml:"snippet_context_lines"`
}

DiagnosticsConfig configures error diagnosis and Levenshtein suggestion behavior.

type DocsConfig added in v0.34.0

type DocsConfig struct {
	CacheEnabled           bool          `mapstructure:"cache_enabled" yaml:"cache_enabled"`
	CacheTTL               time.Duration `mapstructure:"cache_ttl" yaml:"cache_ttl"`
	CacheMaxEntries        int           `mapstructure:"cache_max_entries" yaml:"cache_max_entries"`
	ExternalFetch          bool          `mapstructure:"external_fetch" yaml:"external_fetch"`
	OfflineMode            bool          `mapstructure:"offline_mode" yaml:"offline_mode"`
	PkgGoDevURL            string        `mapstructure:"pkg_go_dev_url" yaml:"pkg_go_dev_url"`
	MaxSymbolsRendered     int           `mapstructure:"max_symbols_rendered" yaml:"max_symbols_rendered"`
	FuzzySuggestions       bool          `mapstructure:"fuzzy_suggestions" yaml:"fuzzy_suggestions"`
	MaxFuzzySuggestions    int           `mapstructure:"max_fuzzy_suggestions" yaml:"max_fuzzy_suggestions"`
	FuzzyDistanceThreshold int           `mapstructure:"fuzzy_distance_threshold" yaml:"fuzzy_distance_threshold"`
	DefaultFormat          string        `mapstructure:"default_format" yaml:"default_format"`
	TempDir                string        `mapstructure:"temp_dir,omitempty" yaml:"temp_dir,omitempty"`
}

DocsConfig configures read_docs AST documentation extraction.

type EditConfig added in v0.34.0

type EditConfig struct {
	BackupStrategy         string        `mapstructure:"backup_strategy" yaml:"backup_strategy"`
	AtomicWrite            bool          `mapstructure:"atomic_write" yaml:"atomic_write"`
	PreservePermissions    bool          `mapstructure:"preserve_permissions" yaml:"preserve_permissions"`
	DefaultThreshold       float64       `mapstructure:"default_threshold" yaml:"default_threshold"`
	FuzzyThreshold         float64       `mapstructure:"fuzzy_threshold,omitempty" yaml:"fuzzy_threshold,omitempty"`
	FormatOnSave           string        `mapstructure:"format_on_save" yaml:"format_on_save"`
	ExcludePaths           []string      `mapstructure:"exclude_paths" yaml:"exclude_paths"`
	ExcludeDirs            []string      `mapstructure:"exclude_dirs,omitempty" yaml:"exclude_dirs,omitempty"`
	MaxLevenshteinDistance int           `mapstructure:"max_levenshtein_distance" yaml:"max_levenshtein_distance"`
	CompilerGate           string        `mapstructure:"compiler_gate" yaml:"compiler_gate"`
	Timeout                time.Duration `mapstructure:"timeout" yaml:"timeout" json:"timeout"`
}

EditConfig configures smart_edit coordinate editing.

type FeaturesConfig added in v0.34.0

type FeaturesConfig struct {
	Autofix                bool `mapstructure:"autofix" yaml:"autofix"`
	ModTidy                bool `mapstructure:"mod_tidy" yaml:"mod_tidy"`
	ModernizeCheck         bool `mapstructure:"modernize_check" yaml:"modernize_check"`
	DeadcodeCheck          bool `mapstructure:"deadcode_check" yaml:"deadcode_check"`
	FormatOnBuild          bool `mapstructure:"format_on_build" yaml:"format_on_build"`
	FormatOnEdit           bool `mapstructure:"format_on_edit" yaml:"format_on_edit"`
	VetGate                bool `mapstructure:"vet_gate" yaml:"vet_gate"`
	AutoRollback           bool `mapstructure:"auto_rollback" yaml:"auto_rollback"`
	TestQuerySync          bool `mapstructure:"testquery_sync" yaml:"testquery_sync"`
	TestQueryCompat        bool `mapstructure:"testquery_compat,omitempty" yaml:"testquery_compat,omitempty"`
	VersionCheckHints      bool `mapstructure:"version_check_hints" yaml:"version_check_hints"`
	CoverageGate           bool `mapstructure:"coverage_gate" yaml:"coverage_gate"`
	RaceDetector           bool `mapstructure:"race_detector" yaml:"race_detector"`
	StrictMode             bool `mapstructure:"strict_mode" yaml:"strict_mode"`
	RemoteDocFetch         bool `mapstructure:"remote_doc_fetch" yaml:"remote_doc_fetch"`
	VanityResolution       bool `mapstructure:"vanity_resolution" yaml:"vanity_resolution"`
	DocsCache              bool `mapstructure:"docs_cache" yaml:"docs_cache"`
	LevenshteinSuggestions bool `mapstructure:"levenshtein_suggestions,omitempty" yaml:"levenshtein_suggestions,omitempty"`
	MutationTesting        bool `mapstructure:"mutation_testing,omitempty" yaml:"mutation_testing,omitempty"`
}

FeaturesConfig holds global feature toggles.

type InstructionsConfig added in v0.34.0

type InstructionsConfig struct {
	Enabled          bool   `mapstructure:"enabled" yaml:"enabled" json:"enabled"`
	Compact          bool   `mapstructure:"compact" yaml:"compact" json:"compact"`
	DynamicTools     bool   `mapstructure:"dynamic_tools" yaml:"dynamic_tools"`
	RulesFile        string `mapstructure:"rules_file,omitempty" yaml:"rules_file,omitempty"`
	CustomRules      string `mapstructure:"custom_rules,omitempty" yaml:"custom_rules,omitempty"`
	CustomPromptPath string `mapstructure:"custom_prompt_path,omitempty" yaml:"custom_prompt_path,omitempty"`
	ExtraGuidance    string `mapstructure:"extra_guidance,omitempty" yaml:"extra_guidance,omitempty"`
}

InstructionsConfig configures dynamic agent instructions and prompts.

type MatchingConfig added in v0.34.0

type MatchingConfig struct {
	FuzzyFallback        bool    `mapstructure:"fuzzy_fallback" yaml:"fuzzy_fallback"`
	SimilarityThreshold  float64 `mapstructure:"similarity_threshold" yaml:"similarity_threshold"`
	DefaultThreshold     float64 `mapstructure:"default_threshold,omitempty" yaml:"default_threshold,omitempty"`
	NormalizeUnicode     bool    `mapstructure:"normalize_unicode" yaml:"normalize_unicode"`
	MinSeedLength        int     `mapstructure:"min_seed_length" yaml:"min_seed_length"`
	WindowExpansionDelta int     `mapstructure:"window_expansion_delta" yaml:"window_expansion_delta"`
	MaxWindowLines       int     `mapstructure:"max_window_lines" yaml:"max_window_lines"`
}

MatchingConfig configures AST/fuzzy text matching parameters in smart_edit.

type SafeShellConfig added in v0.34.0

type SafeShellConfig struct {
	Mode            string        `mapstructure:"mode" yaml:"mode" json:"mode"`
	CommandTimeout  time.Duration `mapstructure:"command_timeout" yaml:"command_timeout"`
	DefaultTimeout  time.Duration `mapstructure:"default_timeout,omitempty" yaml:"default_timeout,omitempty"`
	AllowedBinaries []string      `mapstructure:"allowed_binaries" yaml:"allowed_binaries"`
	MaxOutputBytes  int64         `mapstructure:"max_output_bytes" yaml:"max_output_bytes"`
}

SafeShellConfig configures safe shell execution parameters.

type ServerConfig added in v0.34.0

type ServerConfig struct {
	Name            string              `mapstructure:"name" yaml:"name" json:"name"`
	Transport       string              `mapstructure:"transport" yaml:"transport" json:"transport"`
	HTTP            ServerHTTPConfig    `mapstructure:"http" yaml:"http" json:"http"`
	Logging         ServerLoggingConfig `mapstructure:"logging" yaml:"logging" json:"logging"`
	ListenAddr      string              `mapstructure:"listen_addr,omitempty" yaml:"listen_addr,omitempty"`
	ReadTimeout     time.Duration       `mapstructure:"read_timeout,omitempty" yaml:"read_timeout,omitempty"`
	WriteTimeout    time.Duration       `mapstructure:"write_timeout,omitempty" yaml:"write_timeout,omitempty"`
	IdleTimeout     time.Duration       `mapstructure:"idle_timeout,omitempty" yaml:"idle_timeout,omitempty"`
	ShutdownTimeout time.Duration       `mapstructure:"shutdown_timeout,omitempty" yaml:"shutdown_timeout,omitempty"`
	AllowedOrigins  []string            `mapstructure:"allowed_origins,omitempty" yaml:"allowed_origins,omitempty"`
}

ServerConfig configures the MCP server and StreamableHTTP endpoints.

type ServerHTTPConfig added in v0.34.0

type ServerHTTPConfig struct {
	Listen           string        `mapstructure:"listen" yaml:"listen" json:"listen"`
	ListenAddr       string        `mapstructure:"listen_addr,omitempty" yaml:"listen_addr,omitempty"`
	ReadTimeout      time.Duration `mapstructure:"read_timeout" yaml:"read_timeout" json:"read_timeout"`
	WriteTimeout     time.Duration `mapstructure:"write_timeout" yaml:"write_timeout" json:"write_timeout"`
	IdleTimeout      time.Duration `mapstructure:"idle_timeout" yaml:"idle_timeout" json:"idle_timeout"`
	ShutdownTimeout  time.Duration `mapstructure:"shutdown_timeout" yaml:"shutdown_timeout"`
	AllowedOrigins   []string      `mapstructure:"allowed_origins" yaml:"allowed_origins"`
	AllowCredentials bool          `mapstructure:"allow_credentials" yaml:"allow_credentials"`
}

ServerHTTPConfig configures HTTP-specific server options.

type ServerLoggingConfig added in v0.34.0

type ServerLoggingConfig struct {
	Level            string `mapstructure:"level" yaml:"level" json:"level"`
	Format           string `mapstructure:"format" yaml:"format" json:"format"`
	TraceMCPPayloads bool   `mapstructure:"trace_mcp_payloads" yaml:"trace_mcp_payloads"`
	LogFile          string `mapstructure:"log_file,omitempty" yaml:"log_file,omitempty"`
}

ServerLoggingConfig configures logging options for the server.

type TestConfig added in v0.34.0

type TestConfig struct {
	DefaultLevel      string        `mapstructure:"default_level" yaml:"default_level"`
	DefaultPackages   string        `mapstructure:"default_packages" yaml:"default_packages"`
	Timeout           time.Duration `mapstructure:"timeout" yaml:"timeout" json:"timeout"`
	Verbose           bool          `mapstructure:"verbose" yaml:"verbose" json:"verbose"`
	RaceDetector      bool          `mapstructure:"race_detector" yaml:"race_detector"`
	CoverageThreshold float64       `mapstructure:"coverage_threshold" yaml:"coverage_threshold"`
	CoverageProfile   string        `mapstructure:"coverage_profile" yaml:"coverage_profile"`
	CoverageOutputDir string        `mapstructure:"coverage_output_dir,omitempty" yaml:"coverage_output_dir,omitempty"`
	BenchmarkPattern  string        `mapstructure:"benchmark_pattern" yaml:"benchmark_pattern"`
	BenchmarkFlags    []string      `mapstructure:"benchmark_flags,omitempty" yaml:"benchmark_flags,omitempty"`
	BenchmarkMem      bool          `mapstructure:"benchmark_mem" yaml:"benchmark_mem"`
}

TestConfig configures the smart_test runner.

type TestQueryConfig added in v0.34.0

type TestQueryConfig struct {
	DatabasePath string        `mapstructure:"db_path" yaml:"db_path" json:"db_path"`
	WALMode      bool          `mapstructure:"wal_mode" yaml:"wal_mode" json:"wal_mode"`
	BusyTimeout  time.Duration `mapstructure:"busy_timeout" yaml:"busy_timeout" json:"busy_timeout"`
	Format       string        `mapstructure:"format" yaml:"format" json:"format"`
}

TestQueryConfig configures SQL analytics against testquery.db.

type ToolSpec added in v0.34.0

type ToolSpec struct {
	BinaryName         string        `mapstructure:"binary_name" yaml:"binary_name"`
	Command            string        `mapstructure:"command,omitempty" yaml:"command,omitempty"`
	RecommendedVersion string        `mapstructure:"recommended_version" yaml:"recommended_version"`
	MinVersion         string        `mapstructure:"min_version,omitempty" yaml:"min_version,omitempty"`
	Pkg                string        `mapstructure:"pkg,omitempty" yaml:"pkg,omitempty"`
	Package            string        `mapstructure:"package,omitempty" yaml:"package,omitempty"`
	Config             string        `mapstructure:"config,omitempty" yaml:"config,omitempty"`
	Packages           string        `mapstructure:"packages,omitempty" yaml:"packages,omitempty"`
	DbPath             string        `mapstructure:"db_path,omitempty" yaml:"db_path,omitempty"`
	Format             string        `mapstructure:"format,omitempty" yaml:"format,omitempty"`
	Timeout            time.Duration `mapstructure:"timeout" yaml:"timeout"`
	Args               []string      `mapstructure:"args,omitempty" yaml:"args,omitempty"`
	Disabled           bool          `mapstructure:"disabled" yaml:"disabled"`
	Workers            int           `mapstructure:"workers,omitempty" yaml:"workers,omitempty"`
	TestQueryCompat    bool          `mapstructure:"testquery_compat,omitempty" yaml:"testquery_compat,omitempty"`
}

ToolSpec defines execution parameters and version tracking for an external binary/package.

type ToolsConfig added in v0.34.0

type ToolsConfig struct {
	GolangCILint ToolSpec `mapstructure:"golangci_lint" yaml:"golangci_lint"`
	Modernize    ToolSpec `mapstructure:"modernize" yaml:"modernize"`
	Deadcode     ToolSpec `mapstructure:"deadcode" yaml:"deadcode"`
	Selene       ToolSpec `mapstructure:"selene" yaml:"selene"`
	TestQuery    ToolSpec `mapstructure:"testquery" yaml:"testquery"`
}

ToolsConfig catalogs external tool specs.

Jump to

Keyboard shortcuts

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