config

package
v1.0.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: Apache-2.0, Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package config provides YAML-based project configuration for codefang.

Index

Constants

View Source
const (
	DefaultPipelineWorkers         = 0
	DefaultPipelineMemoryBudget    = ""
	DefaultPipelineBlobCacheSize   = ""
	DefaultPipelineDiffCacheSize   = 0
	DefaultPipelineBlobArenaSize   = ""
	DefaultPipelineCommitBatchSize = 0
	DefaultPipelineGOGC            = 0
	DefaultPipelineBallastSize     = "0"
)

Pipeline default values.

View Source
const (
	DefaultPipelineUASTSpillThreshold           = 32
	DefaultPipelineIntraCommitParallelThreshold = 4
	DefaultPipelineMaxIntraCommitWorkers        = 4
	DefaultPipelineMaxUASTBlobSize              = 256 * 1024 // 256 KiB.
	DefaultPipelineUASTParseTimeout             = "10s"
	DefaultPipelineMaxChangesPerCommit          = 10000
	DefaultPipelineMaxDiffBatchSize             = 1000
	DefaultPipelineMemoryBudgetRatio            = 50
	DefaultPipelineMemoryBudgetCap              = "2GiB"
	DefaultPipelineMemoryLimitRatio             = 75
	DefaultPipelineUASTSpillTrimInterval        = 16
	DefaultPipelineNativeTrimInterval           = 10
	DefaultPipelineMaxStreamingBuffering        = 3
	DefaultPipelineDrainPrefetchTimeout         = "30s"
	DefaultPipelineSamplerInterval              = "2s"
	DefaultPipelineWorkerRatio                  = 100
	DefaultPipelineUASTWorkerRatio              = 40
	DefaultPipelineLeafWorkerDivisor            = 3
	DefaultPipelineMinLeafWorkers               = 4
	DefaultPipelineBufferSizeMultiplier         = 2
	DefaultPipelineBudgetLimitRatio             = 95
	DefaultPipelineSystemRAMLimitRatio          = 90
	DefaultPipelineStaticMaxWorkers             = 8
	DefaultPipelineMallocTrimInterval           = 50
	DefaultPipelineStaticMemoryLimitRatio       = 90
	DefaultPipelineDiffJobBufferMultiplier      = 10
)

Pipeline advanced tuning defaults.

View Source
const (
	DefaultBurndownGranularity          = 30
	DefaultBurndownSampling             = 30
	DefaultBurndownTrackFiles           = false
	DefaultBurndownTrackPeople          = false
	DefaultBurndownHibernationThreshold = 1000
	DefaultBurndownHibernationToDisk    = true
	DefaultBurndownHibernationDirectory = ""
	DefaultBurndownDebug                = false
	DefaultBurndownGoroutines           = 0
)

Burndown analyzer defaults.

View Source
const (
	DefaultCouplesCouplingThresholdHigh      = 10
	DefaultCouplesOwnershipFewThreshold      = 3
	DefaultCouplesOwnershipModerateThreshold = 5
	DefaultCouplesBatchCouplingThreshold     = 100
	DefaultCouplesHLLPrecision               = 10
	DefaultCouplesTopKPerFile                = 100
	DefaultCouplesMinEdgeWeight              = 2
)

Couples analyzer defaults.

View Source
const (
	DefaultDevsConsiderEmptyCommits  = false
	DefaultDevsAnonymize             = false
	DefaultDevsBusFactorThreshold    = 0.5
	DefaultDevsRiskThresholdCritical = 90.0
	DefaultDevsRiskThresholdHigh     = 80.0
	DefaultDevsRiskThresholdMedium   = 60.0
	DefaultDevsActiveThresholdRatio  = 0.7
	DefaultDevsDefaultActiveDays     = 90
	DefaultDevsHLLPrecision          = 14
)

Devs analyzer defaults.

View Source
const (
	DefaultFileHistoryHotspotCritical = 50
	DefaultFileHistoryHotspotHigh     = 30
	DefaultFileHistoryHotspotMedium   = 15
)

File history analyzer defaults.

