config

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package config provides the modular configuration architecture.

Config sources are decomposed into focused interfaces.

Core principle: Each bucket implements ConfigBase but only handles what it knows. The ConfigOrchestrator coordinates without digging into bucket internals.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultConfigPath

func DefaultConfigPath() string

DefaultConfigPath returns the default configuration file path.

func IsTermux

func IsTermux() bool

IsTermux returns true if running in Termux environment

func LegacyConfigPath

func LegacyConfigPath() string

LegacyConfigPath returns the old plaintext config path

func PromptNewPassword

func PromptNewPassword() (string, error)

PromptNewPassword prompts for a new password with confirmation

func PromptPassword

func PromptPassword(prompt string) (string, error)

PromptPassword prompts for a password with masking Falls back to plain text input on Termux or when terminal manipulation fails

func SecureConfigPath

func SecureConfigPath() string

SecureConfigPath returns the path for encrypted config

Types

type Config

type Config struct {
	Provider         string // "openrouter", "openai", or "anthropic"
	APIKey           string
	Model            string
	WorkingDirectory string
	Verbose          bool
}

Config holds runtime configuration.

func Load

func Load() Config

Load reads configuration from environment variables.

type ConfigBase

type ConfigBase interface {
	// Name returns the bucket identifier (e.g., "env", "file", "flags")
	Name() string

	// CanHandle determines if this bucket provides the given config key.
	CanHandle(key string) bool

	// Get retrieves a config value by key.
	Get(key string) (any, bool)

	// Capabilities describes what this bucket can do.
	Capabilities() ConfigBucketCapabilities
}

ConfigBase is the fundamental interface all config buckets must implement.

type ConfigBucketCapabilities

type ConfigBucketCapabilities struct {
	Priority  int    // Lower = higher priority
	IsMutable bool   // Can be changed at runtime
	Category  string // "env", "file", "flags"
}

ConfigBucketCapabilities describes capabilities.

type ConfigEntry

type ConfigEntry struct {
	Source ConfigSource
	Path   string
}

ConfigEntry represents a single configuration file entry

type ConfigOrchestrator

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

ConfigOrchestrator coordinates multiple ConfigBase implementations.

func NewConfigOrchestrator

func NewConfigOrchestrator(buckets ...ConfigBase) *ConfigOrchestrator

NewConfigOrchestrator creates a new orchestrator.

func (*ConfigOrchestrator) Get

func (o *ConfigOrchestrator) Get(key string) (any, bool)

Get retrieves config from the first matching bucket.

func (*ConfigOrchestrator) GetBool

func (o *ConfigOrchestrator) GetBool(key string) bool

GetBool retrieves a bool config value.

func (*ConfigOrchestrator) GetString

func (o *ConfigOrchestrator) GetString(key string) string

GetString retrieves a string config value.

func (*ConfigOrchestrator) RegisterBucket

func (o *ConfigOrchestrator) RegisterBucket(bucket ConfigBase)

RegisterBucket adds a bucket.

type ConfigSource

type ConfigSource int

ConfigSource represents the source of a configuration entry

const (
	SourceUser ConfigSource = iota
	SourceProject
	SourceLocal
)

func (ConfigSource) String

func (s ConfigSource) String() string

type CredentialManager

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

CredentialManager handles secure credential operations

func NewCredentialManager

func NewCredentialManager() *CredentialManager

NewCredentialManager creates a new credential manager

func (*CredentialManager) ClearSecureConfig

func (cm *CredentialManager) ClearSecureConfig() error

ClearSecureConfig removes all secure credentials

func (*CredentialManager) GetEncryptionStatus

func (cm *CredentialManager) GetEncryptionStatus() EncryptionStatus

GetEncryptionStatus returns the current encryption status

func (*CredentialManager) HasLegacyCredentials

func (cm *CredentialManager) HasLegacyCredentials() bool

HasLegacyCredentials checks if old plaintext credentials exist

func (*CredentialManager) HasSecureCredentials

func (cm *CredentialManager) HasSecureCredentials() bool

HasSecureCredentials checks if encrypted credentials exist

func (*CredentialManager) LoadSecure

func (cm *CredentialManager) LoadSecure() (*SecureConfig, error)

LoadSecure loads credentials from encrypted storage

func (*CredentialManager) MigrateFromLegacy

func (cm *CredentialManager) MigrateFromLegacy() (*SecureConfig, error)

MigrateFromLegacy migrates plaintext credentials to secure storage

func (*CredentialManager) SaveSecure

func (cm *CredentialManager) SaveSecure(cfg *SecureConfig) error

SaveSecure saves credentials to encrypted storage

func (*CredentialManager) UpdateDefaultModel

