This guide will walk you through installing and setting up CodeHealer in your Ruby on Rails application.
Before installing CodeHealer, ensure you have:
- Ruby 2.7.0 or higher
- Rails 6.0.0 or higher
- Git repository initialized
- GitHub account (for pull request creation)
- OpenAI API key (for API-based evolution)
- Claude Code terminal (for local evolution)
Add the gem to your Gemfile:
# Gemfile
source 'https://rubygems.org'
# ... other gems ...
# CodeHealer - AI-powered code healing and self-repair system
gem 'code_healer'
# Required dependencies (if not already present)
gem 'sidekiq', '>= 6.0.0'
gem 'redis', '>= 4.0.0'Run bundle install:
bundle installCopy the example configuration file:
cp config/code_healer.yml.example config/code_healer.ymlEdit config/code_healer.yml with your settings:
---
enabled: true
# Classes that are allowed to evolve
allowed_classes:
- User
- Order
- PaymentProcessor
# Evolution strategy
evolution_strategy:
method: "api" # or "claude_code_terminal" or "hybrid"
# API configuration
api:
provider: "openai"
model: "gpt-4"
api_key: <%= ENV['OPENAI_API_KEY'] %>
# Business context
business_context:
enabled: true
User:
domain: "User Management"
key_rules:
- "Email must be unique and valid"Create or update your .env file:
# .env
OPENAI_API_KEY=your_openai_api_key_here
GITHUB_TOKEN=your_github_token_hereImportant: Never commit API keys to version control!
Create config/sidekiq.yml:
:concurrency: 5
:queues:
- [evolution, 2]
- [default, 1]Add to config/routes.rb:
# config/routes.rb
require 'sidekiq/web'
Rails.application.routes.draw do
# ... other routes ...
# Sidekiq Web UI (optional, for monitoring)
mount Sidekiq::Web => '/sidekiq'
endEnsure Redis is running:
# macOS with Homebrew
brew services start redis
# Ubuntu/Debian
sudo systemctl start redis
# Or run manually
redis-serverCreate a business_requirements/ directory in your project root:
mkdir business_requirementsAdd markdown files with your business rules:
# business_requirements/user_management.md
# User Management Business Rules
## Authentication
- Users must have valid email addresses
- Passwords must be at least 8 characters
- Failed login attempts should be logged
## Data Validation
- All user input must be sanitized
- Email uniqueness is enforced at database level# app/models/user.rb
class User < ApplicationRecord
def calculate_discount(amount, percentage)
# This will trigger evolution if an error occurs
amount * (percentage / 100.0)
end
endStart your Rails server and trigger an error:
rails serverIn another terminal, trigger an error:
curl -X POST http://localhost:3000/api/users/calculate_discount \
-H "Content-Type: application/json" \
-d '{"amount": 100, "percentage": nil}'Check the logs to see CodeHealer in action:
tail -f log/development.logVerify CodeHealer is properly installed:
# In Rails console
rails console
# Check if CodeHealer is loaded
CodeHealer::VERSION
# Should return the version number
# Check configuration
CodeHealer::ConfigManager.config
# Should return your configuration hashVerify Sidekiq is working:
# Start Sidekiq
bundle exec sidekiq
# Check Sidekiq Web UI
open http://localhost:3000/sidekiqVerify business context is loading:
# In Rails console
CodeHealer::BusinessContextManager.get_context_for_error(
ArgumentError.new("test"),
"User",
"calculate_discount"
)| Setting | Description | Default | Required |
|---|---|---|---|
enabled |
Enable/disable CodeHealer | true |
Yes |
allowed_classes |
Classes that can evolve | [] |
Yes |
excluded_classes |
Classes that should never evolve | [] |
No |
allowed_error_types |
Error types that trigger evolution | [] |
No |
| Strategy | Description | Use Case |
|---|---|---|
api |
Use OpenAI API for fixes | Production, cloud-based |
claude_code_terminal |
Use local Claude Code agent | Development, offline |
hybrid |
Try Claude Code first, fallback to API | Best of both worlds |
business_context:
enabled: true
User:
domain: "User Management"
key_rules:
- "Email must be unique and valid"
validation_patterns:
- "Input validation for all parameters"git:
auto_commit: true
auto_push: true
branch_prefix: evolve
pr_target_branch: main
pull_request:
enabled: true
auto_create: true
labels: ["auto-fix", "self-evolving"]Store sensitive data in environment variables:
# config/self_evolution.yml
api:
provider: "openai"
api_key: <%= ENV['OPENAI_API_KEY'] %>
model: "gpt-4"Carefully configure which classes can evolve:
allowed_classes:
- User
- Order
- PaymentProcessor
excluded_classes:
- ApplicationController
- ApplicationRecord
- ApplicationJob
- ApplicationMailerEnable business rule validation:
business_context:
enabled: true
validate_rules: true
strict_mode: trueDisable evolution in test environment:
# config/environments/test.rb
Rails.application.configure do
# ... other config ...
# Disable CodeHealer in tests
config.self_evolving = {
enabled: false,
mock_ai_responses: true,
dry_run: true
}
endUse mock responses for testing:
# config/self_evolution.yml
test:
enabled: false
mock_ai_responses: true
mock_response: "def calculate_discount(amount, percentage)\n return 0 if amount.nil? || percentage.nil?\n amount * (percentage / 100.0)\nend"-
Gem not found
bundle install bundle exec rails console -
Configuration not loading
- Check file path:
config/self_evolution.yml - Verify YAML syntax
- Check file permissions
- Check file path:
-
Sidekiq not working
# Check Redis redis-cli ping # Check Sidekiq bundle exec sidekiq -V
-
Business context not loading
- Verify
business_requirements/directory exists - Check markdown file syntax
- Verify file permissions
- Verify
Enable debug logging:
# config/self_evolution.yml
logging:
level: debug
show_thinking_process: true
verbose: trueCheck relevant log files:
# Rails logs
tail -f log/development.log
# Sidekiq logs
tail -f log/sidekiq.log
# Redis logs
tail -f /var/log/redis/redis-server.logAfter successful installation:
- Read the README for comprehensive usage information
- Check Configuration for advanced options
- Review Examples for practical use cases
- Join Discussions for community support
- 📧 Email: deepan@example.com
- 🐛 Issues: GitHub Issues
- 💬 Discussions: GitHub Discussions
- 📖 Wiki: GitHub Wiki
Happy Evolving! 🚀