{"modulePath":"github.com/codefit-cli/codefit","version":"v0.2.9","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package config\n\nPackage 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.\n\nStatus: BUILT. The struct shape mirrors the PRD's .codefit.yaml and Load validates it, reporting errors located to the offending line. There is no global config to merge with, by design: codefit manages no models and no credentials, so .codefit.yaml is the only configuration there is.\n\n## Constants\n\n```go\nconst (\n\tTestSeverityInfo      = \"info\"\n\tTestSeverityDowngrade = \"downgrade\"\n\tTestSeverityKeep      = \"keep\"\n)\n```\nTest-path severity modes (RF-10). They govern what happens to a security finding whose file is classified \"test\" by path\\_criticality:\n\n  - TestSeverityInfo forces it to info. It is the DEFAULT, and the mode the PRD chose: a secret in a test does not weigh what a secret in production weighs, so it costs the security score nothing (severity penalty 0).\n  - TestSeverityDowngrade lowers it exactly one level (critical→high, …). It was codefit's hardcoded behaviour before this key existed.\n  - TestSeverityKeep applies NO adjustment at all: the natural severity survives. It is the only one of the three that can leave a critical security finding standing on a test path, which means it is also the only one that can make scoring.IsBlocked true from a test file. That is a deliberate, PRD-named choice, not an accident — see SecuritySensor.\n\n```go\nconst (\n\tCriticalityProduction = \"production\"\n\tCriticalityTest       = \"test\"\n\tCriticalityExample    = \"example\"\n)\n```\nPath-criticality classes (RF-10).\n\n```go\nconst LanguageUndetected = \"undetected\"\n```\nLanguageUndetected is the value \\`codefit init\\` writes into project.language when no marker file under the project root resolved an auditable language provider.\n\nIt is a statement about codefit's DETECTION, never about the project. A Java or Rust repository has a language; codefit simply registers no provider that can audit its code, so it says so in the one place every later reader looks instead of refusing to write a config at all. Rendering it as \"this project has no language\" would be a lie.\n\nIt lives here, beside allowedLanguages, for two reasons. internal/scaffold already imports internal/config, so housing it there would invert the dependency; and internal/providers/registry is the wrong home because the sentinel is precisely the ABSENCE of a registered entry — a constant there invites someone to add a matching fake table row.\n\nEvery consumer of Project.Language must read it as \"resolve no provider\", not as a language name. No production sensor or handler reads the field today (validation is its only consumer), so the sentinel resolves nothing anywhere by construction — internal/mcp's Lock A asserts exactly that.\n\n## Functions\n\n```go\nfunc ExpandGlobs(root string, patterns []string) ([]string, error)\n```\nExpandGlobs 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.\n\n## Types\n\n```go\ntype Baseline struct {\n\tEnabled bool   `yaml:\"enabled\"`\n\tFile    string `yaml:\"file\"`\n}\n```\nBaseline configures the adoption baseline (RF-08): when enabled only new findings are reported.\n\n```go\ntype Cache struct {\n\tEnabled bool   `yaml:\"enabled\"`\n\tDir     string `yaml:\"dir\"`\n}\n```\nCache configures the content-hash finding cache.\n\n```go\ntype Config struct {\n\tVersion  string   `yaml:\"version\"`\n\tProject  Project  `yaml:\"project\"`\n\tDatabase Database `yaml:\"database\"`\n\tSensors  Sensors  `yaml:\"sensors\"`\n\tReport   Report   `yaml:\"report\"`\n\tCache    Cache    `yaml:\"cache\"`\n\tBaseline Baseline `yaml:\"baseline\"`\n\tMCP      MCP      `yaml:\"mcp\"`\n\tIgnore   Ignore   `yaml:\"ignore\"`\n}\n```\nConfig is the parsed representation of .codefit.yaml. Fields mirror the PRD schema. Zero values are acceptable throughout: .codefit.yaml is optional and every consumer defaults, so an absent key is a real state, not an unfinished one. Load validates what IS present.\n\n```go\nfunc Load(path string) (*Config, error)\n```\nLoad 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.\n\nIt does not yet apply defaulting or merge with the global user config; those are layered on by the caller.\n\n```go\nfunc LoadOptional(path string) (*Config, error)\n```\nLoadOptional loads a .codefit.yaml only when it exists, distinguishing the three states callers must not conflate:\n\n  - ABSENT  → (nil, nil): no config is fine, the caller uses defaults.\n  - 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).\n  - VALID   → (cfg, nil): loaded normally.\n\nThe returned error is the located, field-level message from Load/validate (e.g. \\`invalid framework \"nextjs\" (allowed: …)\\`), useful enough to fix.\n\n```go\nfunc (c *Config) PathCriticalityFor(file string) string\n```\nPathCriticalityFor 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.\n\nTest 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.\n\n```go\nfunc (c *Config) TestSeverityMode() string\n```\nTestSeverityMode resolves sensors.security.test\\_severity into the mode the security sensor must apply to a test-classified path (RF-10).\n\nIt is the SINGLE place the default is decided. Unset (\"\") means TestSeverityInfo — the PRD's default — and so does a nil Config, which is the ordinary state of a project with no .codefit.yaml. A value outside the enum cannot survive Load (validate rejects it with a located error), so reaching this function it can only come from a hand-built Config; the resolver refuses to invent a fourth mode and falls back to the default rather than silently leaving severities unweighted.\n\nCallers ask for the mode; they never read Sensors.Security.TestSeverity raw. A sensor that re-implemented the \"\" → info rule locally is exactly how two defaults drift apart, which is the same reason PathCriticalityFor lives here.\n\n```go\ntype Database struct {\n\tParadigm    string   `yaml:\"paradigm\"` // oltp | olap | mixed | auto (default)\n\tType        string   `yaml:\"type\"`\n\tSchemaPaths []string `yaml:\"schema_paths\"`\n\tORM         string   `yaml:\"orm\"`\n}\n```\nDatabase declares the DB paradigm and schema sources for the DB sensor.\n\n```go\ntype Ignore struct {\n\tPaths    []string        `yaml:\"paths\"`\n\tFindings []IgnoreFinding `yaml:\"findings\"`\n}\n```\nIgnore holds path globs and finding suppressions. Critical security suppressions require an embedded ConsentRecord (validated later).\n\n```go\ntype IgnoreFinding struct {\n\tID         string `yaml:\"id\"`\n\tReason     string `yaml:\"reason\"`\n\tAcceptedBy string `yaml:\"accepted_by\"`\n\tAcceptedAt string `yaml:\"accepted_at\"`\n}\n```\nIgnoreFinding suppresses a finding by ID. For critical security findings the consent fields are mandatory.\n\n```go\ntype MCP struct {\n\tEnabled     bool     `yaml:\"enabled\"`\n\tExposeTools []string `yaml:\"expose_tools\"`\n}\n```\nMCP configures the MCP server and which tools it exposes.\n\n```go\ntype PathCriticality struct {\n\tProduction []string `yaml:\"production\"`\n\tTest       []string `yaml:\"test\"`\n\tExample    []string `yaml:\"example\"`\n}\n```\nPathCriticality 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-10). Language providers supply sensible defaults via LanguageProvider.DefaultPathCriticality.\n\n```go\ntype Project struct {\n\tName            string          `yaml:\"name\"`\n\tLanguage        string          `yaml:\"language\"`\n\tFramework       string          `yaml:\"framework\"`\n\tDescription     string          `yaml:\"description\"`\n\tPathCriticality PathCriticality `yaml:\"path_criticality\"`\n}\n```\nProject holds project identity and the path-criticality classification that weights finding severity by location (RF-10).\n\n```go\ntype Report struct {\n\tOutput       string         `yaml:\"output\"`\n\tOutFile      string         `yaml:\"out_file\"`\n\tIncludeInfo  bool           `yaml:\"include_info\"`\n\tScoreWeights map[string]int `yaml:\"score_weights\"`\n}\n```\nReport configures output format and the per-dimension score weights (which must sum to 100).\n\n```go\ntype SecuritySensor struct {\n\tSensorToggle `yaml:\",inline\"`\n\tTestSeverity string `yaml:\"test_severity,omitempty\"`\n}\n```\nSecuritySensor is the security sensor's config: the shared toggle plus the knobs only this sensor honours.\n\nSensorToggle is embedded with \\`yaml:\",inline\"\\` so \\`enabled\\` and \\`test\\_severity\\` sit at the same level in .codefit.yaml while \\`enabled\\` keeps ONE definition (and its three-state \\*bool) shared with every other sensor.\n\nTestSeverity selects how a test-classified path re-weights a security finding: \"\" (unset) means TestSeverityInfo — resolve it through (\\*Config).TestSeverityMode(), never by reading this field raw.\n\nCONSEQUENCE OF \"keep\", stated where the key is declared: under TestSeverityKeep a critical security finding in a test file stays critical, so it keeps RequiresConsent and scoring.IsBlocked reports the project as blocked. codefit does not refuse the mode — it is one of the three the PRD names, and the developer decides — but the consequence is not hidden either: the security sensor emits one warning per run when keep actually leaves a finding at critical on a test path.\n\n```go\ntype SensorToggle struct {\n\tEnabled *bool `yaml:\"enabled,omitempty\"`\n}\n```\nSensorToggle 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\".\n\nIt carries ONLY what every sensor honours. Adding a sensor-specific knob here is the tempting one-line edit that makes five other sensors silently ACCEPT a key none of them reads — dead config that parses, validates and does nothing, exactly the class of defect codefit audits for. TestSeverity therefore lives on SecuritySensor, and sensortoggle\\_lock\\_test.go fails the build if that ever stops being true.\n\n```go\ntype Sensors struct {\n\tSecurity   SecuritySensor `yaml:\"security\"`\n\tReview     SensorToggle   `yaml:\"review\"`\n\tDB         SensorToggle   `yaml:\"db\"`\n\tComplexity SensorToggle   `yaml:\"complexity\"`\n\tPractices  SensorToggle   `yaml:\"practices\"`\n\tTests      SensorToggle   `yaml:\"tests\"`\n}\n```\nSensors toggles and tunes each sensor. Only the enable flags and a couple of representative knobs are modeled — the tuning surface grows with the sensors that need it, rather than being declared ahead of them.\n\n","path":"github.com/codefit-cli/codefit/internal/config","name":"config","synopsis":"Package config models and loads .codefit.yaml, the per-project configuration committed to the repository.","isRedistributable":true}
