code_healer 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +70 -0
- data/GEM_SUMMARY.md +307 -0
- data/README.md +281 -0
- data/code_healer.gemspec +77 -0
- data/config/code_healer.yml.example +104 -0
- data/docs/INSTALLATION.md +439 -0
- data/examples/basic_usage.rb +160 -0
- data/exe/code_healer-setup +7 -0
- data/lib/code_healer/application_job.rb +7 -0
- data/lib/code_healer/business_context_analyzer.rb +464 -0
- data/lib/code_healer/business_context_loader.rb +273 -0
- data/lib/code_healer/business_context_manager.rb +297 -0
- data/lib/code_healer/business_logic_generator.rb +94 -0
- data/lib/code_healer/business_rule_applier.rb +54 -0
- data/lib/code_healer/claude_code_evolution_handler.rb +224 -0
- data/lib/code_healer/claude_error_monitor.rb +48 -0
- data/lib/code_healer/config_manager.rb +275 -0
- data/lib/code_healer/context_aware_prompt_builder.rb +153 -0
- data/lib/code_healer/core.rb +513 -0
- data/lib/code_healer/error_handler.rb +141 -0
- data/lib/code_healer/evolution_job.rb +99 -0
- data/lib/code_healer/global_handler.rb +130 -0
- data/lib/code_healer/healing_job.rb +167 -0
- data/lib/code_healer/mcp.rb +108 -0
- data/lib/code_healer/mcp_prompts.rb +111 -0
- data/lib/code_healer/mcp_server.rb +389 -0
- data/lib/code_healer/mcp_tools.rb +2364 -0
- data/lib/code_healer/pull_request_creator.rb +143 -0
- data/lib/code_healer/setup.rb +390 -0
- data/lib/code_healer/simple_evolution.rb +737 -0
- data/lib/code_healer/simple_global_handler.rb +122 -0
- data/lib/code_healer/simple_healer.rb +515 -0
- data/lib/code_healer/terminal_integration.rb +87 -0
- data/lib/code_healer/usage_analyzer.rb +92 -0
- data/lib/code_healer/version.rb +5 -0
- data/lib/code_healer.rb +67 -0
- metadata +411 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ea19c38b242524da0c2be758ff00108c1cbc277c976b818539487bb6279d33af
|
4
|
+
data.tar.gz: a93de9e58f4cae2a75f074515a3ffe3fc9973d64d05961e32b6ed34193090fd9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c7e457626092026ee1511022848c068a828fdab577e55ee3f2e3096c3b41191a7c97ad27b01c291a0485a3cd2d8d7e85e1649953efa4380e71800c2edde1f91e
|
7
|
+
data.tar.gz: e5edefe5097f704dee5969d86135a22ed19b35c1391c385fc2fd849559ca689a4390eba45b6f6a084861cd5395c525b22d47ef365de2443f701bfe0a4cbb7608
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
|
+
|
8
|
+
## [Unreleased]
|
9
|
+
|
10
|
+
### Added
|
11
|
+
- Initial gem release
|
12
|
+
- AI-powered error analysis and code generation
|
13
|
+
- Multiple healing strategies (API, Claude Code, Hybrid)
|
14
|
+
- Business context awareness and integration
|
15
|
+
- Automated Git operations and PR creation
|
16
|
+
- Background job processing with Sidekiq
|
17
|
+
- Comprehensive YAML configuration
|
18
|
+
- Business requirements integration from markdown files
|
19
|
+
- Rails integration via Railtie
|
20
|
+
|
21
|
+
### Changed
|
22
|
+
- Converted from standalone Rails application to gem
|
23
|
+
- Refactored for modular architecture
|
24
|
+
- Improved error handling and logging
|
25
|
+
- Renamed from CodeHealer to CodeHealer
|
26
|
+
|
27
|
+
### Deprecated
|
28
|
+
- None
|
29
|
+
|
30
|
+
### Removed
|
31
|
+
- None
|
32
|
+
|
33
|
+
### Fixed
|
34
|
+
- Business context loading from markdown files
|
35
|
+
- Template placeholder substitution in PR creation
|
36
|
+
- Sidekiq job serialization issues
|
37
|
+
|
38
|
+
### Security
|
39
|
+
- Class restriction system for security
|
40
|
+
- Environment variable support for sensitive data
|
41
|
+
- Business rule validation
|
42
|
+
|
43
|
+
## [0.1.0] - 2025-01-13
|
44
|
+
|
45
|
+
### Added
|
46
|
+
- Initial release of CodeHealer gem
|
47
|
+
- Core healing engine
|
48
|
+
- OpenAI API integration
|
49
|
+
- Claude Code terminal integration
|
50
|
+
- Business context management
|
51
|
+
- Git operations automation
|
52
|
+
- Sidekiq background processing
|
53
|
+
- Comprehensive documentation
|
54
|
+
- Example configurations
|
55
|
+
- Test suite setup
|
56
|
+
|
57
|
+
---
|
58
|
+
|
59
|
+
## Version History
|
60
|
+
|
61
|
+
- **0.1.0**: Initial gem release with core functionality
|
62
|
+
- **Unreleased**: Future improvements and features
|
63
|
+
|
64
|
+
## Contributing
|
65
|
+
|
66
|
+
Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct and the process for submitting pull requests.
|
67
|
+
|
68
|
+
## License
|
69
|
+
|
70
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE.txt) file for details.
|
data/GEM_SUMMARY.md
ADDED
@@ -0,0 +1,307 @@
|
|
1
|
+
# CodeHealer Gem - Complete Package 🏥
|
2
|
+
|
3
|
+
## 📦 What You Get
|
4
|
+
|
5
|
+
This gem package contains everything needed to integrate AI-powered code healing and self-repair into any Ruby application.
|
6
|
+
|
7
|
+
## 🏗️ Gem Structure
|
8
|
+
|
9
|
+
```
|
10
|
+
code_healer_gem/
|
11
|
+
├── lib/
|
12
|
+
│ ├── code_healer.rb # Main gem file with Railtie
|
13
|
+
│ ├── code_healer/
|
14
|
+
│ │ ├── version.rb # Gem version
|
15
|
+
│ │ ├── config_manager.rb # Configuration management
|
16
|
+
│ │ ├── core.rb # Core healing engine
|
17
|
+
│ │ ├── simple_healer.rb # Basic healing logic
|
18
|
+
│ │ ├── claude_code_healing_handler.rb # Claude Code integration
|
19
|
+
│ │ ├── business_context_manager.rb # Business rules management
|
20
|
+
│ │ ├── mcp_server.rb # MCP server for AI integration
|
21
|
+
│ │ ├── mcp_tools.rb # MCP tools and utilities
|
22
|
+
│ │ ├── mcp_prompts.rb # AI prompt templates
|
23
|
+
│ │ ├── pull_request_creator.rb # Git operations automation
|
24
|
+
│ │ ├── error_handler.rb # Error handling utilities
|
25
|
+
│ │ ├── usage_analyzer.rb # Usage analytics
|
26
|
+
│ │ └── healing_job.rb # Sidekiq background job
|
27
|
+
├── config/
|
28
|
+
│ └── code_healer.yml.example # Example configuration
|
29
|
+
├── examples/
|
30
|
+
│ └── basic_usage.rb # Basic usage example
|
31
|
+
├── docs/
|
32
|
+
│ └── INSTALLATION.md # Detailed installation guide
|
33
|
+
├── spec/ # Test suite
|
34
|
+
├── code_healer.gemspec # Gem specification
|
35
|
+
├── Gemfile # Development dependencies
|
36
|
+
├── Rakefile # Build and development tasks
|
37
|
+
├── README.md # Comprehensive documentation
|
38
|
+
├── CHANGELOG.md # Version history
|
39
|
+
└── LICENSE.txt # MIT license
|
40
|
+
```
|
41
|
+
|
42
|
+
## 🚀 Quick Start for Users
|
43
|
+
|
44
|
+
### 1. Add to Gemfile
|
45
|
+
```ruby
|
46
|
+
gem 'self_evolving'
|
47
|
+
```
|
48
|
+
|
49
|
+
### 2. Install
|
50
|
+
```bash
|
51
|
+
bundle install
|
52
|
+
```
|
53
|
+
|
54
|
+
### 3. Configure
|
55
|
+
```bash
|
56
|
+
cp config/self_evolution.yml.example config/self_evolution.yml
|
57
|
+
# Edit the configuration file
|
58
|
+
```
|
59
|
+
|
60
|
+
### 4. Use
|
61
|
+
```ruby
|
62
|
+
# Your models will automatically evolve when errors occur
|
63
|
+
class User < ApplicationRecord
|
64
|
+
def calculate_discount(amount, percentage)
|
65
|
+
amount * (percentage / 100.0) # Will auto-fix if error occurs
|
66
|
+
end
|
67
|
+
end
|
68
|
+
```
|
69
|
+
|
70
|
+
## 🔧 Key Features
|
71
|
+
|
72
|
+
### 🤖 **Multiple AI Integration Options**
|
73
|
+
- **OpenAI API**: Cloud-based, production-ready
|
74
|
+
- **Claude Code Terminal**: Local, offline, full codebase access
|
75
|
+
- **Hybrid**: Best of both worlds with fallback
|
76
|
+
|
77
|
+
### 🎯 **Business Context Awareness**
|
78
|
+
- YAML configuration for business rules
|
79
|
+
- Markdown file integration for requirements
|
80
|
+
- Domain-specific validation patterns
|
81
|
+
|
82
|
+
### 🔄 **Automated Evolution**
|
83
|
+
- Error detection and analysis
|
84
|
+
- AI-powered fix generation
|
85
|
+
- Automatic code application
|
86
|
+
- Class reloading for immediate testing
|
87
|
+
|
88
|
+
### 📝 **Git Operations Automation**
|
89
|
+
- Feature branch creation
|
90
|
+
- Automatic commits with descriptive messages
|
91
|
+
- Pull request creation
|
92
|
+
- Configurable target branches
|
93
|
+
|
94
|
+
### ⚡ **Background Processing**
|
95
|
+
- Sidekiq integration for non-blocking evolution
|
96
|
+
- Queue management and retry logic
|
97
|
+
- Evolution job monitoring
|
98
|
+
|
99
|
+
## 📋 Configuration Options
|
100
|
+
|
101
|
+
### Core Settings
|
102
|
+
```yaml
|
103
|
+
enabled: true
|
104
|
+
allowed_classes: [User, Order, PaymentProcessor]
|
105
|
+
excluded_classes: [ApplicationController, ApplicationRecord]
|
106
|
+
allowed_error_types: [ArgumentError, TypeError, NoMethodError]
|
107
|
+
```
|
108
|
+
|
109
|
+
### Evolution Strategy
|
110
|
+
```yaml
|
111
|
+
evolution_strategy:
|
112
|
+
method: "api" # or "claude_code_terminal" or "hybrid"
|
113
|
+
fallback_to_api: true
|
114
|
+
```
|
115
|
+
|
116
|
+
### Business Context
|
117
|
+
```yaml
|
118
|
+
business_context:
|
119
|
+
enabled: true
|
120
|
+
User:
|
121
|
+
domain: "User Management"
|
122
|
+
key_rules:
|
123
|
+
- "Email must be unique and valid"
|
124
|
+
validation_patterns:
|
125
|
+
- "Input validation for all parameters"
|
126
|
+
```
|
127
|
+
|
128
|
+
### Git Operations
|
129
|
+
```yaml
|
130
|
+
git:
|
131
|
+
auto_commit: true
|
132
|
+
auto_push: true
|
133
|
+
branch_prefix: evolve
|
134
|
+
pr_target_branch: main
|
135
|
+
|
136
|
+
pull_request:
|
137
|
+
enabled: true
|
138
|
+
auto_create: true
|
139
|
+
labels: ["auto-fix", "self-evolving"]
|
140
|
+
```
|
141
|
+
|
142
|
+
## 🎨 Customization
|
143
|
+
|
144
|
+
### Custom Error Handlers
|
145
|
+
```ruby
|
146
|
+
# config/initializers/self_evolution.rb
|
147
|
+
Rails.application.config.after_initialize do
|
148
|
+
CodeHealer::Core.configure do |config|
|
149
|
+
config.custom_error_handler = ->(error, context) {
|
150
|
+
# Custom error handling logic
|
151
|
+
}
|
152
|
+
end
|
153
|
+
end
|
154
|
+
```
|
155
|
+
|
156
|
+
### Custom Evolution Jobs
|
157
|
+
```ruby
|
158
|
+
# app/jobs/custom_evolution_job.rb
|
159
|
+
class CustomEvolutionJob < CodeHealer::EvolutionJob
|
160
|
+
sidekiq_options queue: 'high_priority_evolution'
|
161
|
+
|
162
|
+
def perform(error_data, class_name, method_name, file_path)
|
163
|
+
# Custom evolution logic
|
164
|
+
super
|
165
|
+
end
|
166
|
+
end
|
167
|
+
```
|
168
|
+
|
169
|
+
### Business Context Sources
|
170
|
+
```yaml
|
171
|
+
claude_code:
|
172
|
+
business_context_sources:
|
173
|
+
- "config/business_rules.yml"
|
174
|
+
- "docs/business_logic.md"
|
175
|
+
- "spec/business_context_specs.rb"
|
176
|
+
- "app/models/concerns/business_rules.rb"
|
177
|
+
```
|
178
|
+
|
179
|
+
## 🧪 Testing
|
180
|
+
|
181
|
+
### Run Tests
|
182
|
+
```bash
|
183
|
+
bundle exec rspec
|
184
|
+
```
|
185
|
+
|
186
|
+
### Test Configuration
|
187
|
+
```yaml
|
188
|
+
# config/self_evolution.yml (test environment)
|
189
|
+
test:
|
190
|
+
enabled: false
|
191
|
+
mock_ai_responses: true
|
192
|
+
dry_run: true
|
193
|
+
```
|
194
|
+
|
195
|
+
### Mock Responses
|
196
|
+
```yaml
|
197
|
+
test:
|
198
|
+
mock_response: |
|
199
|
+
def calculate_discount(amount, percentage)
|
200
|
+
return 0 if amount.nil? || percentage.nil?
|
201
|
+
amount * (percentage / 100.0)
|
202
|
+
end
|
203
|
+
```
|
204
|
+
|
205
|
+
## 📊 Monitoring
|
206
|
+
|
207
|
+
### Log Levels
|
208
|
+
- `INFO`: General evolution activities
|
209
|
+
- `WARN`: Potential issues or fallbacks
|
210
|
+
- `ERROR`: Evolution failures
|
211
|
+
- `DEBUG`: Detailed debugging information
|
212
|
+
|
213
|
+
### Metrics
|
214
|
+
```ruby
|
215
|
+
# Access evolution metrics
|
216
|
+
CodeHealer::UsageAnalyzer.get_evolution_stats
|
217
|
+
CodeHealer::UsageAnalyzer.get_business_rule_compliance
|
218
|
+
```
|
219
|
+
|
220
|
+
### Sidekiq Web UI
|
221
|
+
```ruby
|
222
|
+
# config/routes.rb
|
223
|
+
mount Sidekiq::Web => '/sidekiq'
|
224
|
+
```
|
225
|
+
|
226
|
+
## 🔒 Security
|
227
|
+
|
228
|
+
### API Keys
|
229
|
+
```yaml
|
230
|
+
api:
|
231
|
+
provider: "openai"
|
232
|
+
api_key: <%= ENV['OPENAI_API_KEY'] %>
|
233
|
+
```
|
234
|
+
|
235
|
+
### Class Restrictions
|
236
|
+
```yaml
|
237
|
+
allowed_classes:
|
238
|
+
- User
|
239
|
+
- Order
|
240
|
+
# Never include ApplicationController, ApplicationRecord, etc.
|
241
|
+
```
|
242
|
+
|
243
|
+
### Business Rule Validation
|
244
|
+
```yaml
|
245
|
+
business_context:
|
246
|
+
validate_rules: true
|
247
|
+
strict_mode: true
|
248
|
+
```
|
249
|
+
|
250
|
+
## 🚨 Troubleshooting
|
251
|
+
|
252
|
+
### Common Issues
|
253
|
+
1. **Evolution not triggering**: Check class permissions and error types
|
254
|
+
2. **AI integration failing**: Verify API keys and network connectivity
|
255
|
+
3. **Git operations failing**: Check repository configuration and tokens
|
256
|
+
4. **Business context not loading**: Verify file paths and permissions
|
257
|
+
|
258
|
+
### Debug Mode
|
259
|
+
```yaml
|
260
|
+
logging:
|
261
|
+
level: debug
|
262
|
+
show_thinking_process: true
|
263
|
+
verbose: true
|
264
|
+
```
|
265
|
+
|
266
|
+
## 📚 Documentation
|
267
|
+
|
268
|
+
- **README.md**: Comprehensive usage guide
|
269
|
+
- **docs/INSTALLATION.md**: Step-by-step installation
|
270
|
+
- **examples/basic_usage.rb**: Basic usage examples
|
271
|
+
- **CHANGELOG.md**: Version history and changes
|
272
|
+
|
273
|
+
## 🤝 Support
|
274
|
+
|
275
|
+
- 📧 **Email**: deepan@example.com
|
276
|
+
- 🐛 **Issues**: GitHub Issues
|
277
|
+
- 💬 **Discussions**: GitHub Discussions
|
278
|
+
- 📖 **Wiki**: GitHub Wiki
|
279
|
+
|
280
|
+
## 🎯 Use Cases
|
281
|
+
|
282
|
+
### Development
|
283
|
+
- Automatic bug fixes during development
|
284
|
+
- Code improvement suggestions
|
285
|
+
- Business rule enforcement
|
286
|
+
|
287
|
+
### Production
|
288
|
+
- Runtime error recovery
|
289
|
+
- Performance optimization
|
290
|
+
- Security vulnerability fixes
|
291
|
+
|
292
|
+
### Testing
|
293
|
+
- Test case generation
|
294
|
+
- Edge case handling
|
295
|
+
- Validation improvement
|
296
|
+
|
297
|
+
## 🚀 Getting Started
|
298
|
+
|
299
|
+
1. **Read the README.md** for comprehensive information
|
300
|
+
2. **Follow INSTALLATION.md** for setup steps
|
301
|
+
3. **Run examples/basic_usage.rb** to see it in action
|
302
|
+
4. **Customize config/self_evolution.yml** for your needs
|
303
|
+
5. **Start evolving your code!**
|
304
|
+
|
305
|
+
---
|
306
|
+
|
307
|
+
**Transform your Rails application into a self-improving, intelligent system today! 🚀**
|
data/README.md
ADDED
@@ -0,0 +1,281 @@
|
|
1
|
+
# CodeHealer 🏥
|
2
|
+
|
3
|
+
**AI-Powered Code Healing and Self-Repair System for Ruby Applications**
|
4
|
+
|
5
|
+
[](https://badge.fury.io/rb/code_healer)
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
7
|
+
|
8
|
+
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!
|
9
|
+
|
10
|
+
## ✨ Features
|
11
|
+
|
12
|
+
- **🚨 Automatic Error Detection** - Catches runtime errors in real-time
|
13
|
+
- **🤖 AI-Powered Fix Generation** - Uses OpenAI GPT models for intelligent code fixes
|
14
|
+
- **💼 Business Context Awareness** - Incorporates your business rules and domain knowledge
|
15
|
+
- **🔄 Automatic Code Patching** - Applies fixes directly to your source code
|
16
|
+
- **📝 Git Integration** - Creates commits and pull requests for all fixes
|
17
|
+
- **⚡ Background Processing** - Uses Sidekiq for non-blocking error resolution
|
18
|
+
- **🔧 Multiple Healing Strategies** - API-based, Claude Code Terminal, or hybrid approaches
|
19
|
+
|
20
|
+
## Dependencies
|
21
|
+
|
22
|
+
CodeHealer requires the following gems:
|
23
|
+
|
24
|
+
- **Rails** (>= 6.0.0) - Web framework integration
|
25
|
+
- **Sidekiq** (>= 6.0.0) - Background job processing
|
26
|
+
- **Redis** (>= 4.0.0) - Sidekiq backend
|
27
|
+
- **Octokit** (>= 4.0.0) - GitHub API integration
|
28
|
+
- **Git** (>= 1.0.0) - Git operations
|
29
|
+
- **OpenAI** (>= 0.16.0) - AI-powered code generation
|
30
|
+
|
31
|
+
## Installation
|
32
|
+
|
33
|
+
### 1. Interactive Installation (Recommended)
|
34
|
+
|
35
|
+
The easiest way to get started is using our interactive setup script:
|
36
|
+
|
37
|
+
```bash
|
38
|
+
# Install the gem
|
39
|
+
gem install code_healer
|
40
|
+
|
41
|
+
# Run the interactive setup in your Rails app directory
|
42
|
+
code_healer-setup
|
43
|
+
```
|
44
|
+
|
45
|
+
The setup script will:
|
46
|
+
- ✅ Add CodeHealer to your Gemfile
|
47
|
+
- 🔑 Collect your OpenAI API key and GitHub token
|
48
|
+
- 📝 Create configuration files
|
49
|
+
- 💼 Set up business context
|
50
|
+
- 📦 Install dependencies
|
51
|
+
|
52
|
+
### 2. Manual Installation
|
53
|
+
|
54
|
+
```bash
|
55
|
+
# Add to your Gemfile
|
56
|
+
gem 'code_healer'
|
57
|
+
|
58
|
+
# Install dependencies
|
59
|
+
bundle install
|
60
|
+
```
|
61
|
+
|
62
|
+
### 3. Environment Variables
|
63
|
+
|
64
|
+
CodeHealer requires several environment variables to function properly:
|
65
|
+
|
66
|
+
```bash
|
67
|
+
# Required for AI-powered code generation
|
68
|
+
OPENAI_API_KEY=your_openai_api_key_here
|
69
|
+
|
70
|
+
# Required for GitHub integration (PR creation, etc.)
|
71
|
+
GITHUB_TOKEN=your_github_personal_access_token
|
72
|
+
GITHUB_REPOSITORY=username/repository_name
|
73
|
+
|
74
|
+
# Optional: Redis URL for Sidekiq
|
75
|
+
REDIS_URL=redis://localhost:6379/0
|
76
|
+
```
|
77
|
+
|
78
|
+
**Loading Environment Variables:**
|
79
|
+
|
80
|
+
You have several options for loading these variables:
|
81
|
+
|
82
|
+
1. **Using dotenv-rails (Recommended):**
|
83
|
+
```ruby
|
84
|
+
# In your Gemfile
|
85
|
+
gem 'dotenv-rails'
|
86
|
+
```
|
87
|
+
|
88
|
+
2. **Manual export in shell:**
|
89
|
+
```bash
|
90
|
+
export OPENAI_API_KEY=your_key
|
91
|
+
export GITHUB_TOKEN=your_token
|
92
|
+
export GITHUB_REPOSITORY=username/repo
|
93
|
+
```
|
94
|
+
|
95
|
+
3. **Load directly in application.rb:**
|
96
|
+
```ruby
|
97
|
+
# In config/application.rb
|
98
|
+
load '.env' if File.exist?('.env')
|
99
|
+
```
|
100
|
+
|
101
|
+
## ⚙️ Configuration
|
102
|
+
|
103
|
+
### Environment Variables
|
104
|
+
|
105
|
+
Create a `.env` file in your Rails app root:
|
106
|
+
|
107
|
+
```bash
|
108
|
+
# OpenAI Configuration
|
109
|
+
OPENAI_API_KEY=your_openai_api_key_here
|
110
|
+
|
111
|
+
# GitHub Configuration
|
112
|
+
GITHUB_TOKEN=your_github_token_here
|
113
|
+
GITHUB_REPOSITORY=username/repo
|
114
|
+
|
115
|
+
# Optional: Redis Configuration
|
116
|
+
REDIS_URL=redis://localhost:6379/0
|
117
|
+
```
|
118
|
+
|
119
|
+
### Configuration File
|
120
|
+
|
121
|
+
The setup script creates `config/code_healer.yml` automatically, or you can create it manually:
|
122
|
+
|
123
|
+
```yaml
|
124
|
+
enabled: true
|
125
|
+
|
126
|
+
# Allowed classes for healing
|
127
|
+
allowed_classes:
|
128
|
+
- User
|
129
|
+
- Order
|
130
|
+
- PaymentProcessor
|
131
|
+
|
132
|
+
# Evolution strategy
|
133
|
+
evolution_strategy:
|
134
|
+
method: api # Options: api, claude_code_terminal, hybrid
|
135
|
+
fallback_to_api: true
|
136
|
+
|
137
|
+
# OpenAI API configuration
|
138
|
+
api:
|
139
|
+
provider: openai
|
140
|
+
model: gpt-4
|
141
|
+
max_tokens: 2000
|
142
|
+
temperature: 0.1
|
143
|
+
|
144
|
+
# Git operations
|
145
|
+
git:
|
146
|
+
auto_commit: true
|
147
|
+
auto_push: true
|
148
|
+
branch_prefix: "heal"
|
149
|
+
```
|
150
|
+
|
151
|
+
## 🏥 How It Works
|
152
|
+
|
153
|
+
1. **Error Detection**: CodeHealer catches runtime errors using Rails error reporting
|
154
|
+
2. **Context Analysis**: Analyzes the error with business context and codebase information
|
155
|
+
3. **AI Fix Generation**: Uses OpenAI to generate intelligent, context-aware fixes
|
156
|
+
4. **Code Patching**: Automatically applies fixes to your source files
|
157
|
+
5. **Git Operations**: Creates commits and optionally pushes changes
|
158
|
+
6. **Class Reloading**: Reloads patched classes to apply fixes immediately
|
159
|
+
|
160
|
+
## 📖 Usage Examples
|
161
|
+
|
162
|
+
### Basic Usage
|
163
|
+
|
164
|
+
Once configured, CodeHealer works automatically! Just run your Rails app:
|
165
|
+
|
166
|
+
```bash
|
167
|
+
# Start your Rails server
|
168
|
+
rails s
|
169
|
+
|
170
|
+
# Start Sidekiq for background processing
|
171
|
+
bundle exec sidekiq
|
172
|
+
```
|
173
|
+
|
174
|
+
### Testing the Healing
|
175
|
+
|
176
|
+
Create a model with intentional errors to test:
|
177
|
+
|
178
|
+
```ruby
|
179
|
+
# app/models/broken_calculator.rb
|
180
|
+
class BrokenCalculator < ApplicationRecord
|
181
|
+
def divide(a, b)
|
182
|
+
a / b # This will cause ZeroDivisionError when b = 0
|
183
|
+
end
|
184
|
+
end
|
185
|
+
```
|
186
|
+
|
187
|
+
When you hit an endpoint that triggers this error, CodeHealer will:
|
188
|
+
1. Catch the error automatically
|
189
|
+
2. Generate a fix using AI
|
190
|
+
3. Apply the fix to your code
|
191
|
+
4. Create a Git commit
|
192
|
+
5. Reload the class
|
193
|
+
|
194
|
+
### Viewing Healing Results
|
195
|
+
|
196
|
+
Check your Sidekiq dashboard at `http://localhost:3000/sidekiq` to see healing jobs in action.
|
197
|
+
|
198
|
+
## 🔧 Advanced Configuration
|
199
|
+
|
200
|
+
### Business Context
|
201
|
+
|
202
|
+
Create `docs/business_rules.md` to provide domain-specific context:
|
203
|
+
|
204
|
+
```markdown
|
205
|
+
# Business Rules
|
206
|
+
|
207
|
+
## Error Handling
|
208
|
+
- All errors should be logged for audit purposes
|
209
|
+
- User-facing errors should be user-friendly
|
210
|
+
- Critical errors should trigger alerts
|
211
|
+
|
212
|
+
## Data Validation
|
213
|
+
- All user inputs must be validated
|
214
|
+
- Business rules must be enforced
|
215
|
+
- Invalid data should be rejected with clear messages
|
216
|
+
```
|
217
|
+
|
218
|
+
### Custom Healing Strategies
|
219
|
+
|
220
|
+
```yaml
|
221
|
+
# Use Claude Code Terminal for local development
|
222
|
+
evolution_strategy:
|
223
|
+
method: claude_code_terminal
|
224
|
+
fallback_to_api: true
|
225
|
+
|
226
|
+
claude_code:
|
227
|
+
enabled: true
|
228
|
+
command_template: "claude --print '{prompt}' --output-format text"
|
229
|
+
```
|
230
|
+
|
231
|
+
## 🛠️ Development
|
232
|
+
|
233
|
+
### Building the Gem
|
234
|
+
|
235
|
+
```bash
|
236
|
+
git clone https://github.com/deepan-g2/code-healer.git
|
237
|
+
cd code-healer
|
238
|
+
bundle install
|
239
|
+
gem build code_healer.gemspec
|
240
|
+
```
|
241
|
+
|
242
|
+
### Running Tests
|
243
|
+
|
244
|
+
```bash
|
245
|
+
bundle exec rspec
|
246
|
+
```
|
247
|
+
|
248
|
+
## 📚 Documentation
|
249
|
+
|
250
|
+
- [Installation Guide](docs/INSTALLATION.md)
|
251
|
+
- [Configuration Reference](docs/CONFIGURATION.md)
|
252
|
+
- [API Documentation](docs/API.md)
|
253
|
+
- [Examples](examples/)
|
254
|
+
|
255
|
+
## 🤝 Contributing
|
256
|
+
|
257
|
+
1. Fork the repository
|
258
|
+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
259
|
+
3. Commit your changes (`git commit -m 'Add amazing feature'`)
|
260
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
261
|
+
5. Open a Pull Request
|
262
|
+
|
263
|
+
## 📄 License
|
264
|
+
|
265
|
+
This project is licensed under the MIT License - see the [LICENSE.txt](LICENSE.txt) file for details.
|
266
|
+
|
267
|
+
## 🙏 Acknowledgments
|
268
|
+
|
269
|
+
- Built with ❤️ by the CodeHealer Team
|
270
|
+
- Powered by OpenAI's GPT models
|
271
|
+
- Inspired by the need for self-healing applications
|
272
|
+
|
273
|
+
## 📞 Support
|
274
|
+
|
275
|
+
- 📧 Email: support@code-healer.com
|
276
|
+
- 🐛 Issues: [GitHub Issues](https://github.com/deepan-g2/code-healer/issues)
|
277
|
+
- 📖 Documentation: [docs.code-healer.com](https://docs.code-healer.com)
|
278
|
+
|
279
|
+
---
|
280
|
+
|
281
|
+
**CodeHealer** - Because your code deserves to heal itself! 🏥✨
|