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::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(category: "all", offset: 0, limit: nil, server_context: nil) ⇒ Object



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

def self.call(category: "all", offset: 0, limit: nil, server_context: nil)
  fetch_section(:gems, subject: "Gem introspection") do |gems|
    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
    elsif page[:total].zero?
      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
    # An empty page past the end is not an empty app. Saying "no notable
    # gems found" above "No items at offset 9999. Total: 13." contradicts
    # itself, and the first line is the one that reads as the answer.

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