{"modulePath":"github.com/CommitBrief/commitbrief","version":"v1.23.0","isLatest":true,"isStandardLibrary":false,"goos":"linux","goarch":"amd64","docs":"# package setup\n\n## Constants\n\n```go\nconst (\n\tOllamaDefaultBaseURL = \"http://localhost:11434\"\n)\n```\n\n## Functions\n\n```go\nfunc Apply(base *config.Config, choices Choices) *config.Config\n```\nApply produces a Config from collected choices, layered on top of the supplied base. Pass nil to start from config.Default (first-time setup).\n\nCritical: 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.\n\n```go\nfunc GlobalConfigPath() (string, error)\n```\nGlobalConfigPath returns the canonical user-level config path.\n\n```go\nfunc LoadRunConfig(opts RunOptions) (targetPath string, base *config.Config, err error)\n```\nLoadRunConfig 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.\n\nIt 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.\n\n```go\nfunc OllamaModels(ctx context.Context, baseURL string) ([]string, error)\n```\nOllamaModels queries \\\u003cbaseURL\u003e/api/tags and returns the names of the locally installed models. An empty baseURL falls back to the default.\n\n```go\nfunc RepoConfigPath(repoRoot string) string\n```\nRepoConfigPath returns the canonical repo-level config path.\n\n```go\nfunc Run(ctx context.Context, opts RunOptions) (*config.Config, error)\n```\nRun 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).\n\nRun 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.\n\n```go\nfunc TestConnection(ctx context.Context, name string, cfg config.ProviderConfig) error\n```\nTestConnection 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.\n\n```go\nfunc TestConnectionTimeout(ctx context.Context, name string, cfg config.ProviderConfig, d time.Duration) error\n```\nTestConnectionTimeout 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.\n\n```go\nfunc WriteConfig(path string, cfg *config.Config) error\n```\nWriteConfig serializes cfg to YAML at path. Parent directory is created with 0700 (config may contain API keys). Write is atomic: temp + rename.\n\n```go\nfunc WriteRepoConfig(repoRoot string, cfg *config.Config) (gitignoreUpdated bool, err error)\n```\nWriteRepoConfig saves cfg under \\\u003crepoRoot\u003e/.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.\n\n## Types\n\n```go\ntype AliasOptions struct {\n\t// Name is the alias to install. Empty means \"ask\" (when Interactive)\n\t// or \"use alias.DefaultName\" (when not).\n\tName string\n\n\t// Interactive enables the huh prompts (shell picker, name input,\n\t// conflict choice). The CLI sets it only on a TTY.\n\tInteractive bool\n\n\t// AutoYes (from --yes) auto-proceeds past a detected conflict instead\n\t// of asking.\n\tAutoYes bool\n\n\t// Catalog localises the prompts and the conflict notice.\n\tCatalog *i18n.Catalog\n\n\t// Shell forces a specific installer by machine name (\"zsh\", \"cmd\", …);\n\t// empty means detect from the environment. Used by tests.\n\tShell string\n}\n```\nAliasOptions drives RunAlias, the interactive half of \\`commitbrief setup --alias\\`.\n\n```go\ntype AliasOutcome struct {\n\tShell     string // installer machine name actually used\n\tName      string // alias name installed\n\tPath      string // where it was written\n\tChanged   bool   // false when the block was already identical\n\tReloadCmd string // shell reload command, or \"\" ⇒ suggest a restart\n\tConflict  string // non-empty when a conflict was detected and overridden\n\tCanceled  bool   // user chose to cancel at the conflict prompt\n}\n```\nAliasOutcome reports what RunAlias did so the CLI can print the localised result lines.\n\n```go\nfunc RunAlias(ctx context.Context, opts AliasOptions) (AliasOutcome, error)\n```\nRunAlias 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.\n\n```go\ntype Choices struct {\n\tProvider string\n\tAPIKey   string\n\tModel    string\n\tBaseURL  string\n\tLang     string\n}\n```\n\n```go\ntype ProviderSpec struct {\n\tName       string\n\tLabel      string\n\tNeedsKey   bool\n\tNeedsURL   bool\n\tModels     []string\n\tAPIKeyHelp string\n}\n```\n\n```go\nfunc FindSpec(name string) *ProviderSpec\n```\nFindSpec 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.\n\n```go\nfunc Specs() []ProviderSpec\n```\nSpecs returns the providers the wizard offers, with each one's model list read from the provider metadata registry at call time.\n\nIt 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).\n\nOllama 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.\n\n```go\ntype RunOptions struct {\n\tLocal      bool\n\tRepoRoot   string\n\tGlobalPath string\n\n\t// Specs overrides the Specs() default list (test injection).\n\tSpecs []ProviderSpec\n\n\t// Catalog drives prompt titles, validation messages, and the\n\t// connection-test result lines into the active locale. When nil,\n\t// English defaults are used so package consumers without a catalog\n\t// in hand (tests, library users) still get a functional wizard.\n\t// The CLI layer always passes app.Catalog; see UC-16 in\n\t// PATCH_ROADMAP.\n\tCatalog *i18n.Catalog\n\n\t// IgnoreUnknownKeys mirrors `commitbrief --ignore-unknown-config`: when\n\t// set, loading the existing config at the target path tolerates a key\n\t// the schema doesn't define instead of failing the wizard outright.\n\t// setup is the tool's own repair path for a broken config file, so it\n\t// must never be the one command the escape hatch can't reach — the CLI\n\t// layer has already warned about the offending key via resolveContext\n\t// before Run is called, so this load stays silent about it.\n\t//\n\t// Unlike `config set` / `providers use` (internal/cli/config.go,\n\t// providers.go), Run does NOT refuse to write when the load reports an\n\t// ignored key (Wave 0 review turu 2, item 6). Those two commands refuse\n\t// because they decode the file into a typed config.Config and rewrite\n\t// the WHOLE thing, so an unknown key has nowhere to land and is\n\t// silently destroyed by the round-trip. Run has exactly the same\n\t// decode-and-rewrite shape, but it is the deliberate exception: it is\n\t// the tool's own from-scratch recovery path for a config broken enough\n\t// to need this flag, has no claim to preserving content it never\n\t// understood in the first place, and refusing it here would relock the\n\t// exact user the escape hatch exists to rescue.\n\tIgnoreUnknownKeys bool\n}\n```\n\n","path":"github.com/CommitBrief/commitbrief/internal/setup","name":"setup","synopsis":"","isRedistributable":true}
