
Security News
Risky Biz Podcast: Making Reachability Analysis Work in Real-World Codebases
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
AI-Powered Code Healing and Self-Repair System for Ruby Applications
CodeHealer automatically detects runtime errors in your Ruby/Rails application and uses AI to generate intelligent, context-aware fixes. It's like having a senior developer on call 24/7 to fix your bugs!
CodeHealer requires the following gems:
The easiest way to get started is using our interactive bash script that guides you through the entire setup process:
# Install the gem
gem install code_healer
# Run the interactive setup in your Rails app directory
code_healer-setup
The interactive setup script will:
If you prefer manual setup:
# Add to your Gemfile
gem 'code_healer'
# Install dependencies
bundle install
CodeHealer requires several environment variables to function properly:
# Required for AI-powered code generation
OPENAI_API_KEY=your_openai_api_key_here
# Required for GitHub integration (PR creation, etc.)
GITHUB_TOKEN=your_github_personal_access_token
GITHUB_REPOSITORY=username/repository_name
# Optional: Redis URL for Sidekiq
REDIS_URL=redis://localhost:6379/0
Loading Environment Variables:
You have several options for loading these variables:
Using dotenv-rails (Recommended):
# In your Gemfile
gem 'dotenv-rails'
Manual export in shell:
export OPENAI_API_KEY=your_key
export GITHUB_TOKEN=your_token
export GITHUB_REPOSITORY=username/repo
Load directly in application.rb:
# In config/application.rb
load '.env' if File.exist?('.env')
The setup script automatically creates config/code_healer.yml
, or you can create it manually. Here's a comprehensive overview of all available configuration options:
---
# CodeHealer Configuration
enabled: true # Master switch to enable/disable the entire system
# π― Class Control
allowed_classes:
- User # Classes that are allowed to evolve
- Order # Add your model classes here
- PaymentProcessor
- Api::UserController # Controllers are also supported
excluded_classes:
- ApplicationController # Classes that should NEVER evolve
- ApplicationRecord # Core Rails classes
- ApplicationJob
- ApplicationMailer
# π¨ Error Type Filtering
allowed_error_types:
- ArgumentError # Invalid arguments passed to methods
- NameError # Undefined variables or methods
- NoMethodError # Method doesn't exist on object
- TypeError # Wrong type of object
- ValidationError # Custom validation errors
# π€ Evolution Strategy
evolution_strategy:
method: "api" # Options: "api", "claude_code_terminal", "hybrid"
fallback_to_api: true # If Claude Code fails, fall back to API
# π§ Claude Code Terminal (Local AI Agent)
claude_code:
enabled: true # Enable Claude Code integration
timeout: 300 # 5 minutes timeout for AI responses
max_file_changes: 10 # Maximum files Claude can modify
include_tests: true # Include test files in analysis
command_template: "claude --print '{prompt}' --output-format text --permission-mode acceptEdits --allowedTools Edit"
business_context_sources: # Sources for business context
- "config/business_rules.yml"
- "docs/business_logic.md"
- "spec/business_context_specs.rb"
# πΌ Business Context & Domain Knowledge
business_context:
enabled: true # Enable business context integration
User: # Class-specific business rules
domain: "User Management"
key_rules:
- "Email must be unique and valid"
- "Password must meet security requirements"
- "User data must be validated"
validation_patterns:
- "Email format validation"
- "Password strength requirements"
- "Data integrity checks"
Order: # Another class example
domain: "E-commerce Order Processing"
key_rules:
- "Orders must have valid customer information"
- "Payment validation is required"
- "Inventory must be checked before processing"
# π OpenAI API Configuration
api:
provider: "openai" # AI provider (currently OpenAI)
model: "gpt-4" # AI model to use
max_tokens: 2000 # Maximum tokens in response
temperature: 0.1 # Creativity vs. consistency (0.0 = deterministic, 1.0 = creative)
# π Git Operations
git:
auto_commit: true # Automatically commit fixes
auto_push: true # Push to remote repository
branch_prefix: "evolve" # Branch naming: evolve/classname-methodname-timestamp
commit_message_template: 'Fix {class_name}##{method_name}: {error_type}'
pr_target_branch: "main" # Target branch for pull requests
# π Pull Request Configuration
pull_request:
enabled: true # Enable automatic PR creation
auto_create: true # Create PRs automatically
title_template: 'Fix {class_name}##{method_name}: Handle {error_type}'
labels: # Labels to add to PRs
- "auto-fix"
- "self-evolving"
- "bug-fix"
# β‘ Sidekiq Background Processing
sidekiq:
queue: "evolution" # Queue name for healing jobs
retry: 3 # Number of retry attempts
backtrace: true # Include backtraces in job data
Create a .env
file in your Rails app root:
# OpenAI Configuration
OPENAI_API_KEY=your_openai_api_key_here
# GitHub Configuration
GITHUB_TOKEN=your_github_token_here
GITHUB_REPOSITORY=username/repo
# Optional: Redis Configuration
REDIS_URL=redis://localhost:6379/0
Once configured, CodeHealer works automatically! Just run your Rails app:
# Start your Rails server
rails s
# Start Sidekiq for background processing
bundle exec sidekiq
Create a model with intentional errors to test:
# app/models/broken_calculator.rb
class BrokenCalculator < ApplicationRecord
def divide(a, b)
a / b # This will cause ZeroDivisionError when b = 0
end
end
When you hit an endpoint that triggers this error, CodeHealer will:
Check your Sidekiq dashboard at http://localhost:3000/sidekiq
to see healing jobs in action.
CodeHealer is actively developed with a focus on real-world developer workflows. Here's what's coming:
π‘ Have ideas for tool integrations? We'd love to hear from you!
π The future of development is context-aware, and CodeHealer is making it automatic!
The code_healer-setup
script provides an interactive, guided setup experience:
$ code_healer-setup
π₯ Welcome to CodeHealer Setup!
================================
This interactive setup will configure CodeHealer for your Rails application.
π What we'll set up:
- OpenAI API configuration
- GitHub integration
- Business context rules
- Git operations
- Healing strategies
- Sidekiq configuration
π Step 1: OpenAI Configuration
Enter your OpenAI API key: ****************
β
OpenAI API key configured successfully!
π Step 2: GitHub Integration
Enter your GitHub personal access token: ****************
Enter your GitHub repository (username/repo): deepan-g2/myapp
β
GitHub integration configured successfully!
πΌ Step 3: Business Context
Would you like to set up business context rules? (y/n): y
Enter business domain for User class: User Management
Enter key business rules (comma-separated): Email validation, Password security, Data integrity
β
Business context configured successfully!
βοΈ Step 4: Healing Strategy
Choose evolution method:
1. API (OpenAI) - Cloud-based, reliable
2. Claude Code Terminal - Local AI agent, full codebase access
3. Hybrid - Best of both worlds
Enter choice (1-3): 2
β
Claude Code Terminal strategy selected!
π Step 5: Git Configuration
Enter branch prefix for fixes: evolve
Enter target branch for PRs: main
β
Git configuration completed!
π Setup complete! CodeHealer is now configured for your application.
CodeHealer can read business context from Markdown (.md) files to provide domain-specific knowledge for better AI fixes. These files help the AI understand your business rules, validation patterns, and domain logic.
Create markdown files in your project to define business rules:
docs/business_rules.md
- General business rules:
# Business Rules & Standards
## Error Handling Principles
- All errors should be logged for audit purposes
- User-facing errors should be user-friendly and actionable
- Critical errors should trigger immediate alerts
- Security errors should never expose sensitive information
## Data Validation Standards
- All user inputs must be validated before processing
- Business rules must be enforced at the model level
- Invalid data should be rejected with clear, helpful error messages
- Data integrity must be maintained across all operations
## Security Guidelines
- Never log sensitive information (passwords, tokens, PII)
- Input sanitization is mandatory for all user-provided data
- Rate limiting should be applied to prevent abuse
- Authentication must be verified for all protected operations
docs/user_management.md
- Domain-specific rules:
# User Management Domain
## User Registration
- Email addresses must be unique across the system
- Password strength: minimum 8 characters, mixed case, numbers
- Email verification is required before account activation
- Username must be alphanumeric, 3-20 characters
## User Authentication
- Failed login attempts are limited to 5 per hour
- Password reset tokens expire after 1 hour
- Session timeout after 24 hours of inactivity
- Multi-factor authentication for admin accounts
## Data Privacy
- User data is encrypted at rest
- GDPR compliance for EU users
- Right to data deletion must be honored
- Audit trail for all data modifications
docs/order_processing.md
- Another domain example:
# Order Processing Domain
## Order Validation
- Customer information must be complete and verified
- Payment method must be valid and authorized
- Inventory must be available before order confirmation
- Shipping address must be deliverable
## Business Rules
- Orders cannot be cancelled after shipping
- Refunds processed within 30 days
- Bulk orders get 10% discount
- Free shipping for orders over $50
## Error Handling
- Insufficient inventory: suggest alternatives
- Payment failure: retry up to 3 times
- Invalid address: prompt for correction
- System errors: queue for manual review
Update your config/code_healer.yml
to include these files:
business_context:
enabled: true
# Sources for business context (markdown files)
sources:
- "docs/business_rules.md"
- "docs/user_management.md"
- "docs/order_processing.md"
- "README.md" # Project documentation
- "docs/API.md" # API documentation
claude_code:
business_context_sources:
- "docs/business_rules.md"
- "docs/user_management.md"
- "docs/order_processing.md"
- "config/business_rules.yml" # YAML format also supported
#
, ##
, ###
) for structureWhen CodeHealer encounters an error, it:
evolution_strategy:
method: "api"
fallback_to_api: false # No fallback needed
api:
provider: "openai"
model: "gpt-4"
max_tokens: 3000 # Increase for complex fixes
temperature: 0.05 # More deterministic
evolution_strategy:
method: "claude_code_terminal"
fallback_to_api: true # Fallback if Claude fails
claude_code:
enabled: true
timeout: 600 # 10 minutes for complex fixes
max_file_changes: 15 # Allow more file modifications
include_tests: true # Include test files in analysis
evolution_strategy:
method: "hybrid"
fallback_to_api: true
# Claude Code for local development
claude_code:
enabled: true
timeout: 300
# OpenAI API for production/fallback
api:
provider: "openai"
model: "gpt-4"
max_tokens: 2000
git clone https://github.com/deepan-g2/code-healer.git
cd code-healer
bundle install
gem build code_healer.gemspec
bundle exec rspec
ApplicationController
, ApplicationRecord
, etc.repo
, workflow
)# Ensure backtrace is enabled in Sidekiq config
sidekiq:
backtrace: true
# Verify GitHub token has correct permissions
# Check target branch exists
git:
pr_target_branch: "main" # Must exist in remote
# Increase timeout and verify command template
claude_code:
timeout: 600
command_template: "claude --print '{prompt}' --output-format text"
# Ensure markdown files exist and are readable
business_context:
enabled: true
# Check file paths are correct
git checkout -b feature/amazing-feature
)git commit -m 'Add amazing feature'
)git push origin feature/amazing-feature
)This project is licensed under the MIT License - see the LICENSE.txt file for details.
CodeHealer - Because your code deserves to heal itself! π₯β¨
Built with β€οΈ by Deepan Kumar
FAQs
Unknown package
We found that code_healer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Β It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socketβs AI scanner detected the supply chain attack and flagged the malware.
Security News
CISAβs 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.