Class: RailsAiContext::Tools::GetJobPattern
- Defined in:
- lib/rails_ai_context/tools/get_job_pattern.rb
Constant Summary
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(job: nil, detail: "standard", server_context: nil) ⇒ Object
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 |
# File 'lib/rails_ai_context/tools/get_job_pattern.rb', line 27 def self.call(job: nil, detail: "standard", server_context: nil) root = Rails.root.to_s jobs_dir = File.join(root, "app", "jobs") real_root = File.realpath(root).to_s jobs_dir_exists = Dir.exist?(jobs_dir) if jobs_dir_exists real_jobs_dir = File.realpath(jobs_dir).to_s files = Dir.glob(File.join(jobs_dir, "**", "*.rb")) .filter_map { |f| safe_glob_realpath(f, real_jobs_dir, real_root) } .sort job_files = files.reject { |f| File.basename(f) == "application_job.rb" } else real_jobs_dir = jobs_dir job_files = [] end # Pull enriched channel data from the cached introspector context - this # gives us the v5.8.0 fields (identified_by, streams, periodic, actions) # that JobIntrospector#extract_channels populates. channels = (cached_context.dig(:jobs, :channels) || []).reject { |c| c.is_a?(Hash) && c[:error] } # Single-job query: requires jobs to be present. if job return text_response((jobs_dir_exists)) if job_files.empty? return format_single_job(job, job_files, real_jobs_dir, real_root) end # No jobs and no channels - bail out, but say honestly whether the # directory is missing or just has no job classes beyond ApplicationJob. if job_files.empty? && channels.empty? return text_response((jobs_dir_exists)) end # Compose: jobs section (if any) + channels section (if any). lines = [] lines.concat(format_job_listing_lines(job_files, real_jobs_dir, real_root, detail)) if job_files.any? if channels.any? lines << "" if lines.any? lines.concat(format_channels_section(channels)) end text_response(lines.join("\n")) end |