Ragex.Analysis.Runner (Ragex v0.17.2)

View Source

Shared analysis runner logic used by both Mix tasks and MCP tools.

Extracts the "run all analyses" pipeline so that:

  • mix ragex.analyze can run it locally
  • The comprehensive_analyze MCP tool can run it on the server
  • Mix tasks can delegate to the running server via MCP without starting a second BEAM VM

Summary

Functions

Analyzes a directory and populates the knowledge graph.

Analyzes an explicit list of file paths and populates the knowledge graph.

Filters analysis results to only include issues touching the given files.

Runs all enabled analyses based on the config.

Types

analyze_result()

@type analyze_result() :: %{
  files_analyzed: non_neg_integer(),
  entities_found: non_neg_integer(),
  errors: list()
}

config()

@type config() :: %{
  :path => String.t(),
  :severity => [atom()],
  :threshold => float(),
  :min_complexity => integer(),
  :god_threshold => integer(),
  :instability_threshold => float(),
  :analyses => %{required(atom()) => boolean()},
  optional(atom()) => term()
}

Functions

analyze_directory(path, opts \\ [])

@spec analyze_directory(
  String.t(),
  keyword()
) :: {:ok, analyze_result()} | {:error, term()}

Analyzes a directory and populates the knowledge graph.

Returns {:ok, analyze_result} or {:error, reason}.

analyze_files(file_paths, opts \\ [])

@spec analyze_files(
  [String.t()],
  keyword()
) :: {:ok, analyze_result()} | {:error, term()}

Analyzes an explicit list of file paths and populates the knowledge graph.

Used by diff-based analysis to index only changed files.

filter_results_by_files(results, changed_files)

@spec filter_results_by_files(map(), MapSet.t()) :: map()

Filters analysis results to only include issues touching the given files.

changed_files is a MapSet of relative file paths. Results whose file path is not in the set are removed. Whole-project analyses (circulars, coupling, etc.) pass through unfiltered since they represent structural properties, not per-file issues.

run_all(config)

@spec run_all(config()) :: map()

Runs all enabled analyses based on the config.

Returns a map of %{analysis_type => result} matching the format expected by Mix.Tasks.Ragex.Analyze formatters.