config

package
v0.14.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	AppDirName    = ".memorizer"
	MemoryDirName = "memory"
	CacheDirName  = ".cache"
	ConfigFile    = "config.yaml"
	DaemonLogFile = "daemon.log"
	DaemonPIDFile = "daemon.pid"
	MCPLogFile    = "mcp.log"
)

Application directory and file names

View Source
const (
	ClaudeAPIKeyEnv = "ANTHROPIC_API_KEY"
	OpenAIAPIKeyEnv = "OPENAI_API_KEY"
	GoogleAPIKeyEnv = "GOOGLE_API_KEY"
)

Hardcoded environment variable names (convention over configuration) These define which environment variables are checked for credentials. The actual values (API keys, passwords) come from the environment or config file.

View Source
const (
	VoyageAPIKeyEnv = "VOYAGE_API_KEY"
	// Internal settings - not configurable
	EmbeddingsCacheEnabled = true // Always enabled for performance
	EmbeddingsBatchSize    = 100  // Optimized for batch processing
)

Hardcoded Embeddings environment variable names and internal settings

View Source
const (
	DefaultEmbeddingsProvider         = "openai"
	DefaultEmbeddingsModel            = "text-embedding-3-small"
	DefaultEmbeddingsDimensions       = 1536
	DefaultOpenAIEmbeddingsModel      = "text-embedding-3-small"
	DefaultOpenAIEmbeddingsDimensions = 1536
)

Embeddings defaults - can be overridden in config.yaml

View Source
const (
	DefaultVoyageEmbeddingsModel      = "voyage-3"
	DefaultVoyageEmbeddingsDimensions = 1024
)

Voyage embedding defaults

View Source
const (
	DefaultGeminiEmbeddingsModel      = "text-embedding-004"
	DefaultGeminiEmbeddingsDimensions = 768
)

Gemini embedding defaults

View Source
const (
	DefaultSemanticProvider = "claude"
	DefaultClaudeModel      = "claude-sonnet-4-5-20250929"
	DefaultOpenAIModel      = "gpt-5.2-chat-latest"
	DefaultGeminiModel      = "gemini-2.5-flash"
)

Provider-specific defaults

View Source
const (
	DefaultClaudeRateLimit = 20  // Conservative for API quotas
	DefaultOpenAIRateLimit = 60  // Tier 1: 500 RPM, suggest conservative
	DefaultGeminiRateLimit = 100 // Paid tier: 2000 RPM, suggest conservative
)

Provider-specific rate limits (requests per minute)

View Source
const ForgottenDirName = ".forgotten"

ForgottenDirName is the name of the directory for soft-deleted files

View Source
const (
	GraphPasswordEnv = "FALKORDB_PASSWORD"
)

Hardcoded Graph environment variable names

View Source
const (
	OutputShowRecentDays = 7
)

Hardcoded Output settings (convention over configuration)

Variables

View Source
var DefaultConfig = Config{
	Memory: MemoryConfig{
		Root: "~/" + AppDirName + "/" + MemoryDirName,
	},
	Semantic: SemanticConfig{
		Enabled:         true,
		Provider:        DefaultSemanticProvider,
		Model:           DefaultClaudeModel,
		MaxTokens:       1500,
		Timeout:         30,
		EnableVision:    true,
		MaxFileSize:     10485760,
		CacheDir:        "~/" + AppDirName + "/" + CacheDirName,
		RateLimitPerMin: DefaultClaudeRateLimit,
	},
	Daemon: DaemonConfig{
		DebounceMs:                 500,
		Workers:                    3,
		FullRebuildIntervalMinutes: 60,
		HTTPPort:                   0,
		LogFile:                    "~/" + AppDirName + "/" + DaemonLogFile,
		LogLevel:                   "info",
		SkipHidden:                 true,
		SkipDirs:                   DefaultSkipDirs,
		SkipFiles:                  DefaultSkipFiles,
		SkipExtensions:             DefaultSkipExtensions,
	},
	MCP: MCPConfig{
		LogFile:    "~/" + AppDirName + "/" + MCPLogFile,
		LogLevel:   "info",
		DaemonHost: "localhost",
		DaemonPort: 0,
	},
	Graph: GraphConfig{
		Host:                "localhost",
		Port:                6379,
		Database:            "memorizer",
		Password:            "",
		SimilarityThreshold: 0.7,
		MaxSimilarFiles:     10,
	},
	Embeddings: EmbeddingsConfig{
		Enabled:    false,
		APIKey:     "",
		Provider:   DefaultEmbeddingsProvider,
		Model:      DefaultEmbeddingsModel,
		Dimensions: DefaultEmbeddingsDimensions,
	},
}

