Module: Legion::CLI::Chat::AgentRegistry

Defined in:
lib/legion/cli/chat/agent_registry.rb

Constant Summary collapse

AGENT_DIR =
'.legion/agents'
SUPPORTED_EXTENSIONS =
%w[.json .yml .yaml].freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.agentsObject (readonly)

Returns the value of attribute agents.



15
16
17
# File 'lib/legion/cli/chat/agent_registry.rb', line 15

def agents
  @agents
end

Class Method Details

.find(name) ⇒ Object



35
36
37
# File 'lib/legion/cli/chat/agent_registry.rb', line 35

def find(name)
  @agents[name]
end

.listObject



43
44
45
# File 'lib/legion/cli/chat/agent_registry.rb', line 43

def list
  @agents.values
end

.load_agents(base_dir = Dir.pwd) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/legion/cli/chat/agent_registry.rb', line 17

def load_agents(base_dir = Dir.pwd)
  @agents = {}
  dir = File.join(base_dir, AGENT_DIR)
  return @agents unless Dir.exist?(dir)

  Dir.glob(File.join(dir, '*')).each do |path|
    ext = File.extname(path)
    next unless SUPPORTED_EXTENSIONS.include?(ext)

    agent = parse_file(path)
    next unless agent && agent['name']

    @agents[agent['name']] = normalize(agent, path)
  end

  @agents
end

.match_for_task(task_description) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/legion/cli/chat/agent_registry.rb', line 47

def match_for_task(task_description)
  return nil if @agents.empty?

  @agents.values.max_by do |agent|
    score = 0
    keywords = (agent[:description] || '').downcase.split(/\W+/)
    task_words = task_description.downcase.split(/\W+/)
    matching = (keywords & task_words).length
    score += matching * 10
    score += (agent[:weight] || 1.0) * 5
    score
  end
end

.namesObject



39
40
41
# File 'lib/legion/cli/chat/agent_registry.rb', line 39

def names
  @agents.keys
end