config

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateDefaultSecurityConfig

func CreateDefaultSecurityConfig(dir string) error

CreateDefaultSecurityConfig creates a default security config file

func SaveSecurityConfig

func SaveSecurityConfig(path string, config *SecurityConfig) error

SaveSecurityConfig saves security configuration to file

Types

type AgentConfig

type AgentConfig struct {
	MaxTurns           int     `json:"max_turns"`
	MaxIterations      int     `json:"max_iterations"`
	MaxTokenBudget     int64   `json:"max_token_budget"`
	CompressionEnabled bool    `json:"compression_enabled"`
	CompressionRatio   float64 `json:"compression_ratio"`
	ContextWindow      int     `json:"context_window"`
	GoalMaxTurns       int     `json:"goal_max_turns"`    // Max turns for /goal command, default 20
	SameToolLimit      int     `json:"same_tool_limit"`   // Same tool call limit (default: 3)
	ConsecutiveLimit   int     `json:"consecutive_limit"` // Consecutive tool call limit (default: 10)
}

AgentConfig represents agent configuration

type CommandSecurityConfig

type CommandSecurityConfig struct {
	AutoApproveSafe       bool     `yaml:"auto_approve_safe" json:"auto_approve_safe"`
	AutoRejectDangerous   bool     `yaml:"auto_reject_dangerous" json:"auto_reject_dangerous"`
	RequireApprovalLevels []string `yaml:"require_approval_levels" json:"require_approval_levels"` // "medium", "dangerous
	AllowedCommands       []string `yaml:"allowed_commands" json:"allowed_commands"`               // Whitelist
	BlockedCommands       []string `yaml:"blocked_commands" json:"blocked_commands"`               // Blacklist
}

CommandSecurityConfig configures command security

type Config

type Config struct {
	Profile         string                 `json:"profile"`
	MagicHome       string                 `json:"magic_home"`
	Provider        string                 `json:"provider"`
	Model           string                 `json:"model"`
	Providers       map[string]ProviderCfg `json:"providers"`
	Tools           ToolsConfig            `json:"tools"`
	OptionalTools   []string               `json:"optional_tools"` // Optional tools to enable (image_gen, tts, video_analyze)
	Gateway         GatewayConfig          `json:"gateway"`
	Agent           AgentConfig            `json:"agent"`
	Memory          MemoryConfig           `json:"memory"`
	Kanban          KanbanConfig           `json:"kanban"`
	SecretRedaction bool                   `json:"secret_redaction"` // Secret redaction (API keys, tokens, etc.)
	CortexEnabled   bool                   `json:"cortex_enabled"`   // Enable Cortex Agent six-system integration
	WorkingDir      string                 `json:"working_dir"`      // Working directory for file operations
	Security        *SecurityConfig        `json:"-"`
	SecurityPath    string                 `json:"-"`
}

Config represents the main application configuration

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default configuration

func Load

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

Load loads configuration from a file with environment variable overrides

func LoadFromDefault

func LoadFromDefault() (*Config, error)

LoadFromDefault loads configuration from default locations

func (*Config) GetFallbackChain

func (c *Config) GetFallbackChain(name string) []string

GetFallbackChain returns the fallback chain for a provider

func (*Config) GetProviderConfig

func (c *Config) GetProviderConfig(name string) (*ProviderCfg, error)

GetProviderConfig returns the configuration for a specific provider

func (*Config) Save

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

Save saves configuration to a file

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the configuration

type GatewayConfig

type GatewayConfig struct {
	Enabled   bool                   `json:"enabled"`
	Platforms map[string]PlatformCfg `json:"platforms"`
}

GatewayConfig represents gateway configuration

type HooksConfig

type HooksConfig struct {
	Enabled []string            `yaml:"enabled" json:"enabled"` // List of enabled hooks
	Process []ProcessHookConfig `yaml:"process" json:"process"` // External process hooks
}

HooksConfig configures hooks

type KanbanConfig

type KanbanConfig struct {
	Enabled                bool          `json:"enabled"`
	DBPath                 string        `json:"db_path"`                  // Default: ~/.magic/kanban.db
	DispatcherTick         time.Duration `json:"dispatcher_tick"`          // Default: 60s
	MaxRetries             int           `json:"max_retries"`              // Default: 3
	MaxConsecutiveFailures int           `json:"max_consecutive_failures"` // Default: 5
	DefaultMaxRuntime      int           `json:"default_max_runtime"`      // Default: 3600s (1 hour)
}

KanbanConfig represents kanban board configuration

type MemoryConfig

type MemoryConfig struct {
	Enabled     bool   `json:"enabled"`
	DBPath      string `json:"db_path"`
	AutoRecall  bool   `json:"auto_recall"`
	RecallLimit int    `json:"recall_limit"`
}

