Class: Legion::CLI::FleetCommand

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/legion/cli/fleet_command.rb', line 11

def self.exit_on_failure?
  true
end

Instance Method Details

#add(source) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/legion/cli/fleet_command.rb', line 85

def add(source)
  out = formatter
  result = add_fleet_source(source)

  if options[:json]
    out.json(result)
  elsif result[:success]
    out.success("Added #{source} as fleet source")
    puts "  Absorber: #{result[:absorber]}" if result[:absorber]
    puts "  Webhook:  #{result[:webhook_url]}" if result[:webhook_url]
    out.spacer
    puts '  The fleet will now process incoming events from this source.'
  else
    out.error("Failed to add source: #{result[:error]}")
    raise SystemExit, 1
  end
end

#approve(id) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/legion/cli/fleet_command.rb', line 66

def approve(id)
  out = formatter
  result = approve_work_item(id.to_i)

  if options[:json]
    out.json(result)
  elsif result[:success]
    out.success("Approved work item #{id} (#{result[:work_item_id]})")
    puts "  Pipeline resumed: #{result[:resumed]}"
  else
    out.error("Approval failed: #{result[:error]}")
    raise SystemExit, 1
  end
end

#configObject



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/legion/cli/fleet_command.rb', line 104

def config
  out = formatter
  with_settings do
    fleet_settings = Legion::Settings[:fleet] || {}

    if options[:json]
      out.json(fleet_settings)
    else
      out.header('Fleet Configuration')
      out.spacer
      puts "  Enabled:  #{fleet_settings[:enabled] || false}"
      puts "  Sources:  #{(fleet_settings[:sources] || []).join(', ').then { |s| s.empty? ? 'none' : s }}"
      out.spacer

      puts '  Defaults:'
      puts "    Planning:       #{fleet_settings.dig(:planning, :enabled) ? 'enabled' : 'disabled'}"
      puts "    Validation:     #{fleet_settings.dig(:validation, :enabled) ? 'enabled' : 'disabled'}"
      puts "    Max iterations: #{fleet_settings.dig(:implementation, :max_iterations) || 5}"
      puts "    Validators:     #{fleet_settings.dig(:implementation, :validators) || 3}"
      puts "    Isolation:      #{fleet_settings.dig(:workspace, :isolation) || 'worktree'}"
    end
  end
end

#pendingObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/legion/cli/fleet_command.rb', line 47

def pending
  out = formatter
  items = fetch_pending_approvals

  if options[:json]
    out.json(items)
  elsif items.empty?
    puts '  No pending approvals'
  else
    out.header('Pending Approvals')
    rows = items.first(options[:limit]).map do |item|
      [item[:id].to_s, item[:source_ref].to_s, item[:title].to_s,
       item[:source].to_s, item[:created_at].to_s]
    end
    out.table(['ID', 'Source Ref', 'Title', 'Source', 'Created'], rows)
  end
end

#statusObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/legion/cli/fleet_command.rb', line 21

def status
  out = formatter
  data = fetch_fleet_status

  if options[:json]
    out.json(data)
  else
    out.header('Fleet Pipeline Status')
    out.spacer

    puts "  Active work items: #{data[:active_work_items] || 0}"
    puts "  Workers:           #{data[:workers] || 0}"
    out.spacer

    if data[:queues]&.any?
      rows = data[:queues].map { |q| [q[:name], q[:depth].to_s] }
      out.table(%w[Queue Depth], rows)
    else
      puts '  No fleet queues found'
    end
  end
end