Class: RailsAiContext::Tools::GetConfig

Inherits:
BaseTool
  • Object
show all
Defined in:
lib/rails_ai_context/tools/get_config.rb

Constant Summary

Constants inherited from BaseTool

BaseTool::SESSION_CONTEXT, BaseTool::SHARED_CACHE

Class Method Summary collapse

Methods inherited from BaseTool

abstract!, abstract?, cache_key, cached_context, config, extract_method_source_from_file, extract_method_source_from_string, find_closest_match, fuzzy_find_key, inherited, not_found_response, paginate, rails_app, registered_tools, reset_all_caches!, reset_cache!, session_queries, session_record, session_reset!, set_call_params, text_response

Class Method Details

.call(server_context: nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
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
# File 'lib/rails_ai_context/tools/get_config.rb', line 15

def self.call(server_context: nil)
  data = cached_context[:config]
  return text_response("Config introspection not available. Add :config to introspectors or use `config.preset = :full`.") unless data
  return text_response("Config introspection failed: #{data[:error]}") if data[:error]

  lines = [ "# Application Configuration", "" ]

  # Database — critical for query syntax decisions
  db_config = detect_database
  lines << "- **Database:** #{db_config}" if db_config

  # Auth framework — affects every controller
  auth = detect_auth_framework
  lines << "- **Auth:** #{auth}" if auth

  # Assets/CSS — uses frontend framework introspector data when available
  assets = detect_assets_stack
  lines << "- **Assets:** #{assets}" if assets

  # Action Cable — uses Rails config API with YAML fallback
  cable = detect_action_cable
  lines << "- **Action Cable:** #{cable}" if cable

  # Active Storage service
  storage = detect_active_storage
  lines << "- **Active Storage:** #{storage}" if storage

  # Action Mailer delivery method
  mailer_delivery = detect_mailer_delivery
  lines << "- **Mailer delivery:** #{mailer_delivery}" if mailer_delivery

  lines << "- **Cache store:** #{data[:cache_store]}" if data[:cache_store]
  lines << "- **Session store:** #{data[:session_store]}" if data[:session_store]
  lines << "- **Timezone:** #{data[:timezone]}" if data[:timezone]
  lines << "- **Queue adapter:** #{data[:queue_adapter]}" if data[:queue_adapter]
  if data[:mailer].is_a?(Hash) && data[:mailer].any?
    lines << "- **Mailer config:** #{data[:mailer].map { |k, v| "#{k}: #{v}" }.join(', ')}"
  end

  if data[:middleware_stack]&.any?
    # Filter default Rails middleware AND dev-only middleware
    dev_middleware = %w[
      Propshaft::Server WebConsole::Middleware ActionDispatch::Reloader
      Bullet::Rack ActiveSupport::Cache::Strategy::LocalCache
    ]
    excluded_mw = RailsAiContext.configuration.excluded_middleware
    custom = data[:middleware_stack].reject { |m| excluded_mw.include?(m) || dev_middleware.include?(m) }
    if custom.any?
      lines << "" << "## Custom Middleware"
      custom.each { |m| lines << "- #{m}" }
    end
  end

  if data[:initializers]&.any?
    # Filter out standard Rails initializers that every app has
    standard_inits = %w[
      content_security_policy.rb filter_parameter_logging.rb
      inflections.rb permissions_policy.rb assets.rb
      new_framework_defaults.rb cors.rb wrap_parameters.rb
    ]
    notable = data[:initializers].reject { |i| standard_inits.include?(i) }
    if notable.any?
      lines << "" << "## Initializers"
      notable.each { |i| lines << "- `#{i}`" }
    end
  end

  if data[:current_attributes]&.any?
    lines << "" << "## CurrentAttributes"
    data[:current_attributes].each { |c| lines << "- `#{c}`" }
  end

  text_response(lines.join("\n"))
end