Class: RosettAi::RaiConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/rosett_ai/rai_config.rb

Overview

Loads and validates Rosett-AI runtime configuration from ~/.config/rosett-ai/config.yml.

Returns compiled defaults when no config file exists. User values are deep-merged over defaults and validated against the rai config JSON Schema.

Constant Summary collapse

DEFAULTS =
{
  'default_engine' => 'claude',
  'cache' => { 'enabled' => true, 'ttl_hours' => 24 },
  'detect' => { 'on_init' => true },
  'dbus' => { 'allow_plugin_management' => false }
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_path: nil) ⇒ RaiConfig

Returns a new instance of RaiConfig.



23
24
25
26
# File 'lib/rosett_ai/rai_config.rb', line 23

def initialize(config_path: nil)
  @config_path = config_path || RosettAi.paths.rai_config_dir.join('config.yml')
  @data = load_config
end

Instance Attribute Details

#config_pathObject (readonly)

Returns the value of attribute config_path.



21
22
23
# File 'lib/rosett_ai/rai_config.rb', line 21

def config_path
  @config_path
end

Class Method Details

.load(config_path: nil) ⇒ Object



34
35
36
# File 'lib/rosett_ai/rai_config.rb', line 34

def self.load(config_path: nil)
  new(config_path: config_path)
end

Instance Method Details

#cache_enabled?Boolean

Returns:

  • (Boolean)


29
# File 'lib/rosett_ai/rai_config.rb', line 29

def cache_enabled?     = @data.dig('cache', 'enabled')

#cache_ttl_hoursObject



30
# File 'lib/rosett_ai/rai_config.rb', line 30

def cache_ttl_hours    = @data.dig('cache', 'ttl_hours')

#dbus_allow_plugin_management?Boolean

Returns:

  • (Boolean)


32
# File 'lib/rosett_ai/rai_config.rb', line 32

def dbus_allow_plugin_management? = @data.dig('dbus', 'allow_plugin_management') == true

#default_engineObject



28
# File 'lib/rosett_ai/rai_config.rb', line 28

def default_engine     = @data['default_engine']

#detect_on_init?Boolean

Returns:

  • (Boolean)


31
# File 'lib/rosett_ai/rai_config.rb', line 31

def detect_on_init?    = @data.dig('detect', 'on_init')

#update(key, value) ⇒ Object

Update a configuration key and persist to disk.

Parameters:

  • key (String)

    dot-separated key (e.g. 'default_engine', 'cache.enabled')

  • value (String)

    new value (coerced to boolean/integer where appropriate)



42
43
44
45
46
47
# File 'lib/rosett_ai/rai_config.rb', line 42

def update(key, value)
  coerced = coerce_value(value)
  set_nested_key(@data, key, coerced)
  validate!(@data)
  persist!
end