Class: CodeToQuery::Configuration

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/code_to_query/configuration.rb

Overview

Centralized configuration with sensible defaults

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



27
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/code_to_query/configuration.rb', line 27

def initialize
  @adapter = :postgres
  @readonly_role = nil
  @default_limit = 100
  @max_limit = 10_000
  @max_joins = 3
  @block_subqueries = false
  @allow_seq_scans = false
  @max_query_cost = 10_000
  @max_query_rows = 100_000
  @query_timeout = 30
  @force_readonly_session = false
  @reset_session_after_query = false
  @policy_adapter = nil
  @context_pack_path = if defined?(Rails)
                         Rails.root.join('db/code_to_query/context.json')
                       else
                         File.join(Dir.pwd, 'db/code_to_query/context.json')
                       end
  @enable_explain_gate = false
  @explain_fail_open = true
  @provider = :auto
  @openai_api_key = ENV.fetch('OPENAI_API_KEY', nil)
  @openai_model = 'gpt-4'
  @stub_llm = false
  # LLM-assisted glossary enrichment during bootstrap (on by default for better UX)
  @auto_glossary_with_llm = true
  @max_glossary_suggestions = 200
  # Query type specific limits for flexibility
  @count_limit = nil          # No limit for COUNT operations by default
  @aggregation_limit = nil    # No limit for SUM/AVG/MAX/MIN operations by default
  @distinct_limit = 10_000    # Higher limit for DISTINCT queries
  @exists_limit = 1           # LIMIT 1 for existence checks

  # Planner iteration
  @planner_max_attempts = Integer(ENV.fetch('CODE_TO_QUERY_PLANNER_MAX_ATTEMPTS', 2))
  # feedback modes: :none, :schema_strict, :adaptive
  @planner_feedback_mode = ENV.fetch('CODE_TO_QUERY_PLANNER_FEEDBACK_MODE', 'adaptive').to_sym

  # Logging and LLM provider knobs
  @logger = if defined?(Rails) && Rails.respond_to?(:logger)
              Rails.logger
            else
              Logger.new($stdout).tap { |l| l.level = Logger::WARN }
            end
  @llm_api_base = ENV.fetch('CODE_TO_QUERY_LLM_API_BASE', 'https://api.openai.com/v1')
  @llm_timeout = Integer(ENV.fetch('CODE_TO_QUERY_LLM_TIMEOUT', 30))
  @llm_temperature = Float(ENV.fetch('CODE_TO_QUERY_LLM_TEMPERATURE', 0.1))
  @provider_options = {}
  @system_prompt_template = nil
  @llm_client = nil

  # Static analysis and RAG context options
  @prefer_static_scan = true
  @static_scan_dirs = if defined?(Rails)
                        [Rails.root.join('app/models').to_s]
                      else
                        [File.join(Dir.pwd, 'app/models')]
                      end
  @context_rag_top_k = Integer(ENV.fetch('CODE_TO_QUERY_CONTEXT_RAG_TOP_K', 6))

  # Guardrail defaults
  @require_limit_by_default = true
end

Instance Attribute Details

#adapterObject

Returns the value of attribute adapter.



13
14
15
# File 'lib/code_to_query/configuration.rb', line 13

def adapter
  @adapter
end

#aggregation_limitObject

Returns the value of attribute aggregation_limit.



13
14
15
# File 'lib/code_to_query/configuration.rb', line 13

def aggregation_limit
  @aggregation_limit
end

#allow_seq_scansObject

Returns the value of attribute allow_seq_scans.



13
14
15
# File 'lib/code_to_query/configuration.rb', line 13

def allow_seq_scans
  @allow_seq_scans
end

#auto_glossary_with_llmObject

Returns the value of attribute auto_glossary_with_llm.



13
14
15
# File 'lib/code_to_query/configuration.rb', line 13

def auto_glossary_with_llm
  @auto_glossary_with_llm
end

#block_subqueriesObject

Returns the value of attribute block_subqueries.



13
14
15
# File 'lib/code_to_query/configuration.rb', line 13

def block_subqueries
  @block_subqueries
end

#context_pack_pathObject

Returns the value of attribute context_pack_path.



13
14
15
# File 'lib/code_to_query/configuration.rb', line 13

def context_pack_path
  @context_pack_path
end

#context_rag_top_kObject

Returns the value of attribute context_rag_top_k.



13
14
15
# File 'lib/code_to_query/configuration.rb', line 13

def context_rag_top_k
  @context_rag_top_k
end

#count_limitObject

Returns the value of attribute count_limit.



13
14
15
# File 'lib/code_to_query/configuration.rb', line 13

def count_limit
  @count_limit
end

#default_limitObject

Returns the value of attribute default_limit.



13
14
15
# File 'lib/code_to_query/configuration.rb', line 13

def default_limit
  @default_limit
end

#distinct_limitObject

Returns the value of attribute distinct_limit.



13
14
15
# File 'lib/code_to_query/configuration.rb', line 13

def distinct_limit
  @distinct_limit
end

#enable_explain_gateObject

Returns the value of attribute enable_explain_gate.



13
14
15
# File 'lib/code_to_query/configuration.rb', line 13

def enable_explain_gate
  @enable_explain_gate
end

#exists_limitObject

Returns the value of attribute exists_limit.



13
14
15
# File 'lib/code_to_query/configuration.rb', line 13

