config

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 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 models and loads .codefit.yaml, the per-project configuration committed to the repository. It is a leaf package (no codefit dependencies) so that both the core context and the language providers can reference its types without creating import cycles.

Skeleton: the struct shape mirrors the PRD's .codefit.yaml. Validation, defaulting and merging with the global config are not implemented yet.

Index

Constants

View Source
const (
	CriticalityProduction = "production"
	CriticalityTest       = "test"
	CriticalityExample    = "example"
)

Path-criticality classes (RF-11).

Variables

This section is empty.

Functions

func ExpandGlobs

func ExpandGlobs(root string, patterns []string) ([]string, error)

ExpandGlobs resolves glob patterns (with ** support) to the set of existing files under root, project-relative and de-duplicated. It is used to turn schema_paths, test_dirs and ignore.paths into concrete file lists.

Types

type Baseline

type Baseline struct {
	Enabled bool   `yaml:"enabled"`
	File    string `yaml:"file"`
}

Baseline configures the adoption baseline (RF-10): when enabled only new findings are reported.

type Cache

type Cache struct {
	Enabled bool   `yaml:"enabled"`
	Dir     string `yaml:"dir"`
}

Cache configures the content-hash finding cache.

type Config

type Config struct {
	Version  string   `yaml:"version"`
	Project  Project  `yaml:"project"`
	Database Database `yaml:"database"`
	Sensors  Sensors  `yaml:"sensors"`
	Report   Report   `yaml:"report"`
	Cache    Cache    `yaml:"cache"`
	Baseline Baseline `yaml:"baseline"`
	MCP      MCP      `yaml:"mcp"`
	Ignore   Ignore   `yaml:"ignore"`
}

Config is the parsed representation of .codefit.yaml. Fields mirror the PRD schema; this is a skeleton, so zero values are acceptable until the loader and validators are implemented.

func Load

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

Load reads, parses and validates a .codefit.yaml file from path. Validation errors are located (path:line) so the user can jump to the offending line.

It does not yet apply defaulting or merge with the global user config; those are layered on by the caller.

func LoadOptional

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

LoadOptional loads a .codefit.yaml only when it exists, distinguishing the three states callers must not conflate:

  • ABSENT → (nil, nil): no config is fine, the caller uses defaults.
  • PRESENT but INVALID → (nil, error): codefit must REFUSE to run silently with a broken config. Swallowing this is the very anti-pattern codefit exists to catch — a false "all good" that hides a real problem (e.g. an invalid framework silently disabling path_criticality).
  • VALID → (cfg, nil): loaded normally.

The returned error is the located, field-level message from Load/validate (e.g. `invalid framework "nextjs" (allowed: …)`), useful enough to fix.

func (*Config) PathCriticalityFor

func (c *Config) PathCriticalityFor(file string) string

PathCriticalityFor classifies a project-relative file path as "production", "test" or "example" by matching it against the configured path_criticality globs, or returns "" when nothing matches.

Test and example take precedence over production so that, e.g., a *_test.go living under a production directory is correctly treated as test (lower severity), not production.

type Database

type Database struct {
	Paradigm    string   `yaml:"paradigm"` // oltp | olap | mixed (auto by default)
	Type        string   `yaml:"type"`
	SchemaPaths []string `yaml:"schema_paths"`
	ORM         string   `yaml:"orm"`
}

Database declares the DB paradigm and schema sources for the DB sensor.

type Ignore

type Ignore struct {
	Paths    []string        `yaml:"paths"`
	Findings []IgnoreFinding `yaml:"findings"`
}

Ignore holds path globs and finding suppressions. Critical security suppressions require an embedded ConsentRecord (validated later).

type IgnoreFinding

type IgnoreFinding struct {
	ID         string `yaml:"id"`
	Reason     string `yaml:"reason"`
	AcceptedBy string `yaml:"accepted_by"`
	AcceptedAt string `yaml:"accepted_at"`
}

IgnoreFinding suppresses a finding by ID. For critical security findings the consent fields are mandatory.

type MCP

type MCP struct {
	Enabled     bool     `yaml:"enabled"`
	ExposeTools []string `yaml:"expose_tools"`
}

MCP configures the MCP server and which tools it exposes.

type PathCriticality

type PathCriticality struct {
	Production []string `yaml:"production"`
	Test       []string `yaml:"test"`
	Example    []string `yaml:"example"`
}

PathCriticality classifies directories so the engine can raise or lower a finding's severity by where it lives. A secret in a test is noise; in production it is critical (RF-11). Language providers supply sensible defaults via LanguageProvider.DefaultPathCriticality.

type Project

type Project struct {
	Name            string          `yaml:"name"`
	Language        string          `yaml:"language"`
	Framework       string          `yaml:"framework"`
	Description     string          `yaml:"description"`
	PathCriticality PathCriticality `yaml:"path_criticality"`
}

Project holds project identity and the path-criticality classification that weights finding severity by location (RF-11).

type Report

type Report struct {
	Output       string         `yaml:"output"`
	OutFile      string         `yaml:"out_file"`
	IncludeInfo  bool           `yaml:"include_info"`
	ScoreWeights map[string]int `yaml:"score_weights"`
}

Report configures output format and the per-dimension score weights (which must sum to 100).

type SensorToggle

type SensorToggle struct {
	Enabled *bool `yaml:"enabled,omitempty"`
}

SensorToggle is the minimal per-sensor config common to every sensor. Enabled is a *bool to carry a THREE-STATE meaning: nil (unset in .codefit.yaml) lets a sensor apply its own default (the DB sensor treats unset as on — opt-out); an explicit true/false overrides it. A plain bool could not tell "unset" from "explicitly false".

type Sensors

type Sensors struct {
	Security   SensorToggle `yaml:"security"`
	Review     SensorToggle `yaml:"review"`
	DB         SensorToggle `yaml:"db"`
	Complexity SensorToggle `yaml:"complexity"`
	Practices  SensorToggle `yaml:"practices"`
	Tests      SensorToggle `yaml:"tests"`
}

Sensors toggles and tunes each sensor. Skeleton: only the enable flags and a couple of representative knobs are modeled.

Jump to

Keyboard shortcuts

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