View Source
const (
	DefaultImportsGoroutines            = 4
	DefaultImportsMaxFileSize           = 1 << 20 // 1 MiB.
	DefaultImportsMaxDependencyRiskRows = 30
)

Imports analyzer defaults.

View Source
const (
	DefaultSentimentMinCommentLength       = 20
	DefaultSentimentGap                    = 0.5
	DefaultSentimentNeutralizerWeight      = 0.8
	DefaultSentimentMaxWeightRatio         = 3.0
	DefaultSentimentPositiveThreshold      = 0.6
	DefaultSentimentNegativeThreshold      = 0.4
	DefaultSentimentTrendThreshold         = 0.1
	DefaultSentimentLowSentimentRiskThresh = 0.2
)

Sentiment analyzer defaults.

View Source
const (
	DefaultShotnessDSLStruct = `filter(.roles has "Function")`
	DefaultShotnessDSLName   = ".props.name"
)

Shotness analyzer defaults.

View Source
const (
	DefaultAnomalyThreshold  = 2.0
	DefaultAnomalyWindowSize = 20
)

Anomaly analyzer defaults.

View Source
const (
	DefaultClonesMaxClonePairs        = 1000
	DefaultClonesNumHashes            = 128
	DefaultClonesNumBands             = 16
	DefaultClonesNumRows              = 8
	DefaultClonesShingleSize          = 5
	DefaultClonesSimilarityType2      = 0.8
	DefaultClonesSimilarityType3      = 0.5
	DefaultClonesThresholdRatioYellow = 0.1
	DefaultClonesThresholdRatioRed    = 0.3
	DefaultClonesThresholdPairsYellow = 5
	DefaultClonesThresholdPairsRed    = 20
)

Clones analyzer defaults.

View Source
const (
	DefaultCheckpointEnabled   = true
	DefaultCheckpointDir       = ""
	DefaultCheckpointResume    = true
	DefaultCheckpointClearPrev = false
)

Checkpoint defaults.

View Source
const (
	DefaultTyposMaxDistance = 4
)

Typos analyzer defaults.

Variables