def exists_limit
  @exists_limit
end

#explain_fail_openObject

Returns the value of attribute explain_fail_open.



13
14
15
# File 'lib/code_to_query/configuration.rb', line 13

def explain_fail_open
  @explain_fail_open
end

#force_readonly_sessionObject

Returns the value of attribute force_readonly_session.



13
14
15
# File 'lib/code_to_query/configuration.rb', line 13

def force_readonly_session
  @force_readonly_session
end

#llm_api_baseObject

Extended configuration knobs (added for LLM transport and logging)



25
26
27
# File 'lib/code_to_query/configuration.rb', line 25

def llm_api_base
  @llm_api_base
end

#llm_clientObject

Extended configuration knobs (added for LLM transport and logging)



25
26
27
# File 'lib/code_to_query/configuration.rb', line 25

def llm_client
  @llm_client
end

#llm_temperatureObject

Extended configuration knobs (added for LLM transport and logging)



25
26
27
# File 'lib/code_to_query/configuration.rb', line 25

def llm_temperature
  @llm_temperature
end

#llm_timeoutObject

Extended configuration knobs (added for LLM transport and logging)



25
26
27
# File 'lib/code_to_query/configuration.rb', line 25

def llm_timeout
  @llm_timeout
end

#loggerObject

Extended configuration knobs (added for LLM transport and logging)



25
26
27
# File 'lib/code_to_query/configuration.rb', line 25

def logger
  @logger
end

#max_glossary_suggestionsObject

Returns the value of attribute max_glossary_suggestions.



13
14
15
# File 'lib/code_to_query/configuration.rb', line 13

def max_glossary_suggestions
  @max_glossary_suggestions
end

#max_joinsObject

Returns the value of attribute max_joins.



13
14
15
# File 'lib/code_to_query/configuration.rb', line 13

def max_joins
  @max_joins
end

#max_limitObject

Returns the value of attribute max_limit.



13
14
15
# File 'lib/code_to_query/configuration.rb', line 13

def max_limit
  @max_limit
end

#max_query_costObject

Returns the value of attribute max_query_cost.



13
14
15
# File 'lib/code_to_query/configuration.rb', line 13

def max_query_cost
  @max_query_cost
end

#max_query_rowsObject

Returns the value of attribute max_query_rows.



13
14
15
# File 'lib/code_to_query/configuration.rb', line 13

def max_query_rows
  @max_query_rows
end

#openai_api_keyObject

Returns the value of attribute openai_api_key.



13
14
15
# File 'lib/code_to_query/configuration.rb', line 13

def openai_api_key
  @openai_api_key
end

#openai_modelObject

Returns the value of attribute openai_model.



13
14
15
# File 'lib/code_to_query/configuration.rb', line 13

def openai_model
  @openai_model
end

#planner_feedback_modeObject

Returns the value of attribute planner_feedback_mode.



13
14
15
# File 'lib/code_to_query/configuration.rb', line 13

def planner_feedback_mode
  @planner_feedback_mode
end

#planner_max_attemptsObject

Returns the value of attribute planner_max_attempts.



13
14
15
# File 'lib/code_to_query/configuration.rb', line 13

def planner_max_attempts
  @planner_max_attempts
end

#policy_adapterObject

Returns the value of attribute policy_adapter.



13
14
15
# File 'lib/code_to_query/configuration.rb', line 13

def policy_adapter
  @policy_adapter
end

#prefer_static_scanObject

Returns the value of attribute prefer_static_scan.



13
14
15
# File 'lib/code_to_query/configuration.rb', line 13

def prefer_static_scan
  @prefer_static_scan
end

#providerObject

Returns the value of attribute provider.



13
14
15
# File 'lib/code_to_query/configuration.rb', line 13

def provider
  @provider
end

#provider_optionsObject

Extended configuration knobs (added for LLM transport and logging)



25
26
27
# File 'lib/code_to_query/configuration.rb', line 25

def provider_options
  @provider_options
end

#query_timeoutObject

Returns the value of attribute query_timeout.



13
14
15
# File 'lib/code_to_query/configuration.rb', line 13

def query_timeout
  @query_timeout
end

#readonly_roleObject

Returns the value of attribute readonly_role.



13
14
15
# File 'lib/code_to_query/configuration.rb', line 13

def readonly_role
  @readonly_role
end

#require_limit_by_defaultObject

Returns the value of attribute require_limit_by_default.



13
14
15
# File 'lib/code_to_query/configuration.rb', line 13

def require_limit_by_default
  @require_limit_by_default
end

#reset_session_after_queryObject

Returns the value of attribute reset_session_after_query.



13
14
15
# File 'lib/code_to_query/configuration.rb', line 13

def reset_session_after_query
  @reset_session_after_query
end

#static_scan_dirsObject

Returns the value of attribute static_scan_dirs.



13
14
15
# File 'lib/code_to_query/configuration.rb', line 13

def static_scan_dirs
  @static_scan_dirs
end

#stub_llmObject

Returns the value of attribute stub_llm.



13
14
15
# File 'lib/code_to_query/configuration.rb', line 13

def stub_llm
  @stub_llm
end

#system_prompt_templateObject

Extended configuration knobs (added for LLM transport and logging)



25
26
27
# File 'lib/code_to_query/configuration.rb', line 25

def system_prompt_template
  @system_prompt_template
end