config

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const EnvPrefix = "KETCH_"

EnvPrefix is the prefix for every ketch environment variable.

Variables

This section is empty.

Functions

func AvailableBackends

func AvailableBackends() []string

AvailableBackends returns the list of known search backends.

func AvailableCodeBackends

func AvailableCodeBackends() []string

AvailableCodeBackends returns the list of known code search backends.

func AvailableDocBackends

func AvailableDocBackends() []string

AvailableDocBackends returns the list of usable docs backends. The local FTS5 backend is planned but not implemented, so it is not advertised here; docs.NewFromConfig still recognizes "local" and rejects it with a clear precondition error.

func EnvVar added in v0.13.0

func EnvVar(key string) string

EnvVar returns the environment variable name for a config key: "KETCH_" + UPPER_SNAKE of the JSON key.

func Path

func Path() (string, error)

Path returns the config file path: $KETCH_CONFIG if set, otherwise ~/.config/ketch/config.json. KETCH_CONFIG redirects reads and writes (config set) alike.

func Save

func Save(cfg Config) error

Save writes the config to disk, creating the directory if needed.

func ScrubbedEnviron added in v0.13.0

func ScrubbedEnviron() []string

ScrubbedEnviron returns os.Environ() with every KETCH_* secret variable (API keys, tokens) removed. Use it for spawned subprocesses (headless browser, external PDF converter) so injected credentials don't leak.

Types

type Config

type Config struct {
	Backend                            string            `json:"backend"`
	SearxngURL                         string            `json:"searxng_url"`
	BraveAPIKey                        string            `json:"brave_api_key,omitempty"`
	BraveAPIKeys                       []string          `json:"brave_api_keys,omitempty"`
	ExaAPIKey                          string            `json:"exa_api_key,omitempty"`
	ExaAPIKeys                         []string          `json:"exa_api_keys,omitempty"`
	FirecrawlAPIKey                    string            `json:"firecrawl_api_key,omitempty"`
	FirecrawlAPIKeys                   []string          `json:"firecrawl_api_keys,omitempty"`
	KeenableAPIKey                     string            `json:"keenable_api_key,omitempty"`
	KeenableAPIKeys                    []string          `json:"keenable_api_keys,omitempty"`
	Limit                              int               `json:"limit"`
	CacheTTL                           string            `json:"cache_ttl"`
	Browser                            string            `json:"browser,omitempty"` // "chrome", "chromium", or absolute path; empty = disabled
	CodeBackend                        string            `json:"code_backend,omitempty"`
	DocsBackend                        string            `json:"docs_backend,omitempty"`
	Context7APIKey                     string            `json:"context7_api_key,omitempty"`
	SourcegraphURL                     string            `json:"sourcegraph_url,omitempty"`
	GithubToken                        string            `json:"github_token,omitempty"`
	URLRewrites                        []urlrewrite.Rule `json:"url_rewrites,omitempty"`
	SPAMarkers                         []string          `json:"spa_markers,omitempty"`
	CookieFile                         string            `json:"cookie_file,omitempty"` // Netscape cookies.txt path; empty = disabled
	UserAgent                          string            `json:"user_agent,omitempty"`  // HTTP User-Agent override; empty = built-in honest default
	ExternalPDFToMDConverterCommand    string            `json:"external_pdf_to_md_converter_command,omitempty"`
	ExternalPDFToMDConverterTimeoutSec int               `json:"external_pdf_to_md_converter_timeout_sec"`
}

Config holds user-configurable defaults for ketch.

func Defaults

func Defaults() Config

Defaults returns the built-in default configuration.

func LoadFile added in v0.13.0

func LoadFile() Config

LoadFile reads the config file only (no env overlay), falling back to defaults for missing fields. `ketch config set` reads and writes through LoadFile so env-derived values are never persisted into the file.

func (Config) BraveKeys added in v0.12.0

func (c Config) BraveKeys() []string

BraveKeys returns an immutable copy of the effective Brave API key pool.

func (Config) ExaKeys added in v0.12.0

func (c Config) ExaKeys() []string

ExaKeys returns an immutable copy of the effective Exa API key pool.

func (Config) FirecrawlKeys added in v0.12.0

func (c Config) FirecrawlKeys() []string

FirecrawlKeys returns an immutable copy of the effective Firecrawl API key pool.

func (Config) KeenableKeys added in v0.12.0

func (c Config) KeenableKeys() []string

KeenableKeys returns an immutable copy of the effective Keenable API key pool.

func (Config) ResolveGithubToken

func (c Config) ResolveGithubToken() (token, source string)

ResolveGithubToken returns a token and the source it came from, walking the resolution chain: $KETCH_GITHUB_TOKEN → explicit config → $GITHUB_TOKEN → $GH_TOKEN → `gh auth token`. github_token is deliberately excluded from the generic env overlay so this chain stays the single owner of its precedence. Source is one of: "config", "env", "gh-cli", "none". The token is never logged.

type LoadResult added in v0.13.0

type LoadResult struct {
	Config    Config
	Overrides []Override
}

LoadResult is the outcome of Load: the effective config plus the provenance of every env-overridden key.

func Load

func Load() (LoadResult, error)

Load returns the effective config: file values overlaid with KETCH_* environment variables (precedence: env > file > default), plus the provenance of every env override. On invalid env values it returns a best-effort config (valid vars applied, invalid ones skipped) alongside a descriptive error; callers decide when to surface it.

type Override added in v0.13.0

type Override struct {
	Key      string `json:"key"`                // JSON config key, e.g. "limit"
	Var      string `json:"var"`                // env var applied, e.g. "KETCH_LIMIT"
	Previous string `json:"previous,omitempty"` // value replaced (file or default); redacted for secrets
}

Override records one config key whose value came from the environment.

Jump to

Keyboard shortcuts

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