Class: Anima::Installer
- Inherits:
-
Object
- Object
- Anima::Installer
- Defined in:
- lib/anima/installer.rb
Constant Summary collapse
- DIRECTORIES =
%w[ agents skills db config/credentials log tmp tmp/pids tmp/cache ].freeze
- ANIMA_HOME =
Pathname.new(File.("~/.anima")).freeze
- TEMPLATE_DIR =
File.("../../templates", __dir__).freeze
Instance Attribute Summary collapse
-
#anima_home ⇒ Object
readonly
Returns the value of attribute anima_home.
Instance Method Summary collapse
- #create_config_file ⇒ Object
- #create_directories ⇒ Object
- #create_mcp_config ⇒ Object
- #create_settings_config ⇒ Object
-
#create_soul_file ⇒ Object
Copies the soul template to ~/.anima/soul.md — the agent’s self-authored identity file.
- #create_systemd_service ⇒ Object
- #generate_credentials ⇒ Object
-
#initialize(anima_home: ANIMA_HOME) ⇒ Installer
constructor
A new instance of Installer.
- #run ⇒ Object
Constructor Details
#initialize(anima_home: ANIMA_HOME) ⇒ Installer
Returns a new instance of Installer.
25 26 27 |
# File 'lib/anima/installer.rb', line 25 def initialize(anima_home: ANIMA_HOME) @anima_home = anima_home end |
Instance Attribute Details
#anima_home ⇒ Object (readonly)
Returns the value of attribute anima_home.
23 24 25 |
# File 'lib/anima/installer.rb', line 23 def anima_home @anima_home end |
Instance Method Details
#create_config_file ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/anima/installer.rb', line 63 def create_config_file config_path = anima_home.join("config", "anima.yml") return if config_path.exist? config_path.write(<<~YAML) # Anima configuration # See https://github.com/hoblin/anima for documentation YAML say " created #{config_path}" end |
#create_directories ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/anima/installer.rb', line 41 def create_directories DIRECTORIES.each do |dir| path = anima_home.join(dir) next if path.directory? FileUtils.mkdir_p(path) say " created #{path}" end end |
#create_mcp_config ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/anima/installer.rb', line 83 def create_mcp_config config_path = anima_home.join("mcp.toml") return if config_path.exist? config_path.write(<<~TOML) # MCP server configuration # Declare MCP servers here. Anima connects on startup and # registers their tools alongside built-in ones. # # HTTP transport: # [servers.example] # transport = "http" # url = "http://localhost:3000/mcp/v2" # headers = { Authorization = "Bearer ${API_KEY}" } # # Stdio transport: # [servers.example] # transport = "stdio" # command = "my-mcp-server" # args = ["--verbose"] # env = { API_KEY = "${API_KEY}" } TOML say " created #{config_path}" end |
#create_settings_config ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/anima/installer.rb', line 74 def create_settings_config config_path = anima_home.join("config.toml") return if config_path.exist? template = File.read(File.join(TEMPLATE_DIR, "config.toml")) config_path.write(template.gsub("{{ANIMA_HOME}}") { anima_home.to_s }) say " created #{config_path}" end |
#create_soul_file ⇒ Object
Copies the soul template to ~/.anima/soul.md — the agent’s self-authored identity file. Skips if the file already exists so agent-written content is never overwritten.
54 55 56 57 58 59 60 61 |
# File 'lib/anima/installer.rb', line 54 def create_soul_file soul_path = anima_home.join("soul.md") return if soul_path.exist? template = File.join(TEMPLATE_DIR, "soul.md") soul_path.write(File.read(template)) say " created #{soul_path}" end |
#create_systemd_service ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/anima/installer.rb', line 138 def create_systemd_service service_dir = Pathname.new(File.("~/.config/systemd/user")) service_path = service_dir.join("anima.service") FileUtils.mkdir_p(service_dir) anima_bin = File.join(Gem.bindir, "anima") unit_content = <<~UNIT [Unit] Description=Anima - Personal AI Agent After=network.target [Service] Type=simple ExecStart=#{anima_bin} start -e production Restart=on-failure RestartSec=5 [Install] WantedBy=default.target UNIT already_exists = service_path.exist? if already_exists && service_path.read == unit_content say " anima.service unchanged" else service_path.write(unit_content) say " #{already_exists ? "updated" : "created"} #{service_path}" end system("systemctl", "--user", "daemon-reload", err: File::NULL, out: File::NULL) system("systemctl", "--user", "enable", "--now", "anima.service", err: File::NULL, out: File::NULL) say " enabled and started anima.service" end |
#generate_credentials ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/anima/installer.rb', line 108 def generate_credentials require "active_support" require "active_support/encrypted_configuration" %w[production development test].each do |env| content_path = anima_home.join("config", "credentials", "#{env}.yml.enc") key_path = anima_home.join("config", "credentials", "#{env}.key") next if key_path.exist? && content_path.exist? content_str = content_path.to_s key_str = key_path.to_s key = ActiveSupport::EncryptedFile.generate_key key_path.write(key) File.chmod(0o600, key_str) config = ActiveSupport::EncryptedConfiguration.new( config_path: content_str, key_path: key_str, env_key: "RAILS_MASTER_KEY", raise_if_missing_key: true ) config.write("secret_key_base: #{SecureRandom.hex(64)}\n") File.chmod(0o600, content_str) say " created credentials for #{env}" end end |
#run ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/anima/installer.rb', line 29 def run say "Installing Anima to #{anima_home}..." create_directories create_soul_file create_config_file create_settings_config create_mcp_config generate_credentials create_systemd_service say "Installation complete. Brain is running. Connect with 'anima tui'." end |