config

package
v0.2.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package config resolves baum settings from flags, the environment, the XDG config file and defaults, in that order of precedence.

Local review commands contact no baum server and send no telemetry; the file holds the backend choice, optional tokens and generation budgets, nothing else.

Index

Constants

View Source
const (
	EnvGitHubToken     = "GITHUB_TOKEN"
	EnvGHToken         = "GH_TOKEN"
	EnvAnthropicAPIKey = "ANTHROPIC_API_KEY"
	EnvBackend         = "BAUM_BACKEND"
	EnvModel           = "BAUM_MODEL"
)

Environment variables read by Load.

View Source
const (
	DefaultReviewTimeout = 10 * time.Minute
	DefaultRunTimeout    = 30 * time.Minute
)

Default time limits (Budgets).

View Source
const GitHubHost = "github.com"

GitHubHost is github.com, the host GITHUB_TOKEN, GH_TOKEN and github_token belong to.

View Source
const MaxAgentEnv = 32

MaxAgentEnv bounds how many variables AgentEnv may set.

View Source
const SourceBaum = "baum credential store"
View Source
const SourceConfigFile = "config file"

SourceConfigFile is the GitHubTokenSource of github_token in the config file.

Variables

Backends lists every accepted backend name, Auto first.

View Source
var CapDefaults = map[string]int{
	"max_sessions":                   12,
	"max_prompts_per_session":        2,
	"max_command_events_per_session": 20,
	"max_comments":                   40,
	"max_hunk_patch_lines":           200,
	"max_bytes":                      262144,
	"max_diff_files":                 3000,
	"max_diff_patch_bytes":           100 << 20,
	"max_diff_index_bytes":           512 << 10,
	"max_images":                     20,
	"max_image_bytes":                10 << 20,
	"max_image_alt_bytes":            512,
	"checkout_max_file_bytes":        1 << 20,
	"checkout_max_total_bytes":       200 << 20,
	"checkout_max_total_files":       20000,
}

CapDefaults are the generation bundle caps by name, which the [caps] table of the config file overrides. The values are the hosted service's defaults, so the same pull request is trimmed the same way in both places. Byte caps are bytes; the rest are counts or line counts.

View Source
var Efforts = []string{"low", "medium", "high", "xhigh", "max", "ultra"}

Efforts are the reasoning efforts the app offers, passed to Claude Code as --effort, to Codex as model_reasoning_effort and to the Anthropic API as output_config.effort; cursor-agent has none.

View Source
var ErrNoGitHubToken = errors.New("no GitHub token")

GitHubAuth is shared by every token consumer and the local authentication API.

PathBackends are the backends whose executable BackendPaths can name.

Functions

func CapNames

func CapNames() []string

CapNames lists the accepted cap names, sorted.

func DeviceOrganizations added in v0.2.0

func DeviceOrganizations(ctx context.Context, c Config, refresh bool) (githubauth.OrganizationAccess, error)

DeviceOrganizations names the organizations the saved device sign-in cannot reach (githubauth.Manager.Organizations). An explicit token is not asked: a fine-grained one lists no organizations at all, which would read as every membership being hidden.

func ParseEffort

func ParseEffort(s string) (*string, error)

ParseEffort reads a chosen effort case-insensitively: nil for an empty one, which is the harness's own and no choice.

func Path

func Path() (string, error)

Path returns the config file location: $XDG_CONFIG_HOME/baum/config.toml, defaulting to ~/.config/baum/config.toml.

func Save

func Save(path string, cfg Config) error

Save writes cfg to path, creating the directory 0700 and the file 0600 so a stored token is readable by the user only.

func ValidEffort

func ValidEffort(effort string) bool

ValidEffort reports whether effort is empty (the harness's own) or one of Efforts.

func ValidateAgentEnv

func ValidateAgentEnv(env map[string]string) error

ValidateAgentEnv rejects a name that is not a portable variable name, a value with a NUL byte or longer than 4 KiB, and more than MaxAgentEnv variables.

Types

type Backend

type Backend string

Backend names a model backend. Auto picks one at run time: claude, then codex, each when installed and passing its checks, then, in the command line only, anthropic when ANTHROPIC_API_KEY is set. cursor-agent runs only when named. The desktop app and its daemon run auto, claude and codex only (Backend.Desktop).

const (
	BackendAuto        Backend = "auto"
	BackendAnthropic   Backend = "anthropic"
	BackendClaude      Backend = "claude"
	BackendCodex       Backend = "codex"
	BackendCursorAgent Backend = "cursor-agent"
)

func ParseBackend

func ParseBackend(s string) (Backend, error)

ParseBackend accepts a backend name case-insensitively.

func (Backend) Desktop

func (b Backend) Desktop() bool

Desktop reports whether the desktop app and its daemon run jobs with b: auto, claude and codex. cursor-agent and anthropic remain backends of the command line only.

func (Backend) Valid

func (b Backend) Valid() bool

Valid reports whether b is one of Backends.

type Budgets

type Budgets struct {
	PassTimeout   Duration `toml:"pass_timeout"`
	ReviewTimeout Duration `toml:"review_timeout"`
	RunTimeout    Duration `toml:"run_timeout"`
	MaxCalls      int      `toml:"max_calls,omitempty"`
	MaxTokens     int      `toml:"max_tokens,omitempty"`
}

Budgets bound agent runs. Exceeding one fails the run naming it. ReviewTimeout is a review's time limit and RunTimeout that of every other agent run (a fix, a question to a review's agent, a feature build); PassTimeout bounds each model call. MaxCalls and MaxTokens bound each run when set; zero, the default, is no limit, so only the time limit ends a run.

