Class: EnhanceSwarm::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/enhance_swarm/generator.rb

Instance Method Summary collapse

Constructor Details

#initializeGenerator



9
10
11
12
# File 'lib/enhance_swarm/generator.rb', line 9

def initialize
  @config = EnhanceSwarm.configuration
  @template_dir = File.expand_path('../../templates', __dir__)
end

Instance Method Details

#generate_claude_filesObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/enhance_swarm/generator.rb', line 24

def generate_claude_files
  claude_dir = File.join(EnhanceSwarm.root, '.claude')
  FileUtils.mkdir_p(claude_dir)

  # Generate main Claude files
  %w[CLAUDE.md RULES.md MCP.md PERSONAS.md].each do |file|
    generate_from_template(
      "claude/#{file}",
      File.join(claude_dir, file)
    )
  end

  puts '✅ Generated Claude configuration files in .claude/'
end

#generate_git_hooksObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/enhance_swarm/generator.rb', line 66

def generate_git_hooks
  hooks_dir = File.join(EnhanceSwarm.root, '.git', 'hooks')
  FileUtils.mkdir_p(hooks_dir)

  # Pre-commit hook with sanitized command
  safe_test_command = sanitize_shell_command(@config.test_command)
  pre_commit = "    #!/bin/bash\n    # EnhanceSwarm pre-commit hook\n\n    # Run tests before committing\n    echo \"Running tests...\"\n    \#{safe_test_command}\n\n    if [ $? -ne 0 ]; then\n      echo \"\u274C Tests failed! Please fix before committing.\"\n      exit 1\n    fi\n\n    echo \"\u2705 All tests passed!\"\n  HOOK\n\n  hook_path = File.join(hooks_dir, 'pre-commit')\n  File.write(hook_path, pre_commit)\n  File.chmod(0o755, hook_path)\n\n  puts '\u2705 Generated Git hooks'\nend\n"

#generate_mcp_configObject



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
# File 'lib/enhance_swarm/generator.rb', line 39

def generate_mcp_config
  mcp_dir = File.join(EnhanceSwarm.root, '.mcp')
  FileUtils.mkdir_p(mcp_dir)

  # Generate MCP configuration
  config = {
    'tools' => {
      'gemini' => {
        'enabled' => @config.gemini_enabled,
        'command' => 'gemini',
        'description' => 'Large context analysis with Gemini CLI'
      },
      'desktop_commander' => {
        'enabled' => @config.desktop_commander_enabled,
        'description' => 'File operations outside project directory'
      }
    }
  }

  File.write(
    File.join(mcp_dir, 'config.json'),
    JSON.pretty_generate(config)
  )

  puts '✅ Generated MCP configuration'
end

#init_projectObject



14
15
16
17
18
19
20
21
22
# File 'lib/enhance_swarm/generator.rb', line 14

def init_project
  create_directories
  create_config_file
  generate_claude_files
  generate_git_hooks
  setup_task_management

  puts '✅ Project initialized with EnhanceSwarm'
end

#setup_task_managementObject



95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/enhance_swarm/generator.rb', line 95

def setup_task_management
  # Check if swarm-tasks is available

  CommandExecutor.execute('gem', 'list', 'swarm_tasks', '-i')
  puts '✅ swarm_tasks gem detected'
rescue CommandExecutor::CommandError
  # Create basic task directories
  %w[backlog active completed].each do |state|
    FileUtils.mkdir_p(File.join(EnhanceSwarm.root, 'tasks', state))
  end

  puts '⚠️  swarm_tasks gem not found. Created basic task directories.'
  puts '   Install with: gem install swarm_tasks'
end