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



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/anima/cli.rb', line 74

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



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/anima/cli.rb', line 96

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

  TUI::Settings.load!
  host = options[:host] || TUI::Settings.connection_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/anima/cli.rb', line 25

def update
  require_relative "spinner"

  unless options[:migrate_only]
    success = Spinner.run("Upgrading anima-core gem...") do
      system("gem", "update", "anima-core", out: File::NULL, err: File::NULL)
    end
    unless success
      say "Run manually for details: gem update anima-core", :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

  require_relative "config_migrator"

  result = Spinner.run("Migrating brain configuration...") do
    Anima::ConfigMigrator.new.run
  end
  if result.status == :not_found
    say "Config file not found. Run 'anima install' first.", :red
    exit 1
  end
  report_migration("Config", result)

  tui_config_path = File.join(Anima::ConfigMigrator::ANIMA_HOME, "tui.toml")
  tui_template = File.expand_path("../../templates/tui.toml", __dir__)
  unless File.exist?(tui_config_path)
    File.write(tui_config_path, File.read(tui_template))
    say "  created #{tui_config_path} (new in this version)"
  end
  tui_result = Spinner.run("Migrating TUI configuration...") do
    Anima::ConfigMigrator.new(
      config_path: tui_config_path,
      template_path: tui_template
    ).run
  end
  report_migration("TUI config", tui_result)

  restart_service_if_active
end

#versionObject



114
115
116
117
# File 'lib/anima/cli.rb', line 114

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