func (cm *CredentialManager) UpdateDefaultModel(model string) error

UpdateDefaultModel updates just the default model in secure storage This is called when the user changes the model at runtime

type EncryptionMethod

type EncryptionMethod int

EncryptionMethod represents the encryption method in use

const (
	EncryptionNone EncryptionMethod = iota
	EncryptionPlaintext
	EncryptionKeychain
	EncryptionAES256GCM
)

func (EncryptionMethod) String

func (e EncryptionMethod) String() string

type EncryptionStatus

type EncryptionStatus struct {
	Method            EncryptionMethod
	HasCredentials    bool
	KeychainAvailable bool
}

EncryptionStatus represents the current encryption state

type FileConfig

type FileConfig struct {
	Provider         string               `json:"provider,omitempty"`
	APIKey           string               `json:"api_key,omitempty"`
	Model            string               `json:"model,omitempty"`
	WorkingDirectory string               `json:"working_directory,omitempty"`
	Verbose          bool                 `json:"verbose,omitempty"`
	AlwaysAllow      []string             `json:"always_allow,omitempty"`
	AlwaysDeny       []string             `json:"always_deny,omitempty"`
	McpServers       map[string]McpServer `json:"mcp_servers,omitempty"`
	CustomEnv        map[string]string    `json:"custom_env,omitempty"`
}

FileConfig represents settings loaded from disk.

func LoadFile

func LoadFile(path string) (*FileConfig, error)

LoadFile reads configuration from a JSON file.

func (*FileConfig) Save

func (c *FileConfig) Save(path string) error

Save writes configuration to a JSON file.

type LayeredConfig

type LayeredConfig struct {
	Provider       string
	APIKey         string
	Model          string
	PermissionMode PermissionMode
	ExecutionMode  string // "interactive" or "yolo"
	AlwaysAllow    []string
	AlwaysDeny     []string
	McpServers     map[string]mcp.McpServerConfig
	CustomEnv      map[string]string

	// Granular permissions (override PermissionMode when set)
	PermRead    bool // Allow read/search tools
	PermWrite   bool // Allow write/edit tools
	PermDelete  bool // Allow delete/remove tools
	PermExecute bool // Allow execute/bash tools

	// Persona determines the agent's behavioral mode
	Persona string
	// contains filtered or unexported fields
}

LayeredConfig holds merged configuration from all sources

func (*LayeredConfig) GetConfigReport

func (lc *LayeredConfig) GetConfigReport() string

GetConfigReport returns a formatted report of the current configuration

func (*LayeredConfig) GetPermissionReport

func (lc *LayeredConfig) GetPermissionReport() string

GetPermissionReport returns a formatted permission mode report

type LayeredLoader

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

LayeredLoader handles loading and merging configuration layers

func NewLayeredLoader

func NewLayeredLoader(cwd string) *LayeredLoader

NewLayeredLoader creates a new layered config loader

func (*LayeredLoader) Discover

func (ll *LayeredLoader) Discover() []ConfigEntry

Discover returns all configuration file entries in precedence order

func (*LayeredLoader) Load

func (ll *LayeredLoader) Load() (*LayeredConfig, error)

Load loads and merges all configuration layers

func (*LayeredLoader) Save

func (ll *LayeredLoader) Save(source ConfigSource, config *LayeredConfig) error

Save saves the configuration to a specific layer

type McpServer

type McpServer struct {
	Transport string            `json:"transport"`
	Command   string            `json:"command,omitempty"`
	Args      []string          `json:"args,omitempty"`
	URL       string            `json:"url,omitempty"`
	Env       map[string]string `json:"env,omitempty"`
}

McpServer describes an MCP server configuration.

type PermissionMode

type PermissionMode int

PermissionMode controls what tools can do

const (
	PermissionReadOnly PermissionMode = iota
	PermissionWorkspaceWrite
	PermissionDangerFullAccess
)

func ParsePermissionMode

func ParsePermissionMode(s string) (PermissionMode, error)

ParsePermissionMode parses a permission mode string

func (PermissionMode) Description

func (p PermissionMode) Description() string

func (PermissionMode) String

func (p PermissionMode) String() string

type SecureConfig

type SecureConfig struct {
	Provider string
	APIKey   string
	Model    string
}

SecureConfig holds runtime configuration loaded from secure storage

type SecureStore

type SecureStore struct {
	Version    uint32 `json:"version"`
	Salt       []byte `json:"salt"`
	Nonce      []byte `json:"nonce"`
	Ciphertext []byte `json:"ciphertext"`
	Provider   string `json:"provider"`
	Model      string `json:"model"`
}

SecureStore represents encrypted credential storage

Jump to

Keyboard shortcuts

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