Class: RailsAiContext::Tools::GetConfig

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

Constant Summary collapse

STOCK_INITIALIZER_NOTES =

One-line descriptions for initializers Rails generates in every app.

{
  "assets.rb" => "asset pipeline paths/version",
  "content_security_policy.rb" => "Content-Security-Policy headers",
  "cors.rb" => "cross-origin request rules",
  "filter_parameter_logging.rb" => "hides sensitive params in logs",
  "inflections.rb" => "custom singular/plural rules",
  "permissions_policy.rb" => "browser feature permissions",
  "wrap_parameters.rb" => "JSON params wrapping"
}.freeze

Constants inherited from BaseTool

BaseTool::DEFAULT_SESSION, BaseTool::MAX_SESSIONS, BaseTool::MAX_SESSION_ID_LENGTH, BaseTool::SESSION_CONTEXT, BaseTool::SHARED_CACHE

Class Method Summary collapse

Methods inherited from BaseTool

abstract!, abstract?, api_only_app?, api_only_note, cache_key, cached_context, config, current_session, #dedupe_put_patch_routes, detail_param?, error_response, evict_oldest_sessions, extract_method_source_from_file, extract_method_source_from_string, find_closest_match, fuzzy_find_key, guide_row, inherited, introspection_warnings_note, invalid_detail_note, normalize_detail, not_found_response, paginate, rails_app, rails_env_name, registered_tools, reset_all_caches!, reset_cache!, session_from, session_params, session_queries, session_record, session_reset!, static_tier_banner, static_tier_refusal, text_response, touch_session, unavailable_note, with_session, with_session_for

Methods included from SectionFetch

#fetch_section, usable?

Class Method Details

.call(server_context: nil) ⇒ Object



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
89
90
91
92
93
94
# File 'lib/rails_ai_context/tools/get_config.rb', line 21

def self.call(server_context: nil)
  fetch_section(:config, subject: "Config introspection", remedy: "Add :config to introspectors or use `config.preset = :full`.") do |data|
    lines = [ "# Application Configuration", "" ]

    # Several values below (cache store, queue adapter, Action Cable)
    # differ per environment; name the one that produced them.
    if defined?(Rails) && Rails.respond_to?(:env)
      lines << "- **Environment:** #{Rails.env} (values below reflect this environment)"
    end

    # 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?
      # List every initializer - stock ones often carry active code
      # (filter_parameter_logging, assets), so hiding them misleads.
      lines << "" << "## Initializers"
      data[:initializers].each do |i|
        note = initializer_note(i)
        lines << (note ? "- `#{i}` - #{note}" : "- `#{i}`")
      end
    end

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

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