config

package
v0.62.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigWarningWriter io.Writer = os.Stderr

ConfigWarningWriter is the destination for config warnings. Defaults to os.Stderr. Can be replaced for testing or custom logging.

View Source
var ConfigWarnings = true

ConfigWarnings controls whether warnings are logged for invalid config values. Set to false to suppress warnings (useful for tests or scripts).

View Source
var YamlOnlyKeys = map[string]bool{

	"no-db": true,
	"json":  true,

	"db":       true,
	"actor":    true,
	"identity": true,

	"git.author":      true,
	"git.no-gpg-sign": true,
	"no-push":         true,
	"no-git-ops":      true,

	"sync.git-remote":                          true,
	"sync.require_confirmation_on_mass_delete": true,

	"routing.mode":        true,
	"routing.default":     true,
	"routing.maintainer":  true,
	"routing.contributor": true,

	"create.require-description": true,

	"validation.on-create": true,
	"validation.on-sync":   true,

	"hierarchy.max-depth": true,

	"backup.enabled":  true,
	"backup.interval": true,
	"backup.git-push": true,
	"backup.git-repo": true,

	"dolt.idle-timeout":  true,
	"dolt.shared-server": true,
}

YamlOnlyKeys are configuration keys that must be stored in config.yaml rather than the database. These are "startup" settings that are read before the database is opened.

This fixes GH#536: users were confused when `bd config set no-db true` appeared to succeed but had no effect (because no-db is read from yaml at startup, not from the database).

Functions

func AddRepo

func AddRepo(configPath, repoPath string) error

AddRepo adds a repository to the repos.additional list in config.yaml If primary is not set, it defaults to "."

func AllSettings

func AllSettings() map[string]interface{}

AllSettings returns all configuration settings as a map

func ConfigFileUsed

func ConfigFileUsed() string

ConfigFileUsed returns the path to the config file that was loaded. Returns empty string if no config file was found or viper is not initialized. This is useful for resolving relative paths from the config file's directory.

func DefaultAIModel

func DefaultAIModel() string

DefaultAIModel returns the configured AI model identifier. Override via: bd config set ai.model "model-name" or BD_AI_MODEL=model-name

func FindConfigYAMLPath

func FindConfigYAMLPath() (string, error)

FindConfigYAMLPath finds the config.yaml file in .beads directory Walks up from CWD to find .beads/config.yaml

func GetBool

func GetBool(key string) bool

GetBool retrieves a boolean configuration value

func GetCustomStatusesFromYAML

func GetCustomStatusesFromYAML() []string

GetCustomStatusesFromYAML retrieves custom statuses from config.yaml. This is used as a fallback when the database doesn't have status.custom set yet or when the database connection is temporarily unavailable. Returns nil if no custom statuses are configured in config.yaml.

func GetCustomTypesFromYAML

func GetCustomTypesFromYAML() []string

GetCustomTypesFromYAML retrieves custom issue types from config.yaml. This is used as a fallback when the database doesn't have types.custom set yet (e.g., during bd init auto-import before the database is fully configured). Returns nil if no custom types are configured in config.yaml.

func GetDirectoryLabels

func GetDirectoryLabels() []string

GetDirectoryLabels returns labels for the current working directory based on config. It checks directory.labels config for matching patterns. Returns nil if no labels are configured for the current directory.

func GetDuration

func GetDuration(key string) time.Duration

GetDuration retrieves a duration configuration value

func GetExternalProjects

func GetExternalProjects() map[string]string

GetExternalProjects returns the external_projects configuration. Maps project names to paths for cross-project dependency resolution. Example config.yaml:

external_projects:
  beads: ../beads
  gastown: /absolute/path/to/gastown

func GetIdentity

func GetIdentity(flagValue string) string

GetIdentity resolves the user's identity for messaging. Priority chain:

  1. flagValue (if non-empty, from --identity flag)
  2. BEADS_IDENTITY env var / config.yaml identity field (via viper)
  3. git config user.name
  4. hostname

This is used as the sender field in bd mail commands.

func GetInfraTypesFromYAML

func GetInfraTypesFromYAML() []string

