Class: RuboCop::Cop::Legion::Framework::NoDirectDispatch

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/legion/framework/no_direct_dispatch.rb

Overview

Bans defining methods matching ‘/_directz/` on `Legion::LLM` modules. Per G16, all pipeline bypasses (`chat_direct`, `embed_direct`, `structured_direct`) are removed — internal callers route through the governed pipeline with an appropriate profile.

No auto-correct is provided because the fix requires routing through the inference pipeline.

Examples:

# bad
module Legion::LLM
  def chat_direct(message:)
    # bypasses metering, audit, ledger
  end
end

# bad
module Legion::LLM
  def self.embed_direct(text:)
  end
end

# good
module Legion::LLM
  def chat(message:)
    # routes through pipeline
  end
end

Constant Summary collapse

MSG =
'Method `%<name>s` matches `/_direct\\z/` on a `Legion::LLM` module. ' \
'Pipeline bypasses are not allowed — route through the governed pipeline.'
DIRECT_PATTERN =
/_direct\z/

Instance Method Summary collapse

Instance Method Details

#on_def(node) ⇒ Object



41
42
43
44
45
46
# File 'lib/rubocop/cop/legion/framework/no_direct_dispatch.rb', line 41

def on_def(node)
  return unless node.method_name.to_s.match?(DIRECT_PATTERN)
  return unless inside_legion_llm?(node)

  add_offense(node.loc.name, message: format(MSG, name: node.method_name))
end

#on_defs(node) ⇒ Object



48
49
50
51
52
53
# File 'lib/rubocop/cop/legion/framework/no_direct_dispatch.rb', line 48

def on_defs(node)
  return unless node.method_name.to_s.match?(DIRECT_PATTERN)
  return unless inside_legion_llm?(node)

  add_offense(node.loc.name, message: format(MSG, name: node.method_name))
end