Documentation
¶
Index ¶
- func ConfigDir() string
- func DataDir() string
- func DiscoveryPath() (string, error)
- func FiltersConfigPath() string
- func IsSecure(path string) bool
- func LoadCustomFilters() map[string]CustomFilter
- func LoadCustomFiltersFrom(path string) map[string]CustomFilter
- func LoadCustomFiltersWithLocal(cwd string) map[string]CustomFilter
- func ParseCustomFilters(data []byte) map[string]CustomFilter
- func Path() string
- func Validate(path string) []string
- func ValidateFilters(path string) []string
- func WriteDiscoveryInfo(version string) error
- type Config
- type CustomFilter
- type CustomFiltersConfig
- type DiscoveryInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConfigDir ¶ added in v1.21.0
func ConfigDir() string
ConfigDir returns the platform-specific directory for configuration files. On Unix: $XDG_CONFIG_HOME/chop or ~/.config/chop On Windows: %AppData%\chop
func DataDir ¶ added in v1.21.0
func DataDir() string
DataDir returns the platform-specific directory for state, logs, and database. On Unix: $XDG_DATA_HOME/chop or ~/.local/share/chop On Windows: %LocalAppData%\chop
func DiscoveryPath ¶ added in v1.26.0
DiscoveryPath returns the path to the discovery file.
func FiltersConfigPath ¶ added in v1.6.0
func FiltersConfigPath() string
FiltersConfigPath returns the path to the custom filters file.
func IsSecure ¶ added in v1.21.0
IsSecure checks if the given path is secure (owned by current user or root, and not world-writable). Parent directories are also checked recursively up to the root.
func LoadCustomFilters ¶ added in v1.6.0
func LoadCustomFilters() map[string]CustomFilter
LoadCustomFilters reads the custom filters config file. Global filters are trusted only if the config file is secure. Result is cached for the lifetime of the process.
func LoadCustomFiltersFrom ¶ added in v1.6.0
func LoadCustomFiltersFrom(path string) map[string]CustomFilter
LoadCustomFiltersFrom reads custom filters from a specific path as untrusted.
func LoadCustomFiltersWithLocal ¶ added in v1.6.0
func LoadCustomFiltersWithLocal(cwd string) map[string]CustomFilter
LoadCustomFiltersWithLocal loads global custom filters, then overlays a local .chop-filters.yml from the given directory (if it exists). Global filters are trusted; local ones are NOT. Local filters are merged on top of global ones (local wins on conflict).
func ParseCustomFilters ¶ added in v1.6.0
func ParseCustomFilters(data []byte) map[string]CustomFilter
ParseCustomFilters parses YAML bytes into a custom filters map as untrusted.
func Validate ¶ added in v1.28.0
Validate checks a config file for structural issues and returns a list of human-readable error strings. Returns nil if the file is valid.
func ValidateFilters ¶ added in v1.28.0
ValidateFilters checks a filters.yml file for issues: invalid YAML, bad regex patterns, and missing exec scripts. Returns nil if everything looks good.
func WriteDiscoveryInfo ¶ added in v1.26.0
WriteDiscoveryInfo writes discovery metadata to ~/.chop/path.json.
Types ¶
type Config ¶
Config holds user preferences loaded from ~/.config/chop/config.yml.
func Load ¶
func Load() Config
Load reads the config file and returns a Config. Returns defaults if the file doesn't exist or can't be parsed. Result is cached for the lifetime of the process.
func LoadWithLocal ¶ added in v1.1.0
LoadWithLocal loads the global config, then overlays a local .chop.yml from the given directory (if it exists). The local disabled list fully replaces the global one.
func (Config) IsDisabled ¶
IsDisabled returns true if the given command and args match an entry in the disabled list. Matching is prefix-based, so a shorter entry disables all commands that start with it.
Matching rules:
- "git" disables all git subcommands
- "git diff" disables any "git diff ..." invocation
- "git diff --cached" disables only that exact flag combination
Call with: IsDisabled("git", "diff", "--cached") or IsDisabled("git", "diff")
type CustomFilter ¶ added in v1.6.0
type CustomFilter struct {
Keep []string `yaml:"keep"` // regex patterns - only lines matching at least one are kept
Drop []string `yaml:"drop"` // regex patterns - lines matching any are removed
Head int `yaml:"head"` // keep only first N lines (applied after keep/drop)
Tail int `yaml:"tail"` // keep only last N lines (applied after keep/drop)
Exec string `yaml:"exec"` // external script: pipe output through this command
Trusted bool `yaml:"-"` // Internal: true if loaded from a trusted source
}
CustomFilter defines a user-configured output filter for a specific command.
func LookupCustomFilter ¶ added in v1.6.0
func LookupCustomFilter(filters map[string]CustomFilter, command string, args []string) *CustomFilter
LookupCustomFilter finds a custom filter for the given command and args. It checks "command subcommand" first, then falls back to "command". Keys are stored lowercased (see parseCustomFiltersWithTrust), so lookups are O(1) map accesses.
type CustomFiltersConfig ¶ added in v1.6.0
type CustomFiltersConfig struct {
Filters map[string]CustomFilter `yaml:"filters"`
}
CustomFiltersConfig holds the full filters.yml content.
type DiscoveryInfo ¶ added in v1.26.0
DiscoveryInfo contains information for AI agents to discover chop.