DefaultConfig provides sensible defaults for all configuration settings. INTERNAL settings (not shown in initialized config but available for power users): - semantic.max_tokens, semantic.max_file_size - daemon.debounce_ms, daemon.workers, daemon.full_rebuild_interval_minutes, daemon.skip_* - graph.similarity_threshold, graph.max_similar_files

View Source
var DefaultSkipDirs = []string{"node_modules", "vendor", "__pycache__", ".venv"}
View Source
var DefaultSkipExtensions = []string{".zip", ".tar", ".gz", ".exe", ".bin", ".dmg", ".iso"}

Default skip patterns for file watching

View Source
var DefaultSkipFiles = []string{"memorizer"}

Functions

func ExpandHome

func ExpandHome(path string) string

func GetAppDir

func GetAppDir() (string, error)

GetAppDir returns the application directory path. Checks MEMORIZER_APP_DIR environment variable first, then falls back to ~/.agentic-memorizer

func GetConfigPath

func GetConfigPath() string

func GetEmbeddingModelDimensions added in v0.14.0

func GetEmbeddingModelDimensions(provider, model string) int

GetEmbeddingModelDimensions returns the dimension count for a provider/model pair. Returns 0 if the model is not recognized.

func GetForgottenDir added in v0.14.0

func GetForgottenDir() (string, error)

GetForgottenDir returns the path to the forgotten files directory. This is where files are moved when "forgotten" via the CLI. The directory is at ~/.memorizer/.forgotten/ (or $MEMORIZER_APP_DIR/.forgotten/)

func GetPIDPath

func GetPIDPath() (string, error)

GetPIDPath returns the daemon PID file path. The PID file is stored at ~/.agentic-memorizer/daemon.pid

func InitConfig

func InitConfig() error

func ResetForTesting

func ResetForTesting()

ResetForTesting resets viper state for testing purposes. This allows tests to use different config files without interference. Should only be called from test code.

func SafePath

func SafePath(path string) error

SafePath validates that a path is safe (no directory traversal)

func ValidateBinaryPath

func ValidateBinaryPath(path string) error

ValidateBinaryPath validates a binary path for execution

func ValidateConfig

func ValidateConfig(cfg *Config) error

ValidateConfig validates the complete configuration

func ValidateReload

func ValidateReload(oldCfg, newCfg *Config) error

ValidateReload checks if configuration changes are compatible with hot-reload Returns an error if any immutable fields have changed

func WriteConfig

func WriteConfig(path string, cfg *Config) error

func WriteMinimalConfig added in v0.13.0

func WriteMinimalConfig(path string, cfg *Config) error

WriteMinimalConfig writes only user-facing configuration settings. Internal settings are omitted and will use defaults when loaded.

Types

type Config

type Config struct {
	Memory     MemoryConfig     `mapstructure:"memory" yaml:"memory"`
	Semantic   SemanticConfig   `mapstructure:"semantic" yaml:"semantic"`
	Daemon     DaemonConfig     `mapstructure:"daemon" yaml:"daemon"`
	MCP        MCPConfig        `mapstructure:"mcp" yaml:"mcp"`
	Graph      GraphConfig      `mapstructure:"graph" yaml:"graph"`
	Embeddings EmbeddingsConfig `mapstructure:"embeddings" yaml:"embeddings"`
}

func GetConfig

func GetConfig() (*Config, error)

func (*Config) ToMinimalConfig added in v0.13.0

func (c *Config) ToMinimalConfig() *MinimalConfig

ToMinimalConfig converts a full Config to a MinimalConfig for writing. Only user-facing settings are included; internal settings use defaults.

type ConfigSchema added in v0.13.0

type ConfigSchema struct {
	Items     []SchemaItem // Can contain both RootField and SchemaSection
	Hardcoded []HardcodedSetting
}

ConfigSchema describes all configuration settings including configurable settings (minimal and advanced) and hardcoded conventions.

func GetConfigSchema added in v0.13.0

func GetConfigSchema() *ConfigSchema

GetConfigSchema returns the complete configuration schema. Schema is generated automatically via reflection on Config and MinimalConfig structs. Tier classification is derived: fields in MinimalConfig are "minimal", others are "advanced".

type DaemonConfig

