Module: AIA::Directives::Utility

Defined in:
lib/aia/directives/utility.rb

Constant Summary collapse

TERSE_PROMPT =
"\nKeep your response short and to the point.\n"

Class Method Summary collapse

Class Method Details

.next(args = [], context_manager = nil) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/aia/directives/utility.rb', line 50

def self.next(args = [], context_manager = nil)
  if args.empty?
    ap AIA.config.next
  else
    AIA.config.next = args.shift
  end
  ''
end

.pipeline(args = [], context_manager = nil) ⇒ Object Also known as: workflow



59
60
61
62
63
64
65
66
67
68
# File 'lib/aia/directives/utility.rb', line 59

def self.pipeline(args = [], context_manager = nil)
  if args.empty?
    ap AIA.config.pipeline
  elsif 1 == args.size
    AIA.config.pipeline += args.first.split(',').map(&:strip).reject { |id| id.empty? }
  else
    AIA.config.pipeline += args.map { |id| id.gsub(',', '').strip }.reject { |id| id.empty? }
  end
  ''
end

.robot(args, context_manager = nil) ⇒ Object



74
75
76
77
# File 'lib/aia/directives/utility.rb', line 74

def self.robot(args, context_manager = nil)
  AIA::Utility.robot
  ""
end

.terse(args, context_manager = nil) ⇒ Object



70
71
72
# File 'lib/aia/directives/utility.rb', line 70

def self.terse(args, context_manager = nil)
  TERSE_PROMPT
end

.tools(args = [], context_manager = nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/aia/directives/utility.rb', line 11

def self.tools(args = [], context_manager = nil)
  indent = 4
  spaces = " " * indent
  width = TTY::Screen.width - indent - 2
  filter = args.first&.downcase

  if AIA.config.tools.empty?
    puts "No tools are available"
  else
    tools_to_display = AIA.config.tools

    if filter
      tools_to_display = tools_to_display.select do |tool|
        name = tool.respond_to?(:name) ? tool.name : tool.class.name
        name.downcase.include?(filter)
      end
    end

    if tools_to_display.empty?
      puts "No tools match the filter: #{args.first}"
    else
      puts
      header = filter ? "Available Tools (filtered by '#{args.first}')" : "Available Tools"
      puts header
      puts "=" * header.length

      tools_to_display.each do |tool|
        name = tool.respond_to?(:name) ? tool.name : tool.class.name
        puts "\n#{name}"
        puts "-" * name.size
        puts WordWrapper::MinimumRaggedness.new(width, tool.description).wrap.split("\n").map { |s| spaces + s + "\n" }.join
      end
    end
  end
  puts

  ''
end