Documentation
¶
Index ¶
- Constants
- Variables
- func Apply(base *config.Config, choices Choices) *config.Config
- func GlobalConfigPath() (string, error)
- func OllamaModels(ctx context.Context, baseURL string) ([]string, error)
- func RepoConfigPath(repoRoot string) string
- func Run(ctx context.Context, opts RunOptions) (*config.Config, error)
- func TestConnection(ctx context.Context, name string, cfg config.ProviderConfig) error
- func WriteConfig(path string, cfg *config.Config) error
- func WriteRepoConfig(repoRoot string, cfg *config.Config) (gitignoreUpdated bool, err error)
- type AliasOptions
- type AliasOutcome
- type Choices
- type ProviderSpec
- type RunOptions
Constants ¶
const (
OllamaDefaultBaseURL = "http://localhost:11434"
)
Variables ¶
var DefaultSpecs = []ProviderSpec{ { Name: "anthropic", Label: "Anthropic (Claude)", NeedsKey: true, Models: []string{"claude-opus-4-8", "claude-sonnet-4-6", "claude-haiku-4-5-20251001"}, APIKeyHelp: "Get an API key from https://console.anthropic.com/", }, { Name: "openai", Label: "OpenAI (GPT)", NeedsKey: true, Models: []string{"gpt-5.4-mini", "gpt-5.5", "gpt-5.5-pro", "gpt-4o", "gpt-4o-mini"}, APIKeyHelp: "Get an API key from https://platform.openai.com/", }, { Name: "gemini", Label: "Google Gemini", NeedsKey: true, Models: []string{"gemini-3.5-flash", "gemini-3.1-pro-preview", "gemini-3.1-flash-lite"}, APIKeyHelp: "Get an API key from https://aistudio.google.com/", }, { Name: "deepseek", Label: "DeepSeek", NeedsKey: true, Models: []string{"deepseek-chat", "deepseek-reasoner"}, APIKeyHelp: "Get an API key from https://platform.deepseek.com/", }, { Name: "mistral", Label: "Mistral", NeedsKey: true, Models: []string{"mistral-large-latest", "mistral-small-latest", "codestral-latest"}, APIKeyHelp: "Get an API key from https://console.mistral.ai/", }, { Name: "cohere", Label: "Cohere", NeedsKey: true, Models: []string{"command-r-plus", "command-r", "command-a-03-2025"}, APIKeyHelp: "Get an API key from https://dashboard.cohere.com/", }, { Name: "ollama", Label: "Ollama (local, no API key needed)", NeedsURL: true, }, }
DefaultSpecs lists the providers shown in the wizard. The Models slice is the user-facing static list; for Ollama (NeedsURL=true) the models are discovered dynamically via OllamaModels.
Functions ¶
func Apply ¶
Apply produces a Config from collected choices, layered on top of the supplied base. Pass nil to start from config.Default (first-time setup).
Critical: when base is the result of loading an existing config file, API keys and models for *other* providers are preserved intact — only the chosen provider's fields are touched. This is what makes `commitbrief setup` non-destructive across multiple providers.
func GlobalConfigPath ¶
GlobalConfigPath returns the canonical user-level config path.
func OllamaModels ¶
OllamaModels queries <baseURL>/api/tags and returns the names of the locally installed models. An empty baseURL falls back to the default.
func RepoConfigPath ¶
RepoConfigPath returns the canonical repo-level config path.
func Run ¶
Run drives the interactive wizard via huh. The terminal must support a TTY; callers should branch on non-TTY environments before invoking. Returns the final config (already persisted to disk per opts).
Run is non-destructive across providers: it loads the existing config file at the target path (global or repo, per opts.Local) before the wizard runs, then layers the user's choices on top. API keys for providers the user did *not* pick this round are preserved intact.
func TestConnection ¶
TestConnection instantiates the named provider with cfg and runs its TestConnection method. Errors flow through wrapped (provider sentinels preserved); a nil error means the credentials reached the backend and got a non-error response.
func WriteConfig ¶
WriteConfig serializes cfg to YAML at path. Parent directory is created with 0700 (config may contain API keys). Write is atomic: temp + rename.
func WriteRepoConfig ¶
WriteRepoConfig saves cfg under <repoRoot>/.commitbrief/config.yml and makes sure the repo's .gitignore excludes the .commitbrief/ directory. Returns whether .gitignore was modified so callers can surface a notice.
Types ¶
type AliasOptions ¶ added in v1.7.0
type AliasOptions struct {
// Name is the alias to install. Empty means "ask" (when Interactive)
// or "use alias.DefaultName" (when not).
Name string
// Interactive enables the huh prompts (shell picker, name input,
// conflict choice). The CLI sets it only on a TTY.
Interactive bool
// AutoYes (from --yes) auto-proceeds past a detected conflict instead
// of asking.
AutoYes bool
// Catalog localises the prompts and the conflict notice.
Catalog *i18n.Catalog
// Shell forces a specific installer by machine name ("zsh", "cmd", …);
// empty means detect from the environment. Used by tests.
Shell string
}
AliasOptions drives RunAlias, the interactive half of `commitbrief setup --alias`.
type AliasOutcome ¶ added in v1.7.0
type AliasOutcome struct {
Shell string // installer machine name actually used
Name string // alias name installed
Path string // where it was written
Changed bool // false when the block was already identical
ReloadCmd string // shell reload command, or "" ⇒ suggest a restart
Conflict string // non-empty when a conflict was detected and overridden
Canceled bool // user chose to cancel at the conflict prompt
}
AliasOutcome reports what RunAlias did so the CLI can print the localised result lines.
func RunAlias ¶ added in v1.7.0
func RunAlias(ctx context.Context, opts AliasOptions) (AliasOutcome, error)
RunAlias resolves the target shell, the alias name, checks for a conflict, and installs the alias. It performs no direct stdout I/O beyond the huh prompts — the CLI prints the localised result from the returned outcome.
type ProviderSpec ¶
type ProviderSpec struct {
Name string
Label string
NeedsKey bool
NeedsURL bool
Models []string
APIKeyHelp string
}
func FindSpec ¶
func FindSpec(name string) *ProviderSpec
type RunOptions ¶
type RunOptions struct {
Local bool
RepoRoot string
GlobalPath string
// Specs overrides DefaultSpecs (test injection).
Specs []ProviderSpec
// Catalog drives prompt titles, validation messages, and the
// connection-test result lines into the active locale. When nil,
// English defaults are used so package consumers without a catalog
// in hand (tests, library users) still get a functional wizard.
// The CLI layer always passes app.Catalog; see UC-16 in
// PATCH_ROADMAP.
Catalog *i18n.Catalog
}