type DaemonConfig struct {
	DebounceMs                 int    `mapstructure:"debounce_ms" yaml:"debounce_ms"`
	Workers                    int    `mapstructure:"workers" yaml:"workers"`
	FullRebuildIntervalMinutes int    `mapstructure:"full_rebuild_interval_minutes" yaml:"full_rebuild_interval_minutes"`
	HTTPPort                   int    `mapstructure:"http_port" yaml:"http_port"`
	LogFile                    string `mapstructure:"log_file" yaml:"log_file"`
	LogLevel                   string `mapstructure:"log_level" yaml:"log_level"`

	// Skip patterns for file watching
	SkipHidden     bool     `mapstructure:"skip_hidden" yaml:"skip_hidden"`         // Skip hidden files/dirs (default: true)
	SkipDirs       []string `mapstructure:"skip_dirs" yaml:"skip_dirs"`             // Directories to skip
	SkipFiles      []string `mapstructure:"skip_files" yaml:"skip_files"`           // Files to skip by name
	SkipExtensions []string `mapstructure:"skip_extensions" yaml:"skip_extensions"` // Extensions to skip
}

type EmbeddingsConfig added in v0.13.0

type EmbeddingsConfig struct {
	Enabled    bool   `mapstructure:"enabled" yaml:"enabled"`
	APIKey     string `mapstructure:"api_key" yaml:"api_key"`
	Provider   string `mapstructure:"provider" yaml:"provider"`     // Embedding provider (only "openai" currently supported)
	Model      string `mapstructure:"model" yaml:"model"`           // Embedding model (e.g., text-embedding-3-small)
	Dimensions int    `mapstructure:"dimensions" yaml:"dimensions"` // Vector dimensions (must match model)
}

EmbeddingsConfig contains embedding provider configuration. Provider, model, and dimensions have sensible defaults but can be overridden.

type GraphConfig added in v0.13.0

type GraphConfig struct {
	Host                string  `mapstructure:"host" yaml:"host"`
	Port                int     `mapstructure:"port" yaml:"port"`
	Database            string  `mapstructure:"database" yaml:"database"` // Graph database name
	Password            string  `mapstructure:"password" yaml:"password"`
	SimilarityThreshold float64 `mapstructure:"similarity_threshold" yaml:"similarity_threshold"`
	MaxSimilarFiles     int     `mapstructure:"max_similar_files" yaml:"max_similar_files"`
}

GraphConfig contains FalkorDB knowledge graph configuration. FalkorDB is the required storage backend - there is no option to disable it.

type HardcodedSetting added in v0.13.0

type HardcodedSetting struct {
	Name   string
	Value  any
	Reason string
}

HardcodedSetting describes a non-configurable constant

type MCPConfig

type MCPConfig struct {
	LogFile    string `mapstructure:"log_file" yaml:"log_file"`
	LogLevel   string `mapstructure:"log_level" yaml:"log_level"`
	DaemonHost string `mapstructure:"daemon_host" yaml:"daemon_host"`
	DaemonPort int    `mapstructure:"daemon_port" yaml:"daemon_port"`
}

func (*MCPConfig) GetDaemonURL added in v0.13.0

func (m *MCPConfig) GetDaemonURL() string

GetDaemonURL returns the daemon HTTP API URL constructed from host and port. Returns empty string if daemon port is not configured (0).

type MemoryConfig added in v0.14.0

type MemoryConfig struct {
	Root string `mapstructure:"root" yaml:"root"`
}

MemoryConfig contains memory directory configuration.

type MinimalConfig added in v0.13.0

type MinimalConfig struct {
	Memory       MinimalMemoryConfig       `yaml:"memory"`
	Semantic     MinimalSemanticConfig     `yaml:"semantic,omitempty"`
	Daemon       MinimalDaemonConfig       `yaml:"daemon,omitempty"`
	MCP          MinimalMCPConfig          `yaml:"mcp,omitempty"`
	Graph        MinimalGraphConfig        `yaml:"graph,omitempty"`
	Embeddings   MinimalEmbeddingsConfig   `yaml:"embeddings,omitempty"`
	Integrations MinimalIntegrationsConfig `yaml:"integrations,omitempty"`
}

MinimalConfig contains only user-facing settings for initial configuration. Internal settings use defaults and are not written to the initialized config file.

type MinimalDaemonConfig added in v0.13.0

type MinimalDaemonConfig struct {
	HTTPPort int    `yaml:"http_port"`
	LogLevel string `yaml:"log_level,omitempty"`
}

type MinimalEmbeddingsConfig added in v0.13.0