View Source
var (
	// ErrInvalidWorkers indicates the workers value is negative.
	ErrInvalidWorkers = errors.New("pipeline.workers must be non-negative")
	// ErrInvalidDiffCacheSize indicates the diff cache size is negative.
	ErrInvalidDiffCacheSize = errors.New("pipeline.diff_cache_size must be non-negative")
	// ErrInvalidCommitBatchSize indicates the commit batch size is negative.
	ErrInvalidCommitBatchSize = errors.New("pipeline.commit_batch_size must be non-negative")
	// ErrInvalidGOGC indicates the GOGC value is negative.
	ErrInvalidGOGC = errors.New("pipeline.gogc must be non-negative")
	// ErrInvalidUASTSpillThreshold indicates the UAST spill threshold is negative.
	ErrInvalidUASTSpillThreshold = errors.New("pipeline.uast_spill_threshold must be non-negative")
	// ErrInvalidIntraCommitParallelThreshold indicates the intra-commit parallel threshold is negative.
	ErrInvalidIntraCommitParallelThreshold = errors.New("pipeline.intra_commit_parallel_threshold must be non-negative")
	// ErrInvalidMaxIntraCommitWorkers indicates the max intra-commit workers is negative.
	ErrInvalidMaxIntraCommitWorkers = errors.New("pipeline.max_intra_commit_workers must be non-negative")
	// ErrInvalidMaxUASTBlobSize indicates the max UAST blob size is negative.
	ErrInvalidMaxUASTBlobSize = errors.New("pipeline.max_uast_blob_size must be non-negative")
	// ErrInvalidMaxChangesPerCommit indicates the max changes per commit is negative.
	ErrInvalidMaxChangesPerCommit = errors.New("pipeline.max_changes_per_commit must be non-negative")
	// ErrInvalidMaxDiffBatchSize indicates the max diff batch size is negative.
	ErrInvalidMaxDiffBatchSize = errors.New("pipeline.max_diff_batch_size must be non-negative")
	// ErrInvalidMemoryBudgetRatio indicates the memory budget ratio is out of range.
	ErrInvalidMemoryBudgetRatio = errors.New("pipeline.memory_budget_ratio must be between 0 and 100")
	// ErrInvalidMemoryLimitRatio indicates the memory limit ratio is out of range.
	ErrInvalidMemoryLimitRatio = errors.New("pipeline.memory_limit_ratio must be between 0 and 100")
	// ErrInvalidBurndownGranularity indicates the granularity is not positive.
	ErrInvalidBurndownGranularity = errors.New("history.burndown.granularity must be positive")
	// ErrInvalidBurndownSampling indicates the sampling is not positive.
	ErrInvalidBurndownSampling = errors.New("history.burndown.sampling must be positive")
	// ErrInvalidCouplingThreshold indicates the coupling threshold is negative.
	ErrInvalidCouplingThreshold = errors.New("history.couples.coupling_threshold_high must be non-negative")
	// ErrInvalidOwnershipFewThreshold indicates the ownership few threshold is negative.
	ErrInvalidOwnershipFewThreshold = errors.New("history.couples.ownership_few_threshold must be non-negative")
	// ErrInvalidOwnershipModerateThreshold indicates the ownership moderate threshold is negative.
	ErrInvalidOwnershipModerateThreshold = errors.New("history.couples.ownership_moderate_threshold must be non-negative")
	// ErrInvalidCouplesHLLPrecision indicates the HLL precision is out of range.
	ErrInvalidCouplesHLLPrecision = errors.New("history.couples.hll_precision must be between 4 and 18")
	// ErrInvalidBusFactorThreshold indicates the bus factor threshold is out of range.
	ErrInvalidBusFactorThreshold = errors.New("history.devs.bus_factor_threshold must be between 0 and 1")
	// ErrInvalidDevsRiskThresholdCritical indicates the critical risk threshold is out of range.
	ErrInvalidDevsRiskThresholdCritical = errors.New("history.devs.risk_threshold_critical must be between 0 and 100")
	// ErrInvalidDevsRiskThresholdHigh indicates the high risk threshold is out of range.
	ErrInvalidDevsRiskThresholdHigh = errors.New("history.devs.risk_threshold_high must be between 0 and 100")
	// ErrInvalidDevsRiskThresholdMedium indicates the medium risk threshold is out of range.
	ErrInvalidDevsRiskThresholdMedium = errors.New("history.devs.risk_threshold_medium must be between 0 and 100")
	// ErrInvalidDevsActiveThresholdRatio indicates the active threshold ratio is out of range.
	ErrInvalidDevsActiveThresholdRatio = errors.New("history.devs.active_threshold_ratio must be between 0 and 1")
	// ErrInvalidDevsDefaultActiveDays indicates the default active days is negative.
	ErrInvalidDevsDefaultActiveDays = errors.New("history.devs.default_active_days must be non-negative")
	// ErrInvalidDevsHLLPrecision indicates the HLL precision is out of range.
	ErrInvalidDevsHLLPrecision = errors.New("history.devs.hll_precision must be between 4 and 18")
	// ErrInvalidHotspotThresholdCritical indicates the critical hotspot threshold is negative.
	ErrInvalidHotspotThresholdCritical = errors.New("history.file_history.hotspot_threshold_critical must be non-negative")
	// ErrInvalidHotspotThresholdHigh indicates the high hotspot threshold is negative.
	ErrInvalidHotspotThresholdHigh = errors.New("history.file_history.hotspot_threshold_high must be non-negative")
	// ErrInvalidHotspotThresholdMedium indicates the medium hotspot threshold is negative.
	ErrInvalidHotspotThresholdMedium = errors.New("history.file_history.hotspot_threshold_medium must be non-negative")
	// ErrInvalidSentimentMinLength indicates the min comment length is not positive.
	ErrInvalidSentimentMinLength = errors.New("history.sentiment.min_comment_length must be positive")
	// ErrInvalidSentimentGap indicates the sentiment gap is out of range.
	ErrInvalidSentimentGap = errors.New("history.sentiment.gap must be between 0 and 1")
	// ErrInvalidNeutralizerWeight indicates the neutralizer weight is out of range.
	ErrInvalidNeutralizerWeight = errors.New("history.sentiment.neutralizer_weight must be between 0 and 1")
	// ErrInvalidMaxWeightRatio indicates the max weight ratio is negative.
	ErrInvalidMaxWeightRatio = errors.New("history.sentiment.max_weight_ratio must be non-negative")
	// ErrInvalidTyposMaxDistance indicates the max distance is not positive.
	ErrInvalidTyposMaxDistance = errors.New("history.typos.max_distance must be positive")
	// ErrInvalidImportsGoroutines indicates the goroutines value is not positive.
	ErrInvalidImportsGoroutines = errors.New("history.imports.goroutines must be positive")
	// ErrInvalidImportsMaxFileSize indicates the max file size is not positive.
	ErrInvalidImportsMaxFileSize = errors.New("history.imports.max_file_size must be positive")
	// ErrInvalidImportsMaxDependencyRiskRows indicates the max dependency risk rows is negative.
	ErrInvalidImportsMaxDependencyRiskRows = errors.New("history.imports.max_dependency_risk_rows must be non-negative")
	// ErrInvalidAnomalyThreshold indicates the threshold is not positive.
	ErrInvalidAnomalyThreshold = errors.New("history.anomaly.threshold must be positive")
	// ErrInvalidAnomalyWindowSize indicates the window size is less than 2.
	ErrInvalidAnomalyWindowSize = errors.New("history.anomaly.window_size must be at least 2")
	// ErrInvalidClonesMaxClonePairs indicates the max clone pairs is negative.
	ErrInvalidClonesMaxClonePairs = errors.New("history.clones.max_clone_pairs must be non-negative")
)

