config

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SectionRules       = "rules"
	SectionPathRules   = "path-rules"
	SectionVersion     = "version"
	SectionKeybindings = "keybindings"
	SectionTheme       = "theme"
	// SectionGeneral is used when the loader cannot map a failure to one
	// section (unknown top-level key, root syntax error, IO failure).
	SectionGeneral = "config"
)

Well-known .layerx.yaml sections. Used by LoadError and SectionHelp so the CLI can print targeted hints without dumping the full command usage block.

Variables

This section is empty.

Functions

func SectionHelp added in v1.4.0

func SectionHelp(section string) string

SectionHelp returns a short reference excerpt for section. When section is empty or unknown, a general .layerx.yaml hint is returned so every config failure surfaces actionable next steps.

Types

type Config

type Config struct {
	// Version is the schema version of this .layerx.yaml. Currently only 1
	// is accepted. Unset (zero) is treated as 1. Future schema breakage
	// will rev this — readers that see a version they don't understand
	// must error rather than guess.
	Version int `yaml:"version,omitempty"`

	// Theme selects the TUI colour theme. Valid values: catppuccin-mocha,
	// tokyo-night, kanagawa, gruvbox-dark, rose-pine, dracula, oxocarbon,
	// cyberdream. Empty string means the built-in default (tokyo-night).
	Theme string `yaml:"theme,omitempty"`

	// TransparentBackground strips all background colours from the TUI so
	// the terminal's own background (image, gradient, colour) shows through.
	// Opt-in only; default false preserves existing behaviour.
	TransparentBackground bool `yaml:"transparent_background,omitempty"`

	Rules RulesConfig `yaml:"rules"`

	// PathRules is populated by the loader's normalize() pass. It is NOT
	// directly unmarshalled from YAML — see normalizePathRules() — because
	// the YAML can be either a mapping (flat form) or a sequence (list
	// form). Tagged "-" so yaml.Strict() doesn't barf on a missing key.
	PathRules []PathRuleSpec `yaml:"-"`

	// Keybindings is a placeholder for the M12 keybinding-override feature
	// documented in CLAUDE.md. Declared here so yaml.Strict() accepts the
	// documented top-level key without rejecting the whole config; semantics
	// are wired up in M12.
	Keybindings map[string]string `yaml:"keybindings,omitempty"`
}

func Default

func Default() *Config

func Load

func Load() (*Config, error)

Load searches for .layerx.yaml starting from the current working directory and walking up to the filesystem root (bounded at 50 levels). The first file found is loaded. If no file is found in the walk, the XDG user config directory (~/.config/layerx/config.yaml on Linux, %AppData%\layerx\config.yaml on Windows) is checked as a final fallback. Returns Default() when no file is found in any location.

func LoadFrom

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

LoadFrom reads config from the specified path. Returns default config if the file does not exist, is empty, or contains only whitespace/comments.

type LoadError added in v1.4.0

type LoadError struct {
	Path    string
	Section string
	Err     error
}

LoadError wraps a config parse or validation failure with the file path and the config section the user should fix. cmd/ uses SectionHelp(Section) to print a short excerpt after the one-line error.

func (*LoadError) Error added in v1.4.0

func (e *LoadError) Error() string

func (*LoadError) Unwrap added in v1.4.0

func (e *LoadError) Unwrap() error

type PathRuleSpec added in v1.3.0

type PathRuleSpec struct {
	ID        string
	Type      PathRuleType
	Paths     []string
	Threshold int
}

PathRuleSpec is the canonical, post-normalize representation of one path rule. Both YAML forms (flat map and list-of-rules) collapse to a slice of these — downstream code never needs to know which form the user wrote.

For Block / DenyWaste: Paths is populated, Threshold is 0. For MaxLayerCount: Threshold is populated, Paths is nil.

ID is the rule identifier used for log-grep and future --rule-id filters. In flat form, ID is the rule type name itself ("block", "deny-waste", "max-layer-count"). In list form, ID is user-supplied and must be unique.

type PathRuleType added in v1.3.0

type PathRuleType string

PathRuleType identifies one of the three supported path-rule kinds. Unknown values are rejected at load time.

const (
	PathRuleBlock         PathRuleType = "block"
	PathRuleDenyWaste     PathRuleType = "deny-waste"
	PathRuleMaxLayerCount PathRuleType = "max-layer-count"
)

type RulesConfig

type RulesConfig struct {
	LowestEfficiency         float64 `yaml:"lowest-efficiency"`
	HighestWastedBytes       int64   `yaml:"highest-wasted-bytes"`
	HighestUserWastedPercent float64 `yaml:"highest-user-wasted-percent"`
}

Jump to

Keyboard shortcuts

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