Class: RailsInformant::SkillGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- RailsInformant::SkillGenerator
- Defined in:
- lib/generators/rails_informant/skill_generator.rb
Instance Method Summary collapse
- #copy_hook_script ⇒ Object
- #copy_skill_file ⇒ Object
- #create_or_update_mcp_json ⇒ Object
- #create_or_update_settings_json ⇒ Object
- #print_next_steps ⇒ Object
Instance Method Details
#copy_hook_script ⇒ Object
12 13 14 15 |
# File 'lib/generators/rails_informant/skill_generator.rb', line 12 def copy_hook_script copy_file "informant-alerts.sh", ".claude/hooks/informant-alerts.sh" chmod ".claude/hooks/informant-alerts.sh", 0o755 end |
#copy_skill_file ⇒ Object
8 9 10 |
# File 'lib/generators/rails_informant/skill_generator.rb', line 8 def copy_skill_file copy_file "SKILL.md", ".claude/skills/informant/SKILL.md" end |
#create_or_update_mcp_json ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/generators/rails_informant/skill_generator.rb', line 17 def create_or_update_mcp_json mcp_path = File.join(destination_root, ".mcp.json") informant_entry = { "command" => "informant-mcp" } if File.exist?(mcp_path) existing = JSON.parse(File.read(mcp_path)) existing["mcpServers"] ||= {} existing["mcpServers"]["informant"] = informant_entry create_file ".mcp.json", JSON.pretty_generate(existing) + "\n", force: true else create_file ".mcp.json", JSON.pretty_generate( "mcpServers" => { "informant" => informant_entry } ) + "\n" end rescue JSON::ParserError say "Could not parse existing .mcp.json — skipping merge. Add the informant server manually.", :red end |
#create_or_update_settings_json ⇒ Object
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 |
# File 'lib/generators/rails_informant/skill_generator.rb', line 35 def create_or_update_settings_json settings_path = File.join(destination_root, ".claude", "settings.json") hook_command = ".claude/hooks/informant-alerts.sh" if File.exist?(settings_path) existing = JSON.parse(File.read(settings_path)) existing["hooks"] ||= {} existing["hooks"]["SessionStart"] ||= [] already_registered = existing["hooks"]["SessionStart"].any? do |entry| entry["hooks"]&.any? { it["command"] == hook_command } end unless already_registered existing["hooks"]["SessionStart"] << session_start_hook(hook_command) end create_file ".claude/settings.json", JSON.pretty_generate(existing) + "\n", force: true else create_file ".claude/settings.json", JSON.pretty_generate( "hooks" => { "SessionStart" => [ session_start_hook(hook_command) ] } ) + "\n" end rescue JSON::ParserError say "Could not parse existing .claude/settings.json — skipping hook setup.", :red end |
#print_next_steps ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/generators/rails_informant/skill_generator.rb', line 62 def print_next_steps say "" say "Claude Code integration installed!", :green say "" say " Created .mcp.json" say " Created .claude/skills/informant/SKILL.md" say " Created .claude/hooks/informant-alerts.sh" say " Created .claude/settings.json (SessionStart hook)" say "" say "Next step — set env vars so the MCP server and startup alerts can reach your app.", :yellow say "Add to your .envrc (or export manually):" say "" say " export INFORMANT_PRODUCTION_URL=https://your-app.com" say " export INFORMANT_PRODUCTION_TOKEN=<same token from credentials>" say "" say "The token must match rails_informant.api_token in your Rails credentials." say "Add .envrc to .gitignore — it contains secrets." say "" say "Optional: install jq for startup error alerts (brew install jq)", :cyan end |