Sentinel errors for configuration validation.

Functions

This section is empty.

Types

type AnomalyConfig

type AnomalyConfig struct {
	Threshold  float64 `mapstructure:"threshold"`
	WindowSize int     `mapstructure:"window_size"`
}

AnomalyConfig holds temporal anomaly detection analyzer settings.

type BurndownConfig

type BurndownConfig struct {
	Granularity          int    `mapstructure:"granularity"`
	Sampling             int    `mapstructure:"sampling"`
	TrackFiles           bool   `mapstructure:"track_files"`
	TrackPeople          bool   `mapstructure:"track_people"`
	HibernationThreshold int    `mapstructure:"hibernation_threshold"`
	HibernationToDisk    bool   `mapstructure:"hibernation_to_disk"`
	HibernationDirectory string `mapstructure:"hibernation_directory"`
	Debug                bool   `mapstructure:"debug"`
	Goroutines           int    `mapstructure:"goroutines"`
}

BurndownConfig holds burndown analyzer settings.

type CheckpointConfig

type CheckpointConfig struct {
	Enabled   bool   `mapstructure:"enabled"`
	Dir       string `mapstructure:"dir"`
	Resume    bool   `mapstructure:"resume"`
	ClearPrev bool   `mapstructure:"clear_prev"`
}

CheckpointConfig holds checkpoint settings.

type ClonesConfig

type ClonesConfig struct {
	MaxClonePairs        int     `mapstructure:"max_clone_pairs"`
	NumHashes            int     `mapstructure:"num_hashes"`
	NumBands             int     `mapstructure:"num_bands"`
	NumRows              int     `mapstructure:"num_rows"`
	ShingleSize          int     `mapstructure:"shingle_size"`
	SimilarityType2      float64 `mapstructure:"similarity_type2"`
	SimilarityType3      float64 `mapstructure:"similarity_type3"`
	ThresholdRatioYellow float64 `mapstructure:"threshold_ratio_yellow"`
	ThresholdRatioRed    float64 `mapstructure:"threshold_ratio_red"`
	ThresholdPairsYellow int     `mapstructure:"threshold_pairs_yellow"`
	ThresholdPairsRed    int     `mapstructure:"threshold_pairs_red"`
}

ClonesConfig holds clones analyzer settings.

type Config

