Implementation:1broseidon Ketch cmd Config
| Knowledge Sources | |
|---|---|
| Domains | Configuration, CLI |
| Last Updated | 2026-10-27 00:00 GMT |
Overview
Concrete command surface for discovering, initializing, and mutating operator config — the `ketch config` family (show, init, set, path) backed by a discovery payload that never prints secret values.
Description
The configCmd tree in `cmd/config.go` implements four subcommands. `config show` (the default) emits a JSON discovery payload built by buildConfigInfo: every effective setting plus `*_key_set`-style presence booleans and available-backend lists, with secrets represented only by name. `config init` writes `config.Defaults()` to the config path, refusing to clobber an existing file. `config set <key> <value>` round-trips the file via `config.LoadFile` (never the env-overlayed `Load`) so KETCH_* env values are never persisted, dispatches through `applyConfigSet` (one arm per config key, plus the shared `ProviderSettings` loop), validates the value, and writes back with `config.Save`. `config path` prints the resolved path.
The design ensures `config set` validates before persisting — cookies must parse, the external PDF command must construct, the backend must be known — and never echoes a secret value even in error messages (the `configSecretCount` acknowledgement names the key by position, not value).
Usage
Run `ketch config` to inspect what a fresh install sees; `ketch config set` to configure a backend, key, or behavior flag without editing JSON; `ketch config init` to scaffold a default file. Agents read the JSON `*_set` booleans to decide whether a backend is ready without ever touching a value.
Code Reference
Source Location
- Repository: ketch
- File: cmd/config.go
- Lines: 1-507
Signature
// configInfo is the discovery payload returned by `ketch config`.
type configInfo struct {
ConfigPath string `json:"config_path" order:"0"`
Backend string `json:"backend" order:"1"`
// ... every effective setting ...
Providers map[string]any `json:"-"`
ProviderFields []configbase.Field `json:"-"`
}
var configCmd = &cobra.Command{Use: "config", RunE: runConfigShow}
var configInitCmd = &cobra.Command{Use: "init", RunE: runConfigInit}
var configSetCmd = &cobra.Command{Use: "set <key> <value>", Args: exitArgs(cobra.ExactArgs(2)), RunE: runConfigSet}
var configPathCmd = &cobra.Command{Use: "path", RunE: runConfigPath}
func buildConfigInfo(c config.Config, path string) configInfo
func applyConfigSet(c *config.Config, key, value string) error
func (info configInfo) MarshalJSON() ([]byte, error)
Import
import "github.com/1broseidon/ketch/cmd"
// invoked as the `ketch config` subcommand tree
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| key | string | `set` only | The config key to mutate (validated against `validConfigKeys`) |
| value | string | `set` only | The new value; validated per-key before persist |
| cfg | config.Config | internal | Effective config loaded at init (file + env overlay) |
| path | string | internal | Resolved config file path (`KETCH_CONFIG` or `~/.config/ketch/config.json`) |
Outputs
| Name | Type | Description |
|---|---|---|
| stdout (show) | JSON | The configInfo discovery payload |
| stdout (path) | string | The resolved config file path |
| stderr (set/init) | string | Acknowledgement or "created" notice |
| error | error | `[validation]` for unknown key/bad value; `[precondition]` when init would clobber |
Usage Examples
Discover the effective config
ketch config
# Emits JSON: backend, limit, available_backends, *_key_set booleans, env_overrides, ...
Set a backend API key
ketch config set brave_api_key BSA...
# stderr: "set brave_api_key (1 key)"
# Validates the cookie_file / external command before persist; never echoes the value.
Configure a SearXNG instance URL
ketch config set searxng_url http://localhost:8081
# Stored to file; `KETCH_SEARXNG_URL` env overlay still applies on top at runtime.