Class: Phlex::Reactive::Generators::ClaudeGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/phlex/reactive/claude/claude_generator.rb

Overview

rails g phlex:reactive:claude

Installs the phlex-reactive debugging toolkit for Claude Code inside a host app (issue #168):

* copies the shipped `phlex-reactive-debugging` skill into
.claude/skills/ (the debugging runbook: doctor → inventory → find →
browser scan → MCP)
* adds the read-only MCP server to .claude/../.mcp.json — but ONLY when
the file is absent (never rewrite an existing .mcp.json); otherwise it
prints the snippet to add by hand.

The skill ships INSIDE the gem (under lib/, so the gemspec packages it), not as a template, so it always matches the installed gem version.

Constant Summary collapse

SKILL_NAME =
"phlex-reactive-debugging"
MCP_ENTRY =

The MCP server entry a host app adds to .mcp.json. Introspection needs the booted app, so the command is the rake task (not a standalone exe).

{
  "mcpServers" => {
    "phlex-reactive" => {
      "command" => "bin/rails",
      "args" => ["phlex_reactive:mcp"]
    }
  }
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.skill_source_dirObject

The shipped skill directory inside the gem (packaged under lib/).



42
43
44
# File 'lib/generators/phlex/reactive/claude/claude_generator.rb', line 42

def self.skill_source_dir
  File.expand_path("../../../../phlex/reactive/claude/skills/#{SKILL_NAME}", __dir__)
end

Instance Method Details

#configure_mcpObject

Create .mcp.json with the server entry when it's absent; otherwise print the snippet (NEVER rewrite an existing .mcp.json — it may hold other servers the app configured).



56
57
58
59
60
61
62
63
64
# File 'lib/generators/phlex/reactive/claude/claude_generator.rb', line 56

def configure_mcp
  path = ".mcp.json"
  if File.exist?(File.join(destination_root, path))
    say_status :skip, "#{path} exists — add the phlex-reactive server yourself:", :yellow
    say(pretty_entry)
  else
    create_file path, "#{pretty_entry}\n"
  end
end

#install_skillObject

Copy the shipped skill into the host app's .claude/skills/.



47
48
49
50
51
# File 'lib/generators/phlex/reactive/claude/claude_generator.rb', line 47

def install_skill
  source = self.class.skill_source_dir
  dest = File.join(".claude", "skills", SKILL_NAME)
  directory(source, dest)
end

#show_post_installObject



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/generators/phlex/reactive/claude/claude_generator.rb', line 66

def show_post_install
  say_status :info, "phlex-reactive debugging toolkit installed for Claude Code.", :green
  say <<~MSG

    The `#{SKILL_NAME}` skill teaches the debugging workflow (doctor →
    inventory → find → browser report() → MCP). The MCP server needs the
    optional `mcp` gem — add `gem "mcp"` to your Gemfile to enable it.

    Try it:  bin/rails phlex_reactive:doctor
  MSG
end