type Config struct {
	Analyzers  []string         `mapstructure:"analyzers"`
	Pipeline   PipelineConfig   `mapstructure:"pipeline"`
	History    HistoryConfig    `mapstructure:"history"`
	Checkpoint CheckpointConfig `mapstructure:"checkpoint"`
}

Config is the top-level configuration struct for codefang. Field tags use mapstructure for viper unmarshalling.

func LoadConfig

func LoadConfig(configPath string) (*Config, error)

LoadConfig loads configuration from file, env vars, and defaults. If configPath is non-empty, it is used as the explicit config file path. Otherwise, the config file is searched in CWD and $HOME. Missing config file is not an error; defaults are used.

func (*Config) ApplyToFacts

func (c *Config) ApplyToFacts(facts map[string]any)

ApplyToFacts merges config values into the analyzer facts map. Only non-zero config values override existing facts; zero values indicate "use analyzer default" and are skipped. Boolean fields are always applied because false is a meaningful value.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks Config invariants and returns the first error found.

type CouplesConfig

type CouplesConfig struct {
	CouplingThresholdHigh      int `mapstructure:"coupling_threshold_high"`
	OwnershipFewThreshold      int `mapstructure:"ownership_few_threshold"`
	OwnershipModerateThreshold int `mapstructure:"ownership_moderate_threshold"`
	BatchCouplingThreshold     int `mapstructure:"batch_coupling_threshold"`
	HLLPrecision               int `mapstructure:"hll_precision"`
	TopKPerFile                int `mapstructure:"top_k_per_file"`
	MinEdgeWeight              int `mapstructure:"min_edge_weight"`
}

CouplesConfig holds couples analyzer settings.

type DevsConfig

type DevsConfig struct {
	ConsiderEmptyCommits  bool    `mapstructure:"consider_empty_commits"`
	Anonymize             bool    `mapstructure:"anonymize"`
	BusFactorThreshold    float64 `mapstructure:"bus_factor_threshold"`
	RiskThresholdCritical float64 `mapstructure:"risk_threshold_critical"`
	RiskThresholdHigh     float64 `mapstructure:"risk_threshold_high"`
	RiskThresholdMedium   float64 `mapstructure:"risk_threshold_medium"`
	ActiveThresholdRatio  float64 `mapstructure:"active_threshold_ratio"`
	DefaultActiveDays     int     `mapstructure:"default_active_days"`
	HLLPrecision          int     `mapstructure:"hll_precision"`
}

DevsConfig holds devs analyzer settings.

type FileHistoryConfig

type FileHistoryConfig struct {
	HotspotThresholdCritical int `mapstructure:"hotspot_threshold_critical"`
	HotspotThresholdHigh     int `mapstructure:"hotspot_threshold_high"`
	HotspotThresholdMedium   int `mapstructure:"hotspot_threshold_medium"`
}

FileHistoryConfig holds file history analyzer settings.

type HistoryConfig

type HistoryConfig struct {
	Burndown    BurndownConfig    `mapstructure:"burndown"`
	Couples     CouplesConfig     `mapstructure:"couples"`
	Devs        DevsConfig        `mapstructure:"devs"`
	FileHistory FileHistoryConfig `mapstructure:"file_history"`
	Imports     ImportsConfig     `mapstructure:"imports"`
	Sentiment   SentimentConfig   `mapstructure:"sentiment"`
	Shotness    ShotnessConfig    `mapstructure:"shotness"`
	Typos       TyposConfig       `mapstructure:"typos"`
	Anomaly     AnomalyConfig     `mapstructure:"anomaly"`
	Clones      ClonesConfig      `mapstructure:"clones"`
}

HistoryConfig holds per-analyzer configuration for history analyzers.

type ImportsConfig

type ImportsConfig struct {
	Goroutines            int `mapstructure:"goroutines"`
	MaxFileSize           int `mapstructure:"max_file_size"`
	MaxDependencyRiskRows int `mapstructure:"max_dependency_risk_rows"`
}

ImportsConfig holds imports history analyzer settings.

type PipelineConfig

