Class: RailsAiContext::Tools::GetContext

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

Constant Summary collapse

INCLUDE_MAP =
{
  "stimulus"    => -> { GetStimulus.call(detail: "standard") },
  "turbo"       => -> { GetTurboMap.call(detail: "standard") },
  "services"    => -> { GetServicePattern.call(detail: "standard") },
  "jobs"        => -> { GetJobPattern.call(detail: "standard") },
  "conventions" => -> { GetConventions.call },
  "helpers"     => -> { GetHelperMethods.call(detail: "standard") },
  "env"         => -> { GetEnv.call(detail: "summary") },
  "callbacks"   => -> { GetCallbacks.call(detail: "standard") },
  "tests"       => -> { GetTestInfo.call(detail: "full") },
  "config"      => -> { GetConfig.call },
  "gems"        => -> { GetGems.call },
  "security"    => -> { SecurityScan.call(detail: "summary") }
}.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(controller: nil, action: nil, model: nil, feature: nil, include: nil, server_context: nil) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/rails_ai_context/tools/get_context.rb', line 46

def self.call(controller: nil, action: nil, model: nil, feature: nil, include: nil, server_context: nil)
  base_text = if controller && action
    controller_action_context(controller, action)
  elsif controller
    controller_context(controller)
  elsif model
    model_context(model)
  elsif feature
    feature_context(feature)
  else
    return text_response("Provide at least one of: controller, model, or feature.")
  end

  # Append additional context sections if include: is specified
  base_text += append_includes(include) if include.is_a?(Array) && include.any?

  ctx = begin
    cached_context
  rescue StandardError
    nil
  end

  text_response(base_text, suffix: introspection_warnings_note(ctx))
end