Class: Legion::CLI::Swarm

Inherits:
Thor
  • Object
show all
Defined in:
lib/legion/cli/swarm_command.rb

Constant Summary collapse

WORKFLOW_DIR =
'.legion/swarms'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/legion/cli/swarm_command.rb', line 9

def self.exit_on_failure?
  true
end

Instance Method Details

#listObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/legion/cli/swarm_command.rb', line 36

def list
  out = formatter
  dir = File.join(Dir.pwd, WORKFLOW_DIR)

  unless Dir.exist?(dir)
    out.warn("No workflows found. Create them in #{WORKFLOW_DIR}/")
    return
  end

  files = Dir.glob(File.join(dir, '*.json'))
  if files.empty?
    out.warn("No workflow files found in #{WORKFLOW_DIR}/")
    return
  end

  out.header("Swarm Workflows (#{files.length})")
  files.each do |f|
    name = File.basename(f, '.json')
    workflow = parse_workflow_file(f)
    goal = workflow&.dig('goal') || '(no goal)'
    puts "  #{name}#{goal}"
  end
end

#show(name) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/legion/cli/swarm_command.rb', line 61

def show(name)
  out = formatter
  workflow = load_workflow(name)

  if options[:json]
    out.json(workflow)
  else
    out.header("Workflow: #{workflow['name'] || name}")
    puts "  Goal: #{workflow['goal']}"
    puts
    (workflow['agents'] || []).each do |agent|
      puts "  #{out.colorize(agent['role'], :accent)}"
      puts "    #{agent['description']}"
      puts "    Tools: #{agent['tools']&.join(', ') || 'all'}"
      puts "    Model: #{agent['model'] || 'default'}"
      puts
    end
    puts "  Pipeline: #{workflow['pipeline']&.join(' -> ')}"
  end
end

#start(name) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/legion/cli/swarm_command.rb', line 22

def start(name)
  out = formatter
  workflow = load_workflow(name)

  out.header("Swarm: #{workflow['name'] || name}")
  puts out.dim("  Goal: #{workflow['goal']}")
  puts out.dim("  Agents: #{workflow['agents']&.length || 0}")
  puts out.dim("  Pipeline: #{workflow['pipeline']&.join(' -> ')}")
  puts

  run_workflow(workflow, out)
end