setup

package
v1.17.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2026 License: GPL-3.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	OllamaDefaultBaseURL = "http://localhost:11434"
)

Variables

This section is empty.

Functions

func Apply

func Apply(base *config.Config, choices Choices) *config.Config

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

func GlobalConfigPath() (string, error)

GlobalConfigPath returns the canonical user-level config path.

func LoadRunConfig added in v1.17.0

func LoadRunConfig(opts RunOptions) (targetPath string, base *config.Config, err error)

LoadRunConfig performs the pure, non-interactive first step of Run: resolving where the wizard will write (repo-local or user-level, per opts.Local) and loading any existing config already at that path, honoring opts.IgnoreUnknownKeys exactly as Run does. It runs entirely before any prompt is constructed and touches no terminal.

It is split out of Run so callers — this package's own tests, and internal/cli's — can assert "did config validation let this proceed" without a controlling terminal. huh cannot be driven headlessly: it blocks in a raw console read that observes neither context cancellation nor a redirected stdin, and on a runner that still has a console attached (Windows CI) it never fails fast the way it does on a TTY-less Linux/macOS runner — so a test that only reaches this point through the real prompt is racing a 10-minute per-package timeout on one platform and not the others. Exercising this function directly instead makes the assertion deterministic on every platform.

func OllamaModels

func OllamaModels(ctx context.Context, baseURL string) ([]string, error)

OllamaModels queries <baseURL>/api/tags and returns the names of the locally installed models. An empty baseURL falls back to the default.

func RepoConfigPath

func RepoConfigPath(repoRoot string) string

RepoConfigPath returns the canonical repo-level config path.

func Run

func Run(ctx context.Context, opts RunOptions) (*config.Config, error)

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

func TestConnection(ctx context.Context, name string, cfg config.ProviderConfig) error

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 TestConnectionTimeout added in v1.16.0

func TestConnectionTimeout(ctx context.Context, name string, cfg config.ProviderConfig, d time.Duration) error

TestConnectionTimeout is TestConnection with the caller's resolved --timeout / review.timeout value handed to the provider. It matters for the same reason it does on the review path: a probe against a slow ollama host or a CLI binary would otherwise die at the provider's own built-in cap no matter how much time the user allowed. A zero d keeps every built-in exactly as it is.

func WriteConfig

func WriteConfig(path string, cfg *config.Config) error

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

func WriteRepoConfig(repoRoot string, cfg *config.Config) (gitignoreUpdated bool, err error)

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 Choices

type Choices struct {
	Provider string
	APIKey   string
	Model    string
	BaseURL  string
	Lang     string
}

type ProviderSpec

type ProviderSpec struct {
	Name       string
	Label      string
	NeedsKey   bool
	NeedsURL   bool
	Models     []string
	APIKeyHelp string
}

func FindSpec

func FindSpec(name string) *ProviderSpec

FindSpec looks up one provider's wizard spec, or nil when the wizard does not offer that provider. The returned pointer addresses a fresh copy, so mutating it changes nothing for the next caller.

func Specs added in v1.17.0

func Specs() []ProviderSpec

Specs returns the providers the wizard offers, with each one's model list read from the provider metadata registry at call time.

It is a function rather than a package-level var for two reasons. The registry is populated by init() in the provider packages that cmd/commitbrief/main.go blank-imports, so a var initialised at package load could observe it half-built; and building fresh means the wizard can never show a model list that has drifted from the provider's own supportedModels table, which is what the hand-copied literals this replaced kept doing (gemini's order had already diverged).

Ollama is the one provider with no static list: it serves whatever the user has pulled, so selectModel asks the daemon through OllamaModels and never reads Models. Copying the registry's handful of suggestions in would present them as the supported set.

type RunOptions

type RunOptions struct {
	Local      bool
	RepoRoot   string
	GlobalPath string

	// Specs overrides the Specs() default list (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

	// IgnoreUnknownKeys mirrors `commitbrief --ignore-unknown-config`: when
	// set, loading the existing config at the target path tolerates a key
	// the schema doesn't define instead of failing the wizard outright.
	// setup is the tool's own repair path for a broken config file, so it
	// must never be the one command the escape hatch can't reach — the CLI
	// layer has already warned about the offending key via resolveContext
	// before Run is called, so this load stays silent about it.
	//
	// Unlike `config set` / `providers use` (internal/cli/config.go,
	// providers.go), Run does NOT refuse to write when the load reports an
	// ignored key (Wave 0 review turu 2, item 6). Those two commands refuse
	// because they decode the file into a typed config.Config and rewrite
	// the WHOLE thing, so an unknown key has nowhere to land and is
	// silently destroyed by the round-trip. Run has exactly the same
	// decode-and-rewrite shape, but it is the deliberate exception: it is
	// the tool's own from-scratch recovery path for a config broken enough
	// to need this flag, has no claim to preserving content it never
	// understood in the first place, and refusing it here would relock the
	// exact user the escape hatch exists to rescue.
	IgnoreUnknownKeys bool
}

Jump to

Keyboard shortcuts

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