type MinimalEmbeddingsConfig struct {
	Enabled  bool   `yaml:"enabled,omitempty"`
	APIKey   string `yaml:"api_key,omitempty"`
	Provider string `yaml:"provider,omitempty"`
	Model    string `yaml:"model,omitempty"`
}

type MinimalGraphConfig added in v0.13.0

type MinimalGraphConfig struct {
	Host     string `yaml:"host,omitempty"`
	Port     int    `yaml:"port,omitempty"`
	Password string `yaml:"password,omitempty"`
}

type MinimalIntegrationsConfig added in v0.13.0

type MinimalIntegrationsConfig struct {
	Enabled []string `yaml:"enabled,omitempty"`
}

type MinimalMCPConfig added in v0.13.0

type MinimalMCPConfig struct {
	LogLevel   string `yaml:"log_level,omitempty"`
	DaemonHost string `yaml:"daemon_host,omitempty"`
	DaemonPort int    `yaml:"daemon_port,omitempty"`
}

type MinimalMemoryConfig added in v0.14.0

type MinimalMemoryConfig struct {
	Root string `yaml:"root"`
}

type MinimalSemanticConfig added in v0.14.0

type MinimalSemanticConfig struct {
	Enabled  bool   `yaml:"enabled,omitempty"`
	Provider string `yaml:"provider,omitempty"`
	APIKey   string `yaml:"api_key,omitempty"`
	Model    string `yaml:"model,omitempty"`
}

type RootField added in v0.13.0

type RootField struct {
	Name        string
	Type        string
	Default     any
	Tier        string
	HotReload   bool
	Description string
}

RootField represents a simple-type field at the root of the configuration. Unlike nested sections, root fields are displayed directly without a wrapping section.

type SchemaField added in v0.13.0

type SchemaField struct {
	Name        string
	Type        string // "string", "int", "bool", "float64", "[]string"
	Default     any
	Tier        string // "minimal" or "advanced"
	HotReload   bool   // true if hot-reloadable without daemon restart
	Description string
}

SchemaField describes a single configuration field

type SchemaItem added in v0.13.0

type SchemaItem interface {
	// contains filtered or unexported methods
}

SchemaItem represents an item in the configuration schema. It can be either a SchemaSection (for nested struct fields) or a RootField (for simple type fields at the root level).

type SchemaSection added in v0.13.0

type SchemaSection struct {
	Name        string
	Description string
	Fields      []SchemaField
}

SchemaSection represents a config section (claude, daemon, etc.)

type SemanticConfig added in v0.14.0

type SemanticConfig struct {
	// Provider selection
	Enabled  bool   `mapstructure:"enabled" yaml:"enabled"`
	Provider string `mapstructure:"provider" yaml:"provider"` // "claude", "openai", "gemini"

	// Provider credentials and settings
	APIKey       string `mapstructure:"api_key" yaml:"api_key"`
	Model        string `mapstructure:"model" yaml:"model"`
	MaxTokens    int    `mapstructure:"max_tokens" yaml:"max_tokens"`
	Timeout      int    `mapstructure:"timeout" yaml:"timeout"`             // API request timeout in seconds (5-300)
	EnableVision bool   `mapstructure:"enable_vision" yaml:"enable_vision"` // Enable vision API for image analysis

	// Analysis constraints (provider-agnostic)
	MaxFileSize int64 `mapstructure:"max_file_size" yaml:"max_file_size"`

	// Caching
	CacheDir string `mapstructure:"cache_dir" yaml:"cache_dir"`

	// Rate limiting (per-provider)
	RateLimitPerMin int `mapstructure:"rate_limit_per_min" yaml:"rate_limit_per_min"`
}

SemanticConfig contains unified semantic analysis configuration. Merges provider selection, credentials, and analysis constraints into one section.

type ValidationError

type ValidationError struct {
	Field      string
	Value      any
	Rule       string
	Message    string
	Suggestion string
}

ValidationError represents a configuration validation error

func (*ValidationError) Error

func (e *ValidationError) Error() string

Error implements the error interface

type Validator

type Validator struct {
	Errors []ValidationError
}

Validator accumulates validation errors

func (*Validator) AddError

func (v *Validator) AddError(field, rule, message, suggestion string, value any)

AddError adds a validation error

func (*Validator) Error

func (v *Validator) Error() string

Error returns a formatted error message with all validation errors

func (*Validator) HasErrors

func (v *Validator) HasErrors() bool

HasErrors returns true if there are validation errors

Jump to

Keyboard shortcuts

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