GetInfraTypesFromYAML retrieves infrastructure type names from config.yaml. Infrastructure types are routed to the wisps table instead of the versioned issues table. Returns nil if no infra types are configured in config.yaml (caller should use defaults).

func GetInt

func GetInt(key string) int

GetInt retrieves an integer configuration value

func GetNamedRoles

func GetNamedRoles() []string

GetNamedRoles returns roles that can have multiple named instances per rig. These roles include a name suffix: <prefix>-<rig>-<role>-<name>

func GetRigLevelRoles

func GetRigLevelRoles() []string

GetRigLevelRoles returns roles that are rig-level singletons. These roles have one instance per rig: <prefix>-<rig>-<role>

func GetString

func GetString(key string) string

GetString retrieves a string configuration value

func GetStringFromDir

func GetStringFromDir(beadsDir, key string) string

GetStringFromDir reads a single string configuration value directly from <beadsDir>/config.yaml without using or modifying global viper state. This is intended for library consumers that call NewFromConfigWithOptions without first invoking config.Initialize().

The key uses dotted notation (e.g. "dolt.auto-start"). YAML booleans and numbers are coerced to their string representations ("true", "false", etc.). Returns "" if the file is absent, the key is not found, or any error occurs.

func GetStringMapString

func GetStringMapString(key string) map[string]string

GetStringMapString retrieves a map[string]string configuration value

func GetStringSlice

func GetStringSlice(key string) []string

GetStringSlice retrieves a string slice configuration value

func GetTownLevelRoles

func GetTownLevelRoles() []string

GetTownLevelRoles returns roles that are town-level singletons. These roles have no rig association and appear as: <prefix>-<role>

func GetYamlConfig

func GetYamlConfig(key string) string

GetYamlConfig gets a configuration value from config.yaml. Returns empty string if key is not found or is commented out. Keys are normalized to their canonical yaml format (e.g., sync.branch -> sync-branch).

func Initialize

func Initialize() error

Initialize sets up the viper configuration singleton Should be called once at application startup

func IsValidSovereignty

func IsValidSovereignty(sovereignty string) bool

IsValidSovereignty returns true if the given string is a valid sovereignty tier. Empty string is valid (means no restriction).

func IsYamlOnlyKey

func IsYamlOnlyKey(key string) bool

IsYamlOnlyKey returns true if the given key should be stored in config.yaml rather than the Dolt database.

func LogOverride

func LogOverride(override ConfigOverride)

LogOverride logs a message about a configuration override in verbose mode.

func MetadataSchemaFields

func MetadataSchemaFields() map[string]interface{}

MetadataSchemaFields returns the raw field definitions from config. Returns nil if config is not initialized or no fields are defined. Each entry maps field name → map of properties (type, values, required, min, max).

func MetadataValidationMode

func MetadataValidationMode() string

MetadataValidationMode returns the metadata schema validation mode. Returns "none" if config is not initialized or mode is empty/unknown.

func RemoveRepo

func RemoveRepo(configPath, repoPath string) error

RemoveRepo removes a repository from the repos.additional list in config.yaml

func ResetForTesting

func ResetForTesting()

ResetForTesting clears the config state, allowing Initialize() to be called again. This is intended for tests that need to change config.yaml between test steps. WARNING: Not thread-safe. Only call from single-threaded test contexts.

func ResolveExternalProjectPath

func ResolveExternalProjectPath(projectName string) string

ResolveExternalProjectPath resolves a project name to its absolute path. Returns empty string if project not configured or path doesn't exist.

func SaveConfigValue

func SaveConfigValue(key string, value interface{}, beadsDir string) error

SaveConfigValue sets a key-value pair and writes it to the config file. If no config file is currently loaded, it creates config.yaml in the given beadsDir. Only the specified key is modified; other file contents are preserved.

func Set

func Set(key string, value interface{})

Set sets a configuration value

func SetReposInYAML

func SetReposInYAML(configPath string, repos *ReposConfig) error

SetReposInYAML writes the repos configuration to config.yaml It preserves other config sections and comments where possible

func SetYamlConfig

func SetYamlConfig(key, value string) error

