config

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnvHome    = "BRAINJAR_HOME"
	ConfigFile = "config.yaml"
	DBFile     = "brainjar.db"
)
View Source
const ConfigSchemaVersion = 1

ConfigSchemaVersion is bumped when the on-disk YAML schema changes in a way older binaries can't read.

View Source
const DefaultContextName = "default"

DefaultContextName is the name assigned to the context that holds the bootstrap workspace.

View Source
const DefaultPlatform = "claude"

DefaultPlatform is the adapter used when a context is initialized without an explicit choice.

Variables

This section is empty.

Functions

func ConfigPath

func ConfigPath(home string) string

ConfigPath returns the absolute path to the config file inside home.

func DBPath

func DBPath(home string) string

DBPath returns the absolute path to the SQLite database inside home.

func IsNotExist

func IsNotExist(err error) bool

IsNotExist reports whether err indicates the config file is missing.

func ResolveHome

func ResolveHome(homeFlag string) (string, error)

ResolveHome returns the brainjar home directory.

Precedence, highest wins:

  1. homeFlag (the --home flag value, empty if unset)
  2. $BRAINJAR_HOME
  3. $HOME/.brainjar

func Save

func Save(home string, cfg *Config) error

Save writes cfg to <home>/config.yaml atomically: the marshaled bytes go to a sibling temp file, fsynced and chmoded to 0o600, then renamed over the final path. A crash mid-write leaves the previous config intact rather than truncated.

Types

type Config

type Config struct {
	SchemaVersion int                 `yaml:"schema_version" koanf:"schema_version"`
	ActiveContext string              `yaml:"active_context" koanf:"active_context"`
	Contexts      map[string]*Context `yaml:"contexts" koanf:"contexts"`
}

Config is the on-disk CLI configuration. Holds every known context and tracks which one is active.

func Defaults

func Defaults() Config

Defaults returns a fresh Config with a single default context bound to the default platform. WorkspaceID is left empty — callers fill it during `brainjar init`.

func Load

func Load(home string) (*Config, error)

Load reads the config at <home>/config.yaml.

func (*Config) Active

func (c *Config) Active() *Context

Active returns the context selected by ActiveContext. Returns nil when ActiveContext names a missing entry — Load guards against this, so a non-nil result is safe to dereference from normal control flow.

type Context

type Context struct {
	WorkspaceID string `yaml:"workspace_id" koanf:"workspace_id"`
	Platform    string `yaml:"platform" koanf:"platform"`

	// URL, when set, marks this context as remote — the CLI talks to
	// the server at this URL instead of opening the embedded SQLite.
	URL string `yaml:"url,omitempty" koanf:"url,omitempty"`

	// APIKeyRef names a secret (resolved by the caller at send time)
	// that holds the bearer token for the remote URL. Never the
	// plaintext.
	APIKeyRef string `yaml:"api_key_ref,omitempty" koanf:"api_key_ref,omitempty"`

	// CACertPath, when set, names a PEM file whose certificates are
	// trusted in addition to the system trust store. For self-hosted
	// clusters with private CAs, kind smoke-tests, or air-gapped
	// deployments where the server's cert isn't chained to a public root.
	CACertPath string `yaml:"ca_cert,omitempty" koanf:"ca_cert,omitempty"`
}

Context is one entry in the contexts map — a named profile that binds a workspace, platform, and (when remote) an HTTP endpoint plus an API-key reference.

Jump to

Keyboard shortcuts

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