Class: Legion::CLI::MindGrowth

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


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

def self.exit_on_failure?
  true
end

Instance Method Details

#approve(proposal_id) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/legion/cli/mind_growth_command.rb', line 53

def approve(proposal_id)
  require_mind_growth!
  result = mind_growth_client.evaluate_proposal(proposal_id: proposal_id)
  out = formatter
  if options[:json]
    out.json(result)
  elsif result[:success]
    status_label = result[:approved] ? 'approved' : 'rejected'
    out.success("Proposal #{proposal_id[0, 8]} #{status_label}")
  else
    out.warn("Evaluation failed: #{result[:error]}")
  end
end

#build(proposal_id) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/legion/cli/mind_growth_command.rb', line 90

def build(proposal_id)
  require_mind_growth!
  result = mind_growth_client.build_extension(proposal_id: proposal_id)
  out = formatter
  if options[:json]
    out.json(result)
  elsif result[:success]
    out.success("Build pipeline started for #{proposal_id[0, 8]}")
    out.detail(result[:pipeline]) if result[:pipeline]
  else
    out.warn("Build failed: #{result[:error]}")
  end
end

#healthObject



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/legion/cli/mind_growth_command.rb', line 149

def health
  require_mind_growth!
  result = mind_growth_client.validate_fitness(extensions: [])
  out = formatter
  if options[:json]
    out.json(result)
  else
    out.header('Extension Fitness')
    out.spacer
    ranked = result[:ranked] || []
    if ranked.empty?
      out.warn('No extensions to score')
    else
      rows = ranked.map { |e| [e[:name].to_s, format('%.3f', e[:fitness].to_f)] }
      out.table(%w[extension fitness], rows)
    end
  end
end

#historyObject



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/legion/cli/mind_growth_command.rb', line 184

def history
  require_mind_growth!
  result = mind_growth_client.list_proposals(limit: options[:limit])
  out = formatter
  if options[:json]
    out.json(result)
  else
    rows = (result[:proposals] || []).map do |p|
      [p[:id].to_s[0, 8], p[:name].to_s, p[:category].to_s,
       p[:status].to_s, p[:created_at].to_s]
    end
    if rows.empty?
      out.warn('No proposals found')
    else
      out.table(%w[id name category status created_at], rows)
    end
  end
end

#profileObject



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/legion/cli/mind_growth_command.rb', line 130

def profile
  require_mind_growth!
  result = mind_growth_client.cognitive_profile
  out = formatter
  if options[:json]
    out.json(result)
  else
    out.header('Cognitive Architecture Profile')
    out.spacer
    out.detail({ total_extensions: result[:total_extensions],
                 overall_coverage: result[:overall_coverage] })
    out.spacer
    coverage = result[:model_coverage] || {}
    rows = coverage.map { |model, data| [model.to_s, data[:coverage].to_s, data[:missing].to_s] }
    out.table(%w[model coverage missing], rows) unless rows.empty?
  end
end

#proposalsObject



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

def proposals
  require_mind_growth!
  result = mind_growth_client.list_proposals(
    status: options[:status]&.to_sym,
    limit:  options[:limit]
  )
  out = formatter
  if options[:json]
    out.json(result)
  else
    rows = (result[:proposals] || []).map do |p|
      [p[:id].to_s[0, 8], p[:name].to_s, p[:category].to_s,
       p[:status].to_s, p[:created_at].to_s]
    end
    if rows.empty?
      out.warn('No proposals found')
    else
      out.table(%w[id name category status created_at], rows)
    end
  end
end

#proposeObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/legion/cli/mind_growth_command.rb', line 35

def propose
  require_mind_growth!
  result = mind_growth_client.propose_concept(
    category:    options[:category]&.to_sym,
    description: options[:description],
    name:        options[:name]
  )
  out = formatter
  if options[:json]
    out.json(result)
  elsif result[:success]
    out.success("Proposal created: #{result.dig(:proposal, :id)}")
  else
    out.warn("Proposal failed: #{result[:error]}")
  end
end

#reject_proposal(proposal_id) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/legion/cli/mind_growth_command.rb', line 70

def reject_proposal(proposal_id)
  require_mind_growth!
  proposal = Legion::Extensions::MindGrowth::Runners::Proposer.get_proposal_object(proposal_id)
  out = formatter
  if proposal.nil?
    out.warn("Proposal #{proposal_id[0, 8]} not found")
    return
  end
  proposal.transition!(:rejected)
  if options[:json]
    out.json({ success: true, proposal_id: proposal_id, status: 'rejected',
               reason: options[:reason] })
  else
    out.success("Proposal #{proposal_id[0, 8]} rejected")
  end
rescue ArgumentError => e
  formatter.warn("Cannot reject: #{e.message}")
end

#reportObject



169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/legion/cli/mind_growth_command.rb', line 169

def report
  require_mind_growth!
  result = mind_growth_client.session_report
  out = formatter
  if options[:json]
    out.json(result)
  else
    out.header('Mind-Growth Report')
    out.spacer
    out.detail(result)
  end
end

#statusObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/legion/cli/mind_growth_command.rb', line 18

def status
  require_mind_growth!
  result = mind_growth_client.growth_status
  out = formatter
  if options[:json]
    out.json(result)
  else
    out.header('Mind-Growth Status')
    out.spacer
    out.detail(result)
  end
end