SetYamlConfig sets a configuration value in the project's config.yaml file. It handles both adding new keys and updating existing (possibly commented) keys. Keys are normalized to their canonical yaml format (e.g., sync.branch -> sync-branch).

func ValidSovereigntyTiers

func ValidSovereigntyTiers() []string

ValidSovereigntyTiers returns the list of valid sovereignty tier values.

Types

type ConfigOverride

type ConfigOverride struct {
	Key            string
	EffectiveValue interface{}
	OverriddenBy   ConfigSource
	OriginalSource ConfigSource
	OriginalValue  interface{}
}

ConfigOverride represents a detected configuration override

func CheckOverrides

func CheckOverrides(flagOverrides map[string]struct {
	Value  interface{}
	WasSet bool
}) []ConfigOverride

CheckOverrides checks for configuration overrides and returns a list of detected overrides. This is useful for informing users when env vars or flags override config file values. flagOverrides is a map of key -> (flagValue, flagWasSet) for flags that were explicitly set.

type ConfigSource

type ConfigSource string

ConfigSource represents where a configuration value came from

const (
	SourceDefault    ConfigSource = "default"
	SourceConfigFile ConfigSource = "config_file"
	SourceEnvVar     ConfigSource = "env_var"
	SourceFlag       ConfigSource = "flag"
)

func GetValueSource

func GetValueSource(key string) ConfigSource

GetValueSource returns the source of a configuration value. Priority (highest to lowest): env var > config file > default Note: Flag overrides are handled separately in main.go since viper doesn't know about cobra flags.

type FederationConfig

type FederationConfig struct {
	Remote      string      // dolthub://org/beads, gs://bucket/beads, s3://bucket/beads
	Sovereignty Sovereignty // T1, T2, T3, T4
}

FederationConfig holds the federation (Dolt remote) configuration.

func GetFederationConfig

func GetFederationConfig() FederationConfig

GetFederationConfig returns the current federation configuration.

type MultiRepoConfig

type MultiRepoConfig struct {
	Primary    string   // Primary repo path (where canonical issues live)
	Additional []string // Additional repos to hydrate from
}

MultiRepoConfig contains configuration for multi-repo support

func GetMultiRepoConfig

func GetMultiRepoConfig() *MultiRepoConfig

GetMultiRepoConfig retrieves multi-repo configuration Returns nil if multi-repo is not configured (single-repo mode)

type ReposConfig

type ReposConfig struct {
	Primary    string   `yaml:"primary,omitempty"`
	Additional []string `yaml:"additional,omitempty,flow"`
}

ReposConfig represents the repos section of config.yaml

func GetReposFromYAML

func GetReposFromYAML(configPath string) (*ReposConfig, error)

GetReposFromYAML reads the repos configuration from config.yaml Returns an empty ReposConfig if repos section doesn't exist

func ListRepos

func ListRepos(configPath string) (*ReposConfig, error)

ListRepos returns the current repos configuration from YAML

type Sovereignty

type Sovereignty string

Sovereignty represents the federation sovereignty tier

const (
	// SovereigntyNone means no sovereignty restriction (empty value)
	SovereigntyNone Sovereignty = ""
	// SovereigntyT1 is the most open tier (public repos)
	SovereigntyT1 Sovereignty = "T1"
	// SovereigntyT2 is organization-level
	SovereigntyT2 Sovereignty = "T2"
	// SovereigntyT3 is pseudonymous
	SovereigntyT3 Sovereignty = "T3"
	// SovereigntyT4 is anonymous
	SovereigntyT4 Sovereignty = "T4"
)

func GetSovereignty

func GetSovereignty() Sovereignty

GetSovereignty retrieves the federation sovereignty tier configuration. Returns the configured tier, or SovereigntyNone (empty, no restriction) if not set. Returns SovereigntyT1 and logs a warning if an invalid non-empty value is configured.

Config key: federation.sovereignty Valid values: T1, T2, T3, T4 (empty means no restriction)

func (Sovereignty) String

func (s Sovereignty) String() string

String returns the string representation of the Sovereignty.

Jump to

Keyboard shortcuts

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