Class: Anima::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/anima/cli.rb,
lib/anima/cli/mcp.rb,
lib/anima/cli/mcp/secrets.rb

Defined Under Namespace

Classes: Mcp

Constant Summary collapse

VALID_ENVIRONMENTS =
%w[development test production].freeze
DEFAULT_PORT =
42134
DEFAULT_HOST =
"localhost:#{DEFAULT_PORT}"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/anima/cli.rb', line 13

def self.exit_on_failure?
  true
end

Instance Method Details

#installObject



18
19
20
21
# File 'lib/anima/cli.rb', line 18

def install
  require_relative "installer"
  Installer.new.run
end

#startObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/anima/cli.rb', line 60

def start
  env = options[:environment] || ENV.fetch("RAILS_ENV", "development")
  unless VALID_ENVIRONMENTS.include?(env)
    say "Invalid environment: #{env}. Must be one of: #{VALID_ENVIRONMENTS.join(", ")}", :red
    exit 1
  end

  ENV["RAILS_ENV"] = env

  unless File.directory?(File.expand_path("~/.anima"))
    say "Anima is not installed. Run 'anima install' first.", :red
    exit 1
  end

  gem_root = Anima.gem_root
  system(gem_root.join("bin/rails").to_s, "db:prepare", chdir: gem_root.to_s) || abort("db:prepare failed")
  exec("foreman", "start", "-f", gem_root.join("Procfile").to_s, "-p", DEFAULT_PORT.to_s, chdir: gem_root.to_s)
end

#tuiObject



82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/anima/cli.rb', line 82

def tui
  require "ratatui_ruby"
  require_relative "../tui/app"

  host = options[:host] || DEFAULT_HOST

  say "Connecting to brain at #{host}...", :cyan

  cable_client = TUI::CableClient.new(host: host)
  cable_client.connect

  TUI::App.new(cable_client: cable_client, debug: options[:debug]).run
end

#updateObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/anima/cli.rb', line 25

def update
  unless options[:migrate_only]
    say "Upgrading anima-core gem..."
    unless system("gem", "update", "anima-core")
      say "Gem update failed.", :red
      exit 1
    end

    # Re-exec with the updated gem so migration uses the new template.
    exec(File.join(Gem.bindir, "anima"), "update", "--migrate-only")
  end

  say "Migrating configuration..."
  require_relative "config_migrator"
  result = Anima::ConfigMigrator.new.run

  case result.status
  when :not_found
    say "Config file not found. Run 'anima install' first.", :red
    exit 1
  when :up_to_date
    say "Config is already up to date."
  when :updated
    result.additions.each do |addition|
      say "  added [#{addition.section}] #{addition.key} = #{addition.value.inspect}"
    end
    say "Config updated. Changes take effect immediately — no restart needed."
  end
end

#versionObject



98
99
100
101
# File 'lib/anima/cli.rb', line 98

def version
  require_relative "version"
  say "anima #{Anima::VERSION}"
end