Class: AIA::DirectiveProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/aia/directive_processor.rb

Constant Summary collapse

EXCLUDED_METHODS =
%w[ run initialize private? ]

Instance Method Summary collapse

Constructor Details

#initializeDirectiveProcessor

Returns a new instance of DirectiveProcessor.



14
15
16
17
18
# File 'lib/aia/directive_processor.rb', line 14

def initialize
  @prefix_size = PromptManager::Prompt::DIRECTIVE_SIGNAL.size
  @included_files = []
  Directives::WebAndFile.included_files = @included_files
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object (private)

Keep backward compatibility by delegating to Registry



71
72
73
74
75
76
77
# File 'lib/aia/directive_processor.rb', line 71

def method_missing(method_name, *args, &block)
  if Directives::Registry.respond_to?(method_name, true)
    Directives::Registry.send(method_name, *args, &block)
  else
    super
  end
end

Instance Method Details

#directive?(string) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/aia/directive_processor.rb', line 20

def directive?(string)
  Directives::Registry.directive?(string)
end

#process(string, context_manager) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/aia/directive_processor.rb', line 24

def process(string, context_manager)
  return string unless directive?(string)

  content = if string.is_a?(RubyLLM::Message)
             string.content rescue string.to_s
           else
             string.to_s
           end

  key = content.strip
  sans_prefix = key[@prefix_size..]
  args = sans_prefix.split(' ')
  method_name = args.shift.downcase

  Directives::Registry.process(method_name, args, context_manager)
end

#run(directives) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/aia/directive_processor.rb', line 41

def run(directives)
  return {} if directives.nil? || directives.empty?

  directives.each do |key, _|
    sans_prefix = key[@prefix_size..]
    args = sans_prefix.split(' ')
    method_name = args.shift.downcase

    # Use the new module-based directive system
    # Pass nil as context_manager since it's not available at the prompt processing level
    directives[key] = Directives::Registry.process(method_name, args, nil)
  end

  directives
end