Class: RailsAiContext::Tools::GetJobPattern

Inherits:
BaseTool
  • Object
show all
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, extract_method_source_from_file, extract_method_source_from_string, find_closest_match, fuzzy_find_key, inherited, 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
# 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

  if Dir.exist?(jobs_dir)
    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("No app/jobs/ directory found. This app may not use background jobs.") if job_files.empty?
    return format_single_job(job, job_files, real_jobs_dir, real_root)
  end

  # No jobs and no channels — bail out with the legacy message.
  if job_files.empty? && channels.empty?
    return text_response("No app/jobs/ directory found and no Action Cable channels detected. This app may not use background jobs.")
  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