type PipelineConfig struct {
	Workers         int    `mapstructure:"workers"`
	MemoryBudget    string `mapstructure:"memory_budget"`
	BlobCacheSize   string `mapstructure:"blob_cache_size"`
	DiffCacheSize   int    `mapstructure:"diff_cache_size"`
	BlobArenaSize   string `mapstructure:"blob_arena_size"`
	CommitBatchSize int    `mapstructure:"commit_batch_size"`
	GOGC            int    `mapstructure:"gogc"`
	BallastSize     string `mapstructure:"ballast_size"`
	MemoryLimit     string `mapstructure:"memory_limit"`
	WorkerTimeout   string `mapstructure:"worker_timeout"`

	// Advanced pipeline tuning.
	UASTSpillThreshold           int    `mapstructure:"uast_spill_threshold"`
	IntraCommitParallelThreshold int    `mapstructure:"intra_commit_parallel_threshold"`
	MaxIntraCommitWorkers        int    `mapstructure:"max_intra_commit_workers"`
	MaxUASTBlobSize              int    `mapstructure:"max_uast_blob_size"`
	UASTParseTimeout             string `mapstructure:"uast_parse_timeout"`
	MaxChangesPerCommit          int    `mapstructure:"max_changes_per_commit"`
	MaxDiffBatchSize             int    `mapstructure:"max_diff_batch_size"`
	MemoryBudgetRatio            int    `mapstructure:"memory_budget_ratio"`
	MemoryBudgetCap              string `mapstructure:"memory_budget_cap"`
	MemoryLimitRatio             int    `mapstructure:"memory_limit_ratio"`
	UASTSpillTrimInterval        int    `mapstructure:"uast_spill_trim_interval"`
	NativeTrimInterval           int    `mapstructure:"native_trim_interval"`
	MaxStreamingBuffering        int    `mapstructure:"max_streaming_buffering"`
	DrainPrefetchTimeout         string `mapstructure:"drain_prefetch_timeout"`
	SamplerInterval              string `mapstructure:"sampler_interval"`
	WorkerRatio                  int    `mapstructure:"worker_ratio"`
	UASTWorkerRatio              int    `mapstructure:"uast_worker_ratio"`
	LeafWorkerDivisor            int    `mapstructure:"leaf_worker_divisor"`
	MinLeafWorkers               int    `mapstructure:"min_leaf_workers"`
	BufferSizeMultiplier         int    `mapstructure:"buffer_size_multiplier"`
	BudgetLimitRatio             int    `mapstructure:"budget_limit_ratio"`
	SystemRAMLimitRatio          int    `mapstructure:"system_ram_limit_ratio"`
	StaticMaxWorkers             int    `mapstructure:"static_max_workers"`
	MallocTrimInterval           int    `mapstructure:"malloc_trim_interval"`
	StaticMemoryLimitRatio       int    `mapstructure:"static_memory_limit_ratio"`
	DiffJobBufferMultiplier      int    `mapstructure:"diff_job_buffer_multiplier"`
}

PipelineConfig holds pipeline resource knobs.

type SentimentConfig

type SentimentConfig struct {
	MinCommentLength       int     `mapstructure:"min_comment_length"`
	Gap                    float64 `mapstructure:"gap"`
	NeutralizerWeight      float64 `mapstructure:"neutralizer_weight"`
	MaxWeightRatio         float64 `mapstructure:"max_weight_ratio"`
	PositiveThreshold      float64 `mapstructure:"positive_threshold"`
	NegativeThreshold      float64 `mapstructure:"negative_threshold"`
	TrendThreshold         float64 `mapstructure:"trend_threshold"`
	LowSentimentRiskThresh float64 `mapstructure:"low_sentiment_risk_threshold"`
}

SentimentConfig holds sentiment analyzer settings.

type ShotnessConfig

type ShotnessConfig struct {
	DSLStruct string `mapstructure:"dsl_struct"`
	DSLName   string `mapstructure:"dsl_name"`
}

ShotnessConfig holds shotness analyzer settings.

type TyposConfig

type TyposConfig struct {
	MaxDistance int `mapstructure:"max_distance"`
}

TyposConfig holds typos analyzer settings.

Jump to

Keyboard shortcuts

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