config

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: May 26, 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 AliyunSMSConfig added in v0.3.0

type AliyunSMSConfig struct {
	AccessKeyID     string `json:"access_key_id"`     // Aliyun AccessKey ID
	AccessKeySecret string `json:"access_key_secret"` // Aliyun AccessKey Secret
	SignName        string `json:"sign_name"`         // SMS signature name
	Endpoint        string `json:"endpoint"`          // API endpoint (optional)
}

AliyunSMSConfig represents Aliyun SMS 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"`
	Notification    NotificationConfig     `json:"notification"`     // Email and SMS notification configuration
	ImageGen        ImageGenConfig         `json:"image_gen"`        // Image generation configuration
	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 EmailConfig added in v0.3.0

type EmailConfig struct {
	SMTPHost     string `json:"smtp_host"`     // SMTP server host
	SMTPPort     int    `json:"smtp_port"`     // SMTP server port
	Username     string `json:"username"`      // SMTP username
	Password     string `json:"password"`      // SMTP password or app-specific password
	From         string `json:"from"`          // From email address
	FromName     string `json:"from_name"`     // From name
	UseTLS       bool   `json:"use_tls"`       // Use TLS
	UseStartTLS  bool   `json:"use_starttls"`  // Use STARTTLS
	InsecureSkip bool   `json:"insecure_skip"` // Skip TLS certificate verification
}

EmailConfig represents email (SMTP) 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 ImageGenConfig added in v0.3.0

type ImageGenConfig struct {
	Provider        string `json:"provider"`         // Provider: dall-e, stable-diffusion, midjourney, together
	APIKey          string `json:"api_key"`          // API key for the provider
	BaseURL         string `json:"base_url"`         // Custom base URL (optional)
	DefaultSize     string `json:"default_size"`     // Default image size
	DefaultStyle    string `json:"default_style"`    // Default art style
	OutputDirectory string `json:"output_directory"` // Output directory for generated images
}

ImageGenConfig represents image generation configuration

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 NotificationConfig added in v0.3.0

type NotificationConfig struct {
	Email EmailConfig `json:"email"`
	SMS   SMSConfig   `json:"sms"`
}

NotificationConfig represents notification service 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 SMSConfig added in v0.3.0

type SMSConfig struct {
	Provider string           `json:"provider"` // Provider: twilio, aliyun, tencent
	Twilio   TwilioConfig     `json:"twilio"`
	Aliyun   AliyunSMSConfig  `json:"aliyun"`
	Tencent  TencentSMSConfig `json:"tencent"`
}

SMSConfig represents SMS service configuration

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 TencentSMSConfig added in v0.3.0

type TencentSMSConfig struct {
	SecretID  string `json:"secret_id"`  // Tencent Secret ID
	SecretKey string `json:"secret_key"` // Tencent Secret Key
	SDKAppID  string `json:"sdk_app_id"` // SMS SDK App ID
	SignName  string `json:"sign_name"`  // SMS signature name
	Endpoint  string `json:"endpoint"`   // API endpoint (optional)
}

TencentSMSConfig represents Tencent Cloud SMS configuration

type ToolsConfig

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

ToolsConfig represents tools configuration

type TwilioConfig added in v0.3.0

type TwilioConfig struct {
	AccountSID string `json:"account_sid"` // Twilio Account SID
	AuthToken  string `json:"auth_token"`  // Twilio Auth Token
	FromNumber string `json:"from_number"` // Twilio phone number
}

TwilioConfig represents Twilio SMS configuration

Jump to

Keyboard shortcuts

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