Documentation
¶
Overview ¶
Package userconfig manages the per-user CLI configuration: which provider the bare `m` command uses, the model id, and provider-specific connection details. API keys are intentionally excluded from this file — they live in the OS keychain (see keychain.go) so the YAML is safe to back up or sync.
Index ¶
- Variables
- func DeleteAPIKey(provider Provider) error
- func Exists() bool
- func GetAPIKey(provider Provider) (string, error)
- func GetAPIKeyByName(name string) (string, error)
- func GetAPIKeyWithFallback(provider Provider) (string, error)
- func IsKeyNotFound(err error) bool
- func IsNotExist(err error) bool
- func Path() (string, error)
- func Save(cfg *Config) error
- func SaveAPIKey(provider Provider, key string) error
- func SaveAPIKeyByName(name, key string) error
- func SaveState(st *State) error
- type Config
- type Provider
- type State
Constants ¶
This section is empty.
Variables ¶
var ErrSecretToolMissing = errors.New("secret-tool not found: install libsecret-tools (apt) or libsecret (dnf/pacman)")
ErrSecretToolMissing signals that the libsecret CLI (`secret-tool`) is not installed. The wizard catches this on Linux and offers to install it via the system package manager. Defined here (not in keychain_linux.go) so callers on every OS can reference it for cross-platform error matching with errors.Is.
Functions ¶
func DeleteAPIKey ¶
DeleteAPIKey removes a stored API key. Idempotent: missing entries are not an error.
func Exists ¶
func Exists() bool
Exists reports whether a config file is present. It does not validate it.
func GetAPIKey ¶
GetAPIKey retrieves a previously stored API key. Returns ErrKeyNotFound when no entry exists for that provider.
func GetAPIKeyByName ¶ added in v0.0.35
GetAPIKeyByName retrieves a secret by arbitrary name.
func GetAPIKeyWithFallback ¶
GetAPIKeyWithFallback tries the keychain first, then falls back to the corresponding environment variable. This allows users without keychain tooling to simply export the API key in their shell.
Returns the key string if found in either location, or an error if neither exists. For providers that don't require an API key (e.g., local Ollama), returns empty string and no error.
func IsKeyNotFound ¶
IsKeyNotFound reports whether err indicates a missing keychain entry.
func IsNotExist ¶
IsNotExist reports whether err indicates the config file is missing.
func Path ¶
Path returns the absolute path of the config file (~/.config/m/config.yaml on Linux/macOS).
func Save ¶
Save writes the config atomically with mode 0600. Atomic write avoids a half-truncated file if the process is killed mid-write.
func SaveAPIKey ¶
SaveAPIKey stores an API key for a provider in the OS keychain. macOS uses the `security` CLI (always available); Linux uses `secret-tool` from libsecret-tools (must be installed — see keychain_linux.go).
func SaveAPIKeyByName ¶ added in v0.0.35
SaveAPIKeyByName stores a secret by arbitrary name (for MCP tokens etc).
Types ¶
type Config ¶
type Config struct {
Provider Provider `yaml:"provider"`
Model string `yaml:"model"`
// BaseURL is set for LiteLLM (the proxy endpoint) and may be set for
// custom Ollama hosts. Empty for Anthropic / vanilla OpenAI.
BaseURL string `yaml:"base_url,omitempty"`
// DefaultAgent is an optional path to a custom .md agent file used by
// bare `m` instead of the embedded default. Empty means use the builtin.
DefaultAgent string `yaml:"default_agent,omitempty"`
}
Config is the on-disk schema. Fields are minimal on purpose: anything secret stays out (see keychain.go), and anything derivable from the model string is not duplicated.
type State ¶
type State struct {
LastSeenVersion string `yaml:"last_seen_version,omitempty"`
}
State is the on-disk record of what version's release notes the user has already been shown. Kept separate from Config because it's machine-managed, not user-edited: the wizard never writes it, and nothing user-visible references it.