config

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FlagProxyListen         = "proxy-listen"
	FlagAPIListen           = "api-listen"
	FlagAPIWebUI            = "api-web-ui"
	FlagUpstream            = "upstream"
	FlagProvider            = "provider"
	FlagPostgres            = "postgres"
	FlagProject             = "project"
	FlagVectorStoreTgt      = "vector-store-target"
	FlagEmbeddingProv       = "embedding-provider"
	FlagEmbeddingTgt        = "embedding-target"
	FlagEmbeddingModel      = "embedding-model"
	FlagEmbeddingDims       = "embedding-dimensions"
	FlagSkillModel          = "skill-model"
	FlagAPITarget           = "api-target"
	FlagProxyTarget         = "proxy-target"
	FlagKafkaBrokers        = "kafka-brokers"
	FlagKafkaTopic          = "kafka-topic"
	FlagKafkaClientID       = "kafka-client-id"
	FlagTelemetryDisabled   = "telemetry-disabled"
	FlagUpdateCheckDisabled = "update-check-disabled"

	FlagIngestListen = "ingest-listen"

	// Standalone subcommand variants use "listen" as the flag name
	// but bind to different viper keys depending on the service.
	FlagProxyListenStandalone  = "proxy-listen-standalone"
	FlagAPIListenStandalone    = "api-listen-standalone"
	FlagIngestListenStandalone = "ingest-listen-standalone"

	// Derive worker (`tapes serve derive-worker`) tunables.
	FlagDeriveWorkerPoll          = "derive-worker-poll-interval"
	FlagDeriveWorkerDebounce      = "derive-worker-debounce"
	FlagDeriveWorkerSweep         = "derive-worker-sweep-interval"
	FlagDeriveWorkerSweepWindow   = "derive-worker-sweep-window" //nolint:gosec // flag registry key, not a credential
	FlagDeriveWorkerMaxDeriveLag  = "derive-worker-max-derive-lag"
	FlagDeriveWorkerMetricsListen = "derive-worker-metrics-listen"
	FlagDeriveWorkerWaitForDB     = "derive-worker-wait-for-db"

	// Embed worker (`tapes serve embed-worker`) tunables.
	FlagEmbedWorkerInterval      = "embed-worker-interval"
	FlagEmbedWorkerMetricsListen = "embed-worker-metrics-listen"
	FlagEmbedWorkerWaitForDB     = "embed-worker-wait-for-db"
	FlagEmbedWorkerBatchSize     = "embed-worker-batch-size"
	FlagEmbedWorkerMaxTextBytes  = "embed-worker-max-text-bytes"
	FlagEmbedWorkerOrg           = "embed-worker-org"
)

Flag registry keys. Use these constants when calling AddStringFlag, AddUintFlag, AddBoolFlag, and BindRegisteredFlags to avoid typos or drift from one command to another.

View Source
const (

	// CurrentV is the currently supported version, points to v0
	CurrentV = v0
)

Variables

This section is empty.

Functions

func AddBoolFlag added in v0.8.0

func AddBoolFlag(cmd *cobra.Command, fs FlagSet, registryKey string, target *bool)

AddBoolFlag registers a bool flag on cmd from the given FlagSet.

func AddIntFlag added in v0.18.0

func AddIntFlag(cmd *cobra.Command, fs FlagSet, registryKey string, target *int)

AddIntFlag registers an int flag on cmd from the given FlagSet.

func AddStringFlag

func AddStringFlag(cmd *cobra.Command, fs FlagSet, key string, target *string)

AddStringFlag registers a string flag on cmd from the given FlagSet. The flag's name, shorthand, default, and description all come from the FlagSet entry so they cannot drift across commands.

func AddUintFlag

func AddUintFlag(cmd *cobra.Command, fs FlagSet, registryKey string, target *uint)

AddUintFlag registers a uint flag on cmd from the given FlagSet.

func BindRegisteredFlags

func BindRegisteredFlags(v *viper.Viper, cmd *cobra.Command, fs FlagSet, registryKeys []string)

BindRegisteredFlags binds already-registered flags to viper using definitions from the given FlagSet. Call this in PreRunE after InitViper to connect flags to the viper precedence chain (flag > env > config file > default).

func ExplicitConfigKeySet added in v0.11.0

func ExplicitConfigKeySet(v *viper.Viper, key string) bool

