Class: RailsAiContext::Tools::GetConfig
- 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::SESSION_CONTEXT, BaseTool::SHARED_CACHE
Class Method Summary collapse
Methods inherited from BaseTool
abstract!, abstract?, cache_key, cached_context, config, #dedupe_put_patch_routes, error_response, extract_method_source_from_file, extract_method_source_from_string, find_closest_match, fuzzy_find_key, inherited, introspection_warnings_note, 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 |
# 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? # 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 |