Ragex.AI.Features.Config (Ragex v0.8.0)

View Source

Configuration management for AI-enhanced features.

Provides a centralized configuration system for optional AI integrations throughout Ragex. Each feature can be individually enabled/disabled, and there's a master switch to control all AI features at once.

Configuration

# config/runtime.exs
config :ragex, :ai,
  enabled: true,  # Master switch - disables ALL AI features if false
  providers: [:deepseek_r1, :openai],
  default_provider: :deepseek_r1,
  fallback_enabled: true

config :ragex, :ai_features,
  # Editor features
  validation_error_explanation: true,
  refactor_preview_commentary: true,
  commit_message_generation: true,

  # Analysis features
  dead_code_refinement: true,
  duplication_semantic_analysis: true,
  dependency_insights: true,
  test_suggestions: false,
  complexity_explanation: true

Usage

# Check if a feature is enabled
if Config.enabled?(:validation_error_explanation) do
  # Use AI enhancement
else
  # Fallback to non-AI behavior
end

# Check with per-call override
if Config.enabled?(:refactor_preview_commentary, ai_preview: false) do
  # This will be false due to override
end

# Get feature-specific configuration
config = Config.get_feature_config(:validation_error_explanation)

Summary

Functions

Check if AI features are enabled globally.

Check if a specific AI feature is enabled.

Get the configuration map for a specific feature.

List all available AI features.

Get status of all AI features.

Types

feature()

@type feature() ::
  :validation_error_explanation
  | :refactor_preview_commentary
  | :commit_message_generation
  | :dead_code_refinement
  | :duplication_semantic_analysis
  | :dependency_insights
  | :test_suggestions
  | :complexity_explanation

override()

@type override() :: boolean() | :force

Functions

ai_enabled?()

@spec ai_enabled?() :: boolean()

Check if AI features are enabled globally.

Returns false if the master :ai, enabled flag is false, regardless of individual feature flags.

Examples

iex> Config.ai_enabled?()
true

enabled?(feature, opts \\ [])

@spec enabled?(
  feature(),
  keyword()
) :: boolean()

Check if a specific AI feature is enabled.

Respects the master AI switch and individual feature flags. Can be overridden with per-call options.

Parameters

  • feature - Feature identifier atom
  • opts - Keyword list with optional overrides:
    • :ai_<feature> - Override for specific feature (e.g., :ai_preview)
    • :force_ai - Force enable regardless of config (for testing)

Returns

  • true if feature should be used
  • false if feature should be skipped

Examples

# Check global + feature config
Config.enabled?(:validation_error_explanation)

# With per-call override (disable)
Config.enabled?(:refactor_preview_commentary, ai_preview: false)

# With per-call override (force enable)
Config.enabled?(:test_suggestions, force_ai: true)

get_feature_config(feature)

@spec get_feature_config(feature()) :: map()

Get the configuration map for a specific feature.

Returns feature-specific settings like timeout, cache TTL, model preferences, etc.

Parameters

  • feature - Feature identifier atom

Returns

  • Map of feature configuration options

Examples

iex> Config.get_feature_config(:validation_error_explanation)
%{
  enabled: true,
  timeout: 5000,
  cache_ttl: 604_800,  # 7 days
  temperature: 0.7
}

list_features()

@spec list_features() :: [feature()]

List all available AI features.

Returns

  • List of feature atoms

Examples

iex> Config.list_features()
[:validation_error_explanation, :refactor_preview_commentary, ...]

status()

@spec status() :: %{required(feature()) => boolean()}

Get status of all AI features.

Returns a map showing which features are currently enabled.

Returns

  • Map of feature => enabled status

Examples

iex> Config.status()
%{
  validation_error_explanation: true,
  refactor_preview_commentary: true,
  test_suggestions: false,
  ...
}