ExplicitConfigKeySet reports whether a config key was supplied through the environment or the loaded config file.

func InitViper

func InitViper(configDir string) (*viper.Viper, error)

InitViper creates and returns a configured *viper.Viper. It sets defaults from NewDefaultConfig(), reads the config.toml file (if found via dotdir resolution), and binds environment variables with the TAPES_ prefix.

Config precedence (highest to lowest):

  1. CLI flags (once bound via BindRegisteredFlags)
  2. Environment variables (TAPES_PROXY_LISTEN, TAPES_API_LISTEN, etc.)
  3. config.toml file values
  4. Defaults from NewDefaultConfig()

func IsRegisteredFlagExplicitlySet added in v0.11.0

func IsRegisteredFlagExplicitlySet(v *viper.Viper, cmd *cobra.Command, fs FlagSet, registryKey string) bool

IsRegisteredFlagExplicitlySet reports whether a registered flag's value came from a CLI flag, environment variable, or config file rather than defaults.

func IsValidConfigKey

func IsValidConfigKey(key string) bool

IsValidConfigKey returns true if the given key is a supported configuration key.

func RedactDSN added in v0.14.0

func RedactDSN(dsn string) string

RedactDSN masks the password in a database connection string so the string can be logged safely. URL DSNs (postgres://user:pass@host/db, including the libpq-style ?password=... query parameter) and keyword/value DSNs (host=... password=...) are supported. Strings without a password are returned unchanged.

func ValidConfigKeys

func ValidConfigKeys() []string

ValidConfigKeys returns the sorted list of all supported configuration key names.

func ValidPresetNames

func ValidPresetNames() []string

ValidPresetNames returns the list of recognized preset names.

Types

type APIConfig

type APIConfig struct {
	Listen string `toml:"listen,omitempty" mapstructure:"listen"`
	WebUI  bool   `toml:"web_ui,omitempty" mapstructure:"web_ui"`
}

APIConfig holds API server settings.

type ClientConfig

type ClientConfig struct {
	ProxyTarget string `toml:"proxy_target,omitempty" mapstructure:"proxy_target"`
	APITarget   string `toml:"api_target,omitempty"   mapstructure:"api_target"`
}

ClientConfig holds settings for CLI commands that connect to the running proxy and API servers (e.g. tapes search, tapes checkout). Values are full URLs (scheme + host + port).

type Config

type Config struct {
	Version     int               `toml:"version"       mapstructure:"version"`
	Storage     StorageConfig     `toml:"storage"       mapstructure:"storage"`
	Proxy       ProxyConfig       `toml:"proxy"         mapstructure:"proxy"`
	API         APIConfig         `toml:"api"           mapstructure:"api"`
	Ingest      IngestConfig      `toml:"ingest"        mapstructure:"ingest"`
	Client      ClientConfig      `toml:"client"        mapstructure:"client"`
	VectorStore VectorStoreConfig `toml:"vector_store"  mapstructure:"vector_store"`
	Embedding   EmbeddingConfig   `toml:"embedding"     mapstructure:"embedding"`
	OpenCode    OpenCodeConfig    `toml:"opencode"      mapstructure:"opencode"`
	Telemetry   TelemetryConfig   `toml:"telemetry"     mapstructure:"telemetry"`
}

Config represents the persistent tapes configuration stored as config.toml in the .tapes/ directory. The TOML layout uses sections for logical grouping.

func NewDefaultConfig

func NewDefaultConfig() *Config

NewDefaultConfig returns a Config with sane defaults for all fields. This is the single source of truth for default values.

func ParseConfigTOML

func ParseConfigTOML(data []byte) (*Config, error)

ParseConfigTOML parses raw TOML bytes into a Config. Returns an error if the version field is present and not equal to CurrentConfigVersion.

func PresetConfig

func PresetConfig(name string) (*Config, error)

PresetConfig returns a Config with sane defaults for the named provider preset. Supported presets: "openai", "anthropic", "ollama". Returns an error if the preset name is not recognized.

type Configer

type Configer struct {
	// contains filtered or unexported fields
}

func NewConfiger

func NewConfiger(override string) (*Configer, error)

func (*Configer) GetConfigValue

func (c *Configer) GetConfigValue(key string) (string, error)

GetConfigValue loads the config and returns the string representation of the given key. Returns an error if the key is not a valid config key.

func (*Configer) GetTarget

func (c *Configer) GetTarget() string

func (*Configer) LoadConfig

func (c *Configer) LoadConfig() (*Config, error)

LoadConfig loads the configuration from config.toml in the target .tapes/ directory. If the file does not exist, returns DefaultConfig() so callers always receive a fully-populated Config with sane defaults. Fields explicitly set in the file override the defaults.

func (*Configer) SaveConfig

func (c *Configer) SaveConfig(cfg *Config) error

SaveConfig persists the configuration to config.toml in the target .tapes/ directory.

func (*Configer) SetConfigValue

func (c *Configer) SetConfigValue(key string, value string) error

SetConfigValue loads the config, sets the given key to the given value, and saves it. Returns an error if the key is not a valid config key.

type EmbeddingConfig

type EmbeddingConfig struct {
	Provider   string `toml:"provider,omitempty"   mapstructure:"provider"`
	Target     string `toml:"target,omitempty"     mapstructure:"target"`
	Model      string `toml:"model,omitempty"      mapstructure:"model"`
	Dimensions uint   `toml:"dimensions,omitempty" mapstructure:"dimensions"`
}

EmbeddingConfig holds embedding provider settings.

func ResolveEmbeddingConfig added in v0.11.0

func ResolveEmbeddingConfig(provider, target, model string, dimensions uint) EmbeddingConfig

ResolveEmbeddingConfig normalizes provider-specific embedding defaults after config, flags, and environment variables have been merged.

func ResolveEmbeddingConfigWithOptions added in v0.11.0

func ResolveEmbeddingConfigWithOptions(provider, target, model string, dimensions uint, opts ResolveEmbeddingConfigOptions) EmbeddingConfig

ResolveEmbeddingConfigWithOptions normalizes provider-specific embedding defaults while preserving explicitly configured values.

type Flag

type Flag struct {
	// Name is the long flag name (e.g. "upstream").
	Name string

	// Shorthand is the one-letter short flag (e.g. "u"). Empty for no shorthand.
	Shorthand string

	// ViperKey is the dotted config key this flag maps to (e.g. "proxy.upstream").
	ViperKey string

	// Description is the help text shown in --help output.
	Description string
}

Flag is the single source of truth for a CLI flag. Commands reference flags by registry key rather than hard-coding names, shorthands, defaults, and descriptions inline. This prevents flag drift when the same logical flag appears on multiple commands (e.g., --upstream on both "tapes serve" and "tapes serve proxy").

type FlagSet

type FlagSet map[string]Flag

FlagSet is a mapping of flag names to Flag structs that hold their name, shorthand, viper key, etc.

type IngestConfig added in v0.3.0

type IngestConfig struct {
	Listen string `toml:"listen,omitempty" mapstructure:"listen"`
}

IngestConfig holds ingest server settings for sidecar mode.

type OpenCodeConfig

type OpenCodeConfig struct {
	Provider string `toml:"provider,omitempty" mapstructure:"provider"`
	Model    string `toml:"model,omitempty"    mapstructure:"model"`
}

OpenCodeConfig holds OpenCode agent settings for provider and model selection.

type ProxyConfig

type ProxyConfig struct {
	Provider string `toml:"provider,omitempty" mapstructure:"provider"`
	Upstream string `toml:"upstream,omitempty" mapstructure:"upstream"`
	Listen   string `toml:"listen,omitempty"   mapstructure:"listen"`
	Project  string `toml:"project,omitempty"  mapstructure:"project"`
}

ProxyConfig holds proxy-specific settings.

type ResolveEmbeddingConfigOptions added in v0.11.0

type ResolveEmbeddingConfigOptions struct {
	DimensionsSet bool
}

ResolveEmbeddingConfigOptions describes which values came from explicit user input instead of inherited defaults.

type StorageConfig

type StorageConfig struct {
	PostgresDSN string `toml:"postgres_dsn,omitempty" mapstructure:"postgres_dsn"`
}

StorageConfig holds shared storage settings used by both proxy and API.

type TelemetryConfig added in v0.2.0

type TelemetryConfig struct {
	Disabled bool `toml:"disabled,omitempty" mapstructure:"disabled"`
}

TelemetryConfig holds anonymous telemetry settings.

type VectorStoreConfig

type VectorStoreConfig struct {
	Target string `toml:"target,omitempty"   mapstructure:"target"`
}

VectorStoreConfig holds vector store settings.

Jump to

Keyboard shortcuts

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