Class: Protege::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Protege::Generators::InstallGenerator
- Defined in:
- lib/generators/protege/install/install_generator.rb
Overview
Bootstraps Protege into a host Rails app — the one command to go from gem 'protege' to a
runnable dashboard. It installs the Rails frameworks Protege depends on (Active Storage for
attachments, Action Mailbox for inbound mail), writes a fully-documented initializer, mounts the
engine, wires the Loop's recurring tick, and scaffolds a starter persona. The steps it cannot do
safely for you — wrapping the mount in your own authentication, running migrations, setting
credentials — are printed as next steps.
Constant Summary collapse
- RECURRING_TICK =
The recurring job entry that drives the Loop scheduler — one tick a minute fires due responsibilities. Written at column zero; #indented_tick nests it under an environment key.
<<~YAML protege_responsibility_tick: class: Protege::ResponsibilityTickJob schedule: every minute YAML
- ENVIRONMENTS =
The recurring.yml environments the tick must run in.
%w[production development].freeze
Instance Method Summary collapse
-
#add_recurring_tick ⇒ void
Wire the Loop's recurring tick into
config/recurring.yml. -
#create_initializer ⇒ void
Write the fully-documented Protege initializer with smart, ENV-backed defaults.
-
#create_starter_persona ⇒ void
Scaffold a starter
Agentpersona by delegating to the persona generator (single source of truth for the persona template). -
#install_dependencies ⇒ void
Install the Rails frameworks Protege builds on: Active Storage (attachments) and Action Mailbox (inbound mail — this also creates
app/mailboxes/application_mailbox.rb). -
#mount_engine ⇒ void
Mount the engine in the host's routes, with a loud reminder to wrap it in authentication — the engine ships none, so an unwrapped mount exposes the dashboard to everyone.
-
#print_next_steps ⇒ void
Print the wiring the generator can't safely automate.
Instance Method Details
#add_recurring_tick ⇒ void
This method returns an undefined value.
Wire the Loop's recurring tick into config/recurring.yml. Creates the file when absent;
ensures the tick runs in both production and development, injecting it under an existing
environment key or appending a fresh block when that environment is absent (a fresh Rails app
ships only a production: block, so development: is added). Idempotent — a second run is a
no-op once the tick is present.
69 70 71 72 73 74 75 76 77 |
# File 'lib/generators/protege/install/install_generator.rb', line 69 def add_recurring_tick path = 'config/recurring.yml' if !file_exists?(path) create_file path, ENVIRONMENTS.map { |env| "#{env}:\n#{indented_tick}" }.join("\n") elsif !recurring_already_wired?(path) ENVIRONMENTS.each { |env| add_tick_for(env, path) } end end |
#create_initializer ⇒ void
This method returns an undefined value.
Write the fully-documented Protege initializer with smart, ENV-backed defaults.
46 47 48 |
# File 'lib/generators/protege/install/install_generator.rb', line 46 def create_initializer template 'initializer.rb.tt', 'config/initializers/protege.rb' end |
#create_starter_persona ⇒ void
This method returns an undefined value.
Scaffold a starter Agent persona by delegating to the persona generator (single source of
truth for the persona template).
83 84 85 |
# File 'lib/generators/protege/install/install_generator.rb', line 83 def create_starter_persona invoke Protege::Generators::PersonaGenerator, ['Agent'] end |
#install_dependencies ⇒ void
This method returns an undefined value.
Install the Rails frameworks Protege builds on: Active Storage (attachments) and Action Mailbox
(inbound mail — this also creates app/mailboxes/application_mailbox.rb). Their migrations are
copied here; Protege's own migrations load straight from the gem.
38 39 40 41 |
# File 'lib/generators/protege/install/install_generator.rb', line 38 def install_dependencies rails_command 'active_storage:install' rails_command 'action_mailbox:install' end |
#mount_engine ⇒ void
This method returns an undefined value.
Mount the engine in the host's routes, with a loud reminder to wrap it in authentication — the engine ships none, so an unwrapped mount exposes the dashboard to everyone.
54 55 56 57 58 59 60 |
# File 'lib/generators/protege/install/install_generator.rb', line 54 def mount_engine route <<~RUBY.chomp # TODO: Protege ships no authentication — wrap this mount in your app's auth # (e.g. `authenticate :user do ... end`) before exposing the dashboard. mount Protege::Engine => '/protege' RUBY end |
#print_next_steps ⇒ void
This method returns an undefined value.
Print the wiring the generator can't safely automate.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/generators/protege/install/install_generator.rb', line 90 def print_next_steps say "\n Protege installed.", :green say <<~STEPS Next steps: 1. Run the migrations (Active Storage, Action Mailbox, and Protege's own): bin/rails db:migrate 2. WRAP THE ENGINE MOUNT in your authentication in config/routes.rb — the engine ships no auth of its own. An unwrapped mount exposes the dashboard to anyone. 3. Set your provider credentials (the defaults read OpenRouter from ENV): OPENROUTER_API_KEY=sk-... (and OPENROUTER_MODEL to pick a model) 4. Let extensions register in development by loading them eagerly — add to config/environments/development.rb: config.eager_load = true (tools/providers/hooks are discovered as loaded subclasses). 5. Create your first persona + email domain (dashboard, or a db/seeds.rb bootstrap) so inbound mail has somewhere to route. Then boot and open /protege. STEPS end |