Class: RailsAiContext::Tools::GetGems

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

Constant Summary collapse

GEM_CONFIG_HINTS =
{
  "devise" => "config/initializers/devise.rb",
  "pundit" => "app/policies/",
  "cancancan" => "app/models/ability.rb",
  "sidekiq" => "config/sidekiq.yml",
  # Rails 8's solid_queue generator writes queue.yml (worker/dispatcher
  # config) and recurring.yml (scheduled tasks) - never solid_queue.yml.
  # Checked at runtime since apps that only added the gem without
  # running the generator yet won't have either file.
  "solid_queue" => %w[config/queue.yml config/recurring.yml],
  "redis" => "config/initializers/redis.rb",
  "stripe" => "config/initializers/stripe.rb",
  "sentry-ruby" => "config/initializers/sentry.rb",
  "rollbar" => "config/initializers/rollbar.rb",
  "aws-sdk-s3" => "config/storage.yml",
  "pg_search" => "app/models/ (include PgSearch::Model)",
  "elasticsearch-rails" => "config/initializers/elasticsearch.rb",
  "pagy" => "config/initializers/pagy.rb",
  "kaminari" => "config/initializers/kaminari_config.rb",
  "rack-cors" => "config/initializers/cors.rb",
  "omniauth" => "config/initializers/omniauth.rb",
  "paper_trail" => "app/models/ (has_paper_trail)"
}.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(category: "all", offset: 0, limit: nil, server_context: nil) ⇒ Object



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
# File 'lib/rails_ai_context/tools/get_gems.rb', line 55

def self.call(category: "all", offset: 0, limit: nil, server_context: nil)
  gems = cached_context[:gems]
  return text_response("Gem introspection not available. Add :gems to introspectors.") unless gems
  return text_response("Gem introspection failed: #{gems[:error]}") if gems[:error]

  notable = gems[:notable_gems] || []
  notable = notable.select { |g| g[:category] == category } unless category == "all"
  sorted = notable.sort_by { |g| [ g[:category], g[:name] ] }

  page = paginate(sorted, offset: offset, limit: limit, default_limit: 50)

  lines = [ "# Notable Gems" ]

  if page[:items].any?
    current_cat = nil
    page[:items].each do |g|
      if g[:category] != current_cat
        current_cat = g[:category]
        lines << "" << "## #{current_cat.capitalize}"
      end
      config_hint = resolve_config_hint(GEM_CONFIG_HINTS[g[:name]])
      version_str = g[:version] ? " `#{g[:version]}`" : ""
      line = "- **#{g[:name]}**#{version_str}: #{g[:note]}"
      line += " _(config: #{config_hint})_" if config_hint
      lines << line
    end
  else
    all_cats = (gems[:notable_gems] || []).map { |g| g[:category] }.uniq.sort
    hint = all_cats.any? ? " Available categories: #{all_cats.join(', ')}" : ""
    lines << "_No notable gems found#{" in category '#{category}'" unless category == 'all'}.#{hint}_"
  end

  lines << "" << page[:hint] unless page[:hint].empty?
  text_response(lines.join("\n"))
end