Class: SentinelRb::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/sentinel_rb/config.rb

Overview

Configuration management for SentinelRb

Constant Summary collapse

DEFAULT_CONFIG =
{
  "provider" => "openai",
  "model" => "gpt-4o-mini",
  "relevance_threshold" => 0.55,
  "divergence_threshold" => 0.25,
  "fact_check_threshold" => 0.7,
  "dangerous_tools" => %w[delete_file transfer_funds system_shutdown exec_command],
  "skip_patterns" => ["**/.git/**", "**/node_modules/**", "**/tmp/**"],
  "output_format" => "table",
  "log_level" => "warn"
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_hash) ⇒ Config

Returns a new instance of Config.



36
37
38
# File 'lib/sentinel_rb/config.rb', line 36

def initialize(config_hash)
  @config = config_hash
end

Class Method Details

.load(config_path = ".sentinel.yml") ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/sentinel_rb/config.rb', line 20

def self.load(config_path = ".sentinel.yml")
  config = DEFAULT_CONFIG.dup

  if File.exist?(config_path)
    begin
      user_config = YAML.load_file(config_path)
      config.merge!(user_config) if user_config.is_a?(Hash)
    rescue Psych::SyntaxError => e
      warn "Warning: Invalid YAML in config file #{config_path}: #{e.message}"
      warn "Using default configuration."
    end
  end

  new(config)
end

Instance Method Details

#[](key) ⇒ Object



40
41
42
# File 'lib/sentinel_rb/config.rb', line 40

def [](key)
  @config[key]
end

#api_key_envObject



56
57
58
# File 'lib/sentinel_rb/config.rb', line 56

def api_key_env
  @config["api_key_env"] || "OPENAI_API_KEY"
end

#modelObject



48
49
50
# File 'lib/sentinel_rb/config.rb', line 48

def model
  @config["model"]
end

#providerObject



44
45
46
# File 'lib/sentinel_rb/config.rb', line 44

def provider
  @config["provider"]
end

#relevance_thresholdObject



52
53
54
# File 'lib/sentinel_rb/config.rb', line 52

def relevance_threshold
  @config["relevance_threshold"]
end

#to_hObject



60
61
62
# File 'lib/sentinel_rb/config.rb', line 60

def to_h
  @config.dup
end