func (Budgets) Validate

func (b Budgets) Validate() error

Validate requires positive time limits and call and token budgets that are zero (no limit) or positive.

type Config

type Config struct {
	Backend Backend `toml:"backend"`
	Model   string  `toml:"model,omitempty"`
	// Effort is the reasoning effort the app chose (Efforts); empty leaves
	// it to the harness. It is never read from or written to the file.
	Effort      string `toml:"-"`
	GitHubToken string `toml:"github_token,omitempty"`
	// GitHubTokenSource names where GitHubToken came from: GITHUB_TOKEN,
	// GH_TOKEN or the config file. It is empty when there is no token and is
	// never written to the file.
	GitHubTokenSource string `toml:"-"`
	// AnthropicAPIKey comes from the environment only and is never written to
	// the file.
	AnthropicAPIKey string  `toml:"-"`
	Budgets         Budgets `toml:"budgets"`
	// Caps override the generation bundle caps by name; unnamed caps keep their
	// defaults. Names are defined by the bundle assembler.
	Caps map[string]int `toml:"caps,omitempty"`
	// BackendPaths names the executable of a backend by absolute path. A named
	// path is used instead of a PATH lookup, never in addition to one, so apps
	// started without the shell's PATH still find their backends. Only claude,
	// codex and cursor-agent are accepted; per-repository settings do not
	// override it.
	BackendPaths map[Backend]string `toml:"backend_paths,omitempty"`
	// AgentEnv are variables set for every agent baum runs on this computer
	// and for the git commands that commit and push a fix, over the inherited
	// environment: for example GIT_CONFIG_GLOBAL, to sign an agent's commits
	// with another key. The app's own choice replaces it (repos.Preferences).
	AgentEnv map[string]string `toml:"agent_env,omitempty"`
}

Config is the resolved configuration. Its TOML form is the on-disk file.

func Default

func Default() Config

Default is the configuration with nothing set anywhere.

func Load

func Load(overrides Overrides) (Config, error)

Load resolves the configuration with the precedence flags, environment, file, defaults. A missing file is not an error.

func ReadFile

func ReadFile(path string) (cfg Config, ok bool, err error)

ReadFile parses the config file at path over the defaults. ok is false when the file does not exist.

func (Config) AgentEnviron

func (c Config) AgentEnviron() []string

AgentEnviron is AgentEnv as "NAME=value" entries sorted by name, each value with a leading ~ and $NAME or ${NAME} expanded from this process's environment, as a shell would.

func (Config) EffectiveCaps

func (c Config) EffectiveCaps() (map[string]int, error)

EffectiveCaps returns every cap: the defaults with the configured overrides applied. An unknown name or a negative value is an error, so a misspelt override is not silently ignored.

func (Config) ExplicitGitHubTokenSource

func (c Config) ExplicitGitHubTokenSource(host string) (string, string)

ExplicitGitHubTokenSource resolves overrides without opening the keyring. Enterprise credentials apply only to the explicitly selected GH_HOST.

func (Config) ResolveGitHubToken

func (c Config) ResolveGitHubToken(ctx context.Context, host string) (string, error)

func (Config) ResolveGitHubTokenSource

func (c Config) ResolveGitHubTokenSource(ctx context.Context, host string) (string, string, error)

type Duration

type Duration time.Duration

Duration is a time.Duration written in TOML as a string such as "10m".

func (Duration) MarshalText

func (d Duration) MarshalText() ([]byte, error)

MarshalText renders d with time.Duration's String.

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(text []byte) error

UnmarshalText parses d with time.ParseDuration.

type Overrides

type Overrides struct {
	Backend string
	Model   string
	// Path replaces the default config file location.
	Path string
}

Overrides are the flag values, which take precedence over everything else. Empty strings mean "not given".

Jump to

Keyboard shortcuts

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