Class: RubynCode::IDE::Handlers::ConfigSetHandler
- Inherits:
-
Object
- Object
- RubynCode::IDE::Handlers::ConfigSetHandler
- Defined in:
- lib/rubyn_code/ide/handlers/config_set_handler.rb
Overview
Handles “config/set” JSON-RPC requests from the IDE extension.
Validates the key is in the allowed list, coerces types as needed, persists the change, and notifies the client via config/changed.
Constant Summary collapse
- EXPOSED_KEYS =
ConfigGetHandler::EXPOSED_KEYS
- NUMERIC_KEYS =
%w[ max_iterations max_sub_agent_iterations max_output_chars context_threshold_tokens session_budget_usd daily_budget_usd ].freeze
- STRING_KEYS =
%w[provider model model_mode].freeze
- VALID_PERMISSION_MODES =
%w[default accept_edits plan_only auto dont_ask bypass].freeze
Instance Method Summary collapse
- #call(params) ⇒ Object
-
#initialize(server) ⇒ ConfigSetHandler
constructor
A new instance of ConfigSetHandler.
Constructor Details
#initialize(server) ⇒ ConfigSetHandler
Returns a new instance of ConfigSetHandler.
24 25 26 |
# File 'lib/rubyn_code/ide/handlers/config_set_handler.rb', line 24 def initialize(server) @server = server end |
Instance Method Details
#call(params) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rubyn_code/ide/handlers/config_set_handler.rb', line 28 def call(params) key = params['key'].to_s value = params['value'] return { 'updated' => false, 'error' => "Unknown config key: #{key}" } unless EXPOSED_KEYS.include?(key) # permission_mode is a runtime-only setting on the server, not persisted to config. if key == 'permission_mode' mode = value.to_s unless VALID_PERMISSION_MODES.include?(mode) return { 'updated' => false, 'error' => "Invalid permission mode: #{mode}. " \ "Valid modes: #{VALID_PERMISSION_MODES.join(', ')}" } end @server. = mode.to_sym @server.tool_output_adapter&. = mode.to_sym @server.notify('config/changed', { 'key' => key, 'value' => mode }) return { 'updated' => true, 'key' => key, 'value' => mode } end value = coerce(key, value) result = Config::Validator.new.validate(key, value) unless result[:valid] return { 'updated' => false, 'error' => result[:errors].join('; ') } end settings = Config::Settings.new settings.set(key, value) settings.save! @server.notify('config/changed', { 'key' => key, 'value' => value }) { 'updated' => true, 'key' => key, 'value' => value } end |