Class: Legion::TTY::Screens::Extensions

Inherits:
Base
  • Object
show all
Defined in:
lib/legion/tty/screens/extensions.rb

Overview

rubocop:disable Metrics/ClassLength

Constant Summary collapse

CORE =
%w[lex-node lex-tasker lex-scheduler lex-conditioner lex-transformer
lex-synapse lex-health lex-log lex-ping lex-metering lex-llm-gateway
lex-codegen lex-exec lex-lex lex-telemetry lex-audit lex-detect].freeze
AI =
%w[lex-claude lex-openai lex-gemini].freeze
SERVICE =
%w[lex-http lex-vault lex-github lex-consul lex-kerberos lex-tfe
lex-redis lex-memcached lex-elasticsearch lex-s3].freeze
CATEGORIES =
[nil, 'Core', 'AI', 'Service', 'Agentic', 'Other'].freeze

Instance Attribute Summary

Attributes inherited from Base

#app

Instance Method Summary collapse

Methods inherited from Base

#deactivate, #teardown

Constructor Details

#initialize(app, output: $stdout) ⇒ Extensions

Returns a new instance of Extensions.



22
23
24
25
26
27
28
29
# File 'lib/legion/tty/screens/extensions.rb', line 22

def initialize(app, output: $stdout)
  super(app)
  @output = output
  @gems = []
  @selected = 0
  @detail = false
  @filter = nil
end

Instance Method Details

#activateObject



31
32
33
# File 'lib/legion/tty/screens/extensions.rb', line 31

def activate
  @gems = discover_extensions
end

#discover_extensionsObject



35
36
37
38
39
# File 'lib/legion/tty/screens/extensions.rb', line 35

def discover_extensions
  Gem::Specification.select { |s| s.name.start_with?('lex-') }
                    .sort_by(&:name)
                    .map { |s| build_entry(s) }
end

#handle_input(key) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/legion/tty/screens/extensions.rb', line 54

def handle_input(key)
  case key
  when :up
    @selected = [(@selected - 1), 0].max
    :handled
  when :down
    max = [current_gems.size - 1, 0].max
    @selected = [(@selected + 1), max].min
    :handled
  when :enter
    @detail = !@detail
    :handled
  when 'q', :escape
    handle_back_key
  else
    handle_action_key(key)
  end
end

#render(_width, height) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/legion/tty/screens/extensions.rb', line 41

def render(_width, height)
  filter_label = @filter ? Theme.c(:warning, "  filter: #{@filter}") : ''
  header = [Theme.c(:accent, '  LEX Extensions'), filter_label].reject(&:empty?)
  lines = header + ['']
  lines += if @detail && current_gems[@selected]
             detail_lines(current_gems[@selected])
           else
             list_lines(height - 4)
           end
  lines += ['', Theme.c(:muted, '  Enter=detail  o=open  f=filter  c=clear  q=back')]
  pad_lines(lines, height)
end