MemoryConfig represents memory configuration

type PIIConfig

type PIIConfig struct {
	Enabled        bool              `yaml:"enabled" json:"enabled"`
	RedactPhone    bool              `yaml:"redact_phone" json:"redact_phone"`
	RedactEmail    bool              `yaml:"redact_email" json:"redact_email"`
	RedactIDCard   bool              `yaml:"redact_id_card" json:"redact_id_card"`
	RedactBankCard bool              `yaml:"redact_bank_card" json:"redact_bank_card"`
	RedactIP       bool              `yaml:"redact_ip" json:"redact_ip"`
	RedactAddress  bool              `yaml:"redact_address" json:"redact_address"`
	CustomPatterns map[string]string `yaml:"custom_patterns" json:"custom_patterns"`
}

PIIConfig configures PII handling

type PlatformCfg

type PlatformCfg struct {
	Token     string `json:"token,omitempty"`
	Secret    string `json:"secret,omitempty"`
	AppKey    string `json:"app_key,omitempty"`
	AppSecret string `json:"app_secret,omitempty"`
	Enabled   bool   `json:"enabled"`
	ProxyURL  string `json:"proxy_url,omitempty"`
}

PlatformCfg represents a platform configuration

type ProcessHookConfig

type ProcessHookConfig struct {
	Name          string   `yaml:"name" json:"name"`
	Command       []string `yaml:"command" json:"command"`
	Dir           string   `yaml:"dir" json:"dir"`
	Env           []string `yaml:"env" json:"env"`
	ObserveKinds  []string `yaml:"observe_kinds" json:"observe_kinds"`
	InterceptLLM  bool     `yaml:"intercept_llm" json:"intercept_llm"`
	InterceptTool bool     `yaml:"intercept_tool" json:"intercept_tool"`
	ApproveTool   bool     `yaml:"approve_tool" json:"approve_tool"`
}

ProcessHookConfig configures an external process hook

type ProviderCfg

type ProviderCfg struct {
	Provider  string                 `json:"provider,omitempty"`
	APIKey    string                 `json:"api_key,omitempty"`
	BaseURL   string                 `json:"base_url,omitempty"`
	Model     string                 `json:"model,omitempty"`
	Proxy     string                 `json:"proxy,omitempty"`
	Fallback  []string               `json:"fallback,omitempty"` // Fallback models
	ExtraBody map[string]interface{} `json:"extra_body,omitempty"`
}

ProviderCfg represents a provider configuration

type RateLimitConfig

type RateLimitConfig struct {
	Enabled              bool  `yaml:"enabled" json:"enabled"`
	MaxRequestsPerMinute int   `yaml:"max_requests_per_minute" json:"max_requests_per_minute"`
	MaxTokenBudget       int64 `yaml:"max_token_budget" json:"max_token_budget"`
}

RateLimitConfig configures rate limiting

type SecurityConfig

type SecurityConfig struct {
	// PII handling
	PII PIIConfig `yaml:"pii" json:"pii"`

	// Command approval
	Commands CommandSecurityConfig `yaml:"commands" json:"commands"`

	// Hooks
	Hooks HooksConfig `yaml:"hooks" json:"hooks"`

	// Rate limiting
	RateLimit RateLimitConfig `yaml:"rate_limit" json:"rate_limit"`
}

SecurityConfig represents the security configuration

func DefaultSecurityConfig

func DefaultSecurityConfig() *SecurityConfig

DefaultSecurityConfig returns the default security configuration

func LoadSecurityConfig

func LoadSecurityConfig(path string) (*SecurityConfig, error)

LoadSecurityConfig loads security configuration from file

func LoadSecurityConfigFromDir

func LoadSecurityConfigFromDir(dir string) (*SecurityConfig, error)

LoadSecurityConfigFromDir loads security config from a directory

func (*SecurityConfig) GetEnabledHooks

func (c *SecurityConfig) GetEnabledHooks() []string

GetEnabledHooks returns the list of enabled built-in hooks

func (*SecurityConfig) ShouldAutoApprove

func (c *SecurityConfig) ShouldAutoApprove(command string) bool

ShouldAutoApprove checks if a command should be auto-approved

func (*SecurityConfig) ShouldRequireApproval

func (c *SecurityConfig) ShouldRequireApproval(riskLevel string) bool

ShouldRequireApproval checks if a command requires approval

func (*SecurityConfig) Validate

func (c *SecurityConfig) Validate() error

Validate validates the security configuration

type ToolsConfig

type ToolsConfig struct {
	Enabled  []string `json:"enabled"`
	Disabled []string `json:"disabled"`
}

ToolsConfig represents tools configuration

Jump to

Keyboard shortcuts

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