Class: Legion::CLI::Mode

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

Constant Summary collapse

SETTINGS_DIR =
File.expand_path('~/.legionio/settings')
ROLE_FILE =
File.join(SETTINGS_DIR, 'role.json')
VALID_PROFILES =
%i[core cognitive service dev custom].freeze
PROFILE_DESCRIPTIONS =
{
  core:      '14 core operational extensions only',
  cognitive: 'core + all agentic extensions',
  service:   'core + service + other integrations',
  dev:       'core + AI + essential agentic (~20 extensions)',
  custom:    'only extensions listed in role.extensions'
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/legion/cli/mode_command.rb', line 24

def self.exit_on_failure?
  true
end

Instance Method Details

#listObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/legion/cli/mode_command.rb', line 56

def list
  out = formatter
  Connection.ensure_settings(resolve_secrets: false)

  if options[:json]
    out.json({ profiles: PROFILE_DESCRIPTIONS, process_roles: Legion::ProcessRole::ROLES.keys })
    return
  end

  out.header('Extension Profiles')
  profile_rows = PROFILE_DESCRIPTIONS.map do |name, desc|
    count = count_extensions_for_profile(name)
    [name.to_s, desc, count.to_s]
  end
  out.table(%w[profile description extensions], profile_rows)

  out.spacer
  out.header('Process Roles')
  role_rows = Legion::ProcessRole::ROLES.map do |name, subsystems|
    enabled = subsystems.select { |_, v| v }.keys.join(', ')
    [name.to_s, enabled]
  end
  out.table(%w[role enabled_subsystems], role_rows)
end

#set(profile = nil) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/legion/cli/mode_command.rb', line 96

def set(profile = nil)
  out = formatter
  Connection.ensure_settings(resolve_secrets: false)

  validate_inputs!(out, profile)

  new_config = build_config(profile)
  existing = read_existing_config

  if options[:dry_run]
    show_dry_run(out, existing, new_config)
    return
  end

  write_config(new_config)
  out.success("Mode updated: #{ROLE_FILE}")
  show_written_config(out, new_config)

  trigger_reload(out) if options[:reload]
end

#showObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/legion/cli/mode_command.rb', line 32

def show
  out = formatter
  Connection.ensure_settings(resolve_secrets: false)

  process_role = Legion::ProcessRole.current
  profile = Legion::Settings.dig(:role, :profile)&.to_s || '(none — all extensions load)'
  custom_exts = Array(Legion::Settings.dig(:role, :extensions))

  if options[:json]
    out.json({ process_role: process_role, extension_profile: profile,
               custom_extensions: custom_exts })
    return
  end

  out.header('Current Mode')
  details = {
    'Process Role'      => process_role.to_s,
    'Extension Profile' => profile
  }
  details['Custom Extensions'] = custom_exts.join(', ') if profile.to_s == 'custom' && custom_exts.any?
  out.detail(details)
end