code_healer 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea19c38b242524da0c2be758ff00108c1cbc277c976b818539487bb6279d33af
4
- data.tar.gz: a93de9e58f4cae2a75f074515a3ffe3fc9973d64d05961e32b6ed34193090fd9
3
+ metadata.gz: d2732ef0363299ed27dfb68eb98922fe769ca68392cccdd556a458aab023f2eb
4
+ data.tar.gz: 6136efb1ddfa6849ebdd6d6f6088f6aab13120bb2f3ae4f27c717969b4bfb5bd
5
5
  SHA512:
6
- metadata.gz: c7e457626092026ee1511022848c068a828fdab577e55ee3f2e3096c3b41191a7c97ad27b01c291a0485a3cd2d8d7e85e1649953efa4380e71800c2edde1f91e
7
- data.tar.gz: e5edefe5097f704dee5969d86135a22ed19b35c1391c385fc2fd849559ca689a4390eba45b6f6a084861cd5395c525b22d47ef365de2443f701bfe0a4cbb7608
6
+ metadata.gz: 99e160254ef12aaa403dc36ff9b286b094df4ffd54a4d300d2612fb58f59d2bc3093bb87e08c9708879506a259d23ae53c1241c5041713b3ebbe50669e283cf5
7
+ data.tar.gz: c50f91788ca4144d8b0bc232d9fe57ae7d4bc4b45e6c79697aecfbc4d0cb3be879713ffeb79fb15a9512f84c79071feb929757b37f518adb831b6883b862ffad
data/CHANGELOG.md CHANGED
@@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.1.1] - 2025-01-14
9
+
10
+ ### Changed
11
+ - **Significantly improved README documentation**
12
+ - Enhanced setup instructions with interactive bash script guidance
13
+ - Added comprehensive configuration explanations for all 50+ options
14
+ - Included detailed markdown file creation guide for business context
15
+ - Added best practices and troubleshooting sections
16
+ - Improved installation and configuration examples
17
+ - Enhanced advanced configuration strategies documentation
18
+
19
+ ### Fixed
20
+ - Updated repository URLs in gemspec to point to correct GitHub repo
21
+ - Fixed executable path configuration in gemspec
22
+
8
23
  ## [Unreleased]
9
24
 
10
25
  ### Added
data/README.md CHANGED
@@ -30,9 +30,9 @@ CodeHealer requires the following gems:
30
30
 
31
31
  ## Installation
32
32
 
33
- ### 1. Interactive Installation (Recommended)
33
+ ### 🚀 Quick Start with Interactive Setup (Recommended)
34
34
 
35
- The easiest way to get started is using our interactive setup script:
35
+ The easiest way to get started is using our **interactive bash script** that guides you through the entire setup process:
36
36
 
37
37
  ```bash
38
38
  # Install the gem
@@ -42,14 +42,20 @@ gem install code_healer
42
42
  code_healer-setup
43
43
  ```
44
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
45
+ The interactive setup script will:
46
+ - ✅ **Automatically add** CodeHealer to your Gemfile
47
+ - 🔑 **Securely collect** your OpenAI API key and GitHub token
48
+ - 📝 **Generate** all necessary configuration files
49
+ - 💼 **Set up** business context and rules
50
+ - 📦 **Install** all required dependencies
51
+ - 🎯 **Configure** Git operations and PR creation
52
+ - ⚙️ **Customize** healing strategies for your project
53
+ - 📚 **Create sample markdown files** for business context
54
+ - 🔧 **Set up directory structure** for documentation
51
55
 
52
- ### 2. Manual Installation
56
+ ### 📋 Manual Installation
57
+
58
+ If you prefer manual setup:
53
59
 
54
60
  ```bash
55
61
  # Add to your Gemfile
@@ -59,7 +65,7 @@ gem 'code_healer'
59
65
  bundle install
60
66
  ```
61
67
 
62
- ### 3. Environment Variables
68
+ ### 🔑 Environment Variables
63
69
 
64
70
  CodeHealer requires several environment variables to function properly:
65
71
 
@@ -100,7 +106,108 @@ You have several options for loading these variables:
100
106
 
101
107
  ## ⚙️ Configuration
102
108
 
103
- ### Environment Variables
109
+ ### 🔧 Configuration File
110
+
111
+ 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:
112
+
113
+ ```yaml
114
+ ---
115
+ # CodeHealer Configuration
116
+ enabled: true # Master switch to enable/disable the entire system
117
+
118
+ # 🎯 Class Control
119
+ allowed_classes:
120
+ - User # Classes that are allowed to evolve
121
+ - Order # Add your model classes here
122
+ - PaymentProcessor
123
+ - Api::UserController # Controllers are also supported
124
+
125
+ excluded_classes:
126
+ - ApplicationController # Classes that should NEVER evolve
127
+ - ApplicationRecord # Core Rails classes
128
+ - ApplicationJob
129
+ - ApplicationMailer
130
+
131
+ # 🚨 Error Type Filtering
132
+ allowed_error_types:
133
+ - ArgumentError # Invalid arguments passed to methods
134
+ - NameError # Undefined variables or methods
135
+ - NoMethodError # Method doesn't exist on object
136
+ - TypeError # Wrong type of object
137
+ - ValidationError # Custom validation errors
138
+
139
+ # 🤖 Evolution Strategy
140
+ evolution_strategy:
141
+ method: "api" # Options: "api", "claude_code_terminal", "hybrid"
142
+ fallback_to_api: true # If Claude Code fails, fall back to API
143
+
144
+ # 🧠 Claude Code Terminal (Local AI Agent)
145
+ claude_code:
146
+ enabled: true # Enable Claude Code integration
147
+ timeout: 300 # 5 minutes timeout for AI responses
148
+ max_file_changes: 10 # Maximum files Claude can modify
149
+ include_tests: true # Include test files in analysis
150
+ command_template: "claude --print '{prompt}' --output-format text --permission-mode acceptEdits --allowedTools Edit"
151
+ business_context_sources: # Sources for business context
152
+ - "config/business_rules.yml"
153
+ - "docs/business_logic.md"
154
+ - "spec/business_context_specs.rb"
155
+
156
+ # 💼 Business Context & Domain Knowledge
157
+ business_context:
158
+ enabled: true # Enable business context integration
159
+
160
+ User: # Class-specific business rules
161
+ domain: "User Management"
162
+ key_rules:
163
+ - "Email must be unique and valid"
164
+ - "Password must meet security requirements"
165
+ - "User data must be validated"
166
+ validation_patterns:
167
+ - "Email format validation"
168
+ - "Password strength requirements"
169
+ - "Data integrity checks"
170
+
171
+ Order: # Another class example
172
+ domain: "E-commerce Order Processing"
173
+ key_rules:
174
+ - "Orders must have valid customer information"
175
+ - "Payment validation is required"
176
+ - "Inventory must be checked before processing"
177
+
178
+ # 🌐 OpenAI API Configuration
179
+ api:
180
+ provider: "openai" # AI provider (currently OpenAI)
181
+ model: "gpt-4" # AI model to use
182
+ max_tokens: 2000 # Maximum tokens in response
183
+ temperature: 0.1 # Creativity vs. consistency (0.0 = deterministic, 1.0 = creative)
184
+
185
+ # 📝 Git Operations
186
+ git:
187
+ auto_commit: true # Automatically commit fixes
188
+ auto_push: true # Push to remote repository
189
+ branch_prefix: "evolve" # Branch naming: evolve/classname-methodname-timestamp
190
+ commit_message_template: 'Fix {class_name}##{method_name}: {error_type}'
191
+ pr_target_branch: "main" # Target branch for pull requests
192
+
193
+ # 🔀 Pull Request Configuration
194
+ pull_request:
195
+ enabled: true # Enable automatic PR creation
196
+ auto_create: true # Create PRs automatically
197
+ title_template: 'Fix {class_name}##{method_name}: Handle {error_type}'
198
+ labels: # Labels to add to PRs
199
+ - "auto-fix"
200
+ - "self-evolving"
201
+ - "bug-fix"
202
+
203
+ # ⚡ Sidekiq Background Processing
204
+ sidekiq:
205
+ queue: "evolution" # Queue name for healing jobs
206
+ retry: 3 # Number of retry attempts
207
+ backtrace: true # Include backtraces in job data
208
+ ```
209
+
210
+ ### 🔑 Environment Variables
104
211
 
105
212
  Create a `.env` file in your Rails app root:
106
213
 
@@ -116,38 +223,6 @@ GITHUB_REPOSITORY=username/repo
116
223
  REDIS_URL=redis://localhost:6379/0
117
224
  ```
118
225
 
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
226
  ## 🏥 How It Works
152
227
 
153
228
  1. **Error Detection**: CodeHealer catches runtime errors using Rails error reporting
@@ -197,35 +272,220 @@ Check your Sidekiq dashboard at `http://localhost:3000/sidekiq` to see healing j
197
272
 
198
273
  ## 🔧 Advanced Configuration
199
274
 
200
- ### Business Context
275
+ ### 🎯 Interactive Setup Script
276
+
277
+ The `code_healer-setup` script provides an interactive, guided setup experience:
278
+
279
+ ```bash
280
+ $ code_healer-setup
281
+
282
+ 🏥 Welcome to CodeHealer Setup!
283
+ ================================
284
+
285
+ This interactive setup will configure CodeHealer for your Rails application.
286
+
287
+ 📋 What we'll set up:
288
+ - OpenAI API configuration
289
+ - GitHub integration
290
+ - Business context rules
291
+ - Git operations
292
+ - Healing strategies
293
+ - Sidekiq configuration
294
+
295
+ 🔑 Step 1: OpenAI Configuration
296
+ Enter your OpenAI API key: ****************
297
+ ✅ OpenAI API key configured successfully!
298
+
299
+ 🔗 Step 2: GitHub Integration
300
+ Enter your GitHub personal access token: ****************
301
+ Enter your GitHub repository (username/repo): deepan-g2/myapp
302
+ ✅ GitHub integration configured successfully!
303
+
304
+ 💼 Step 3: Business Context
305
+ Would you like to set up business context rules? (y/n): y
306
+ Enter business domain for User class: User Management
307
+ Enter key business rules (comma-separated): Email validation, Password security, Data integrity
308
+ ✅ Business context configured successfully!
309
+
310
+ ⚙️ Step 4: Healing Strategy
311
+ Choose evolution method:
312
+ 1. API (OpenAI) - Cloud-based, reliable
313
+ 2. Claude Code Terminal - Local AI agent, full codebase access
314
+ 3. Hybrid - Best of both worlds
315
+ Enter choice (1-3): 2
316
+ ✅ Claude Code Terminal strategy selected!
317
+
318
+ 📝 Step 5: Git Configuration
319
+ Enter branch prefix for fixes: evolve
320
+ Enter target branch for PRs: main
321
+ ✅ Git configuration completed!
322
+
323
+ 🎉 Setup complete! CodeHealer is now configured for your application.
324
+ ```
325
+
326
+ ### 💼 Business Context Integration
327
+
328
+ 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.
201
329
 
202
- Create `docs/business_rules.md` to provide domain-specific context:
330
+ #### 📁 Creating Business Context Files
203
331
 
332
+ Create markdown files in your project to define business rules:
333
+
334
+ **`docs/business_rules.md`** - General business rules:
204
335
  ```markdown
205
- # Business Rules
336
+ # Business Rules & Standards
206
337
 
207
- ## Error Handling
338
+ ## Error Handling Principles
208
339
  - All errors should be logged for audit purposes
209
- - User-facing errors should be user-friendly
210
- - Critical errors should trigger alerts
340
+ - User-facing errors should be user-friendly and actionable
341
+ - Critical errors should trigger immediate alerts
342
+ - Security errors should never expose sensitive information
343
+
344
+ ## Data Validation Standards
345
+ - All user inputs must be validated before processing
346
+ - Business rules must be enforced at the model level
347
+ - Invalid data should be rejected with clear, helpful error messages
348
+ - Data integrity must be maintained across all operations
349
+
350
+ ## Security Guidelines
351
+ - Never log sensitive information (passwords, tokens, PII)
352
+ - Input sanitization is mandatory for all user-provided data
353
+ - Rate limiting should be applied to prevent abuse
354
+ - Authentication must be verified for all protected operations
355
+ ```
356
+
357
+ **`docs/user_management.md`** - Domain-specific rules:
358
+ ```markdown
359
+ # User Management Domain
360
+
361
+ ## User Registration
362
+ - Email addresses must be unique across the system
363
+ - Password strength: minimum 8 characters, mixed case, numbers
364
+ - Email verification is required before account activation
365
+ - Username must be alphanumeric, 3-20 characters
366
+
367
+ ## User Authentication
368
+ - Failed login attempts are limited to 5 per hour
369
+ - Password reset tokens expire after 1 hour
370
+ - Session timeout after 24 hours of inactivity
371
+ - Multi-factor authentication for admin accounts
372
+
373
+ ## Data Privacy
374
+ - User data is encrypted at rest
375
+ - GDPR compliance for EU users
376
+ - Right to data deletion must be honored
377
+ - Audit trail for all data modifications
378
+ ```
211
379
 
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
380
+ **`docs/order_processing.md`** - Another domain example:
381
+ ```markdown
382
+ # Order Processing Domain
383
+
384
+ ## Order Validation
385
+ - Customer information must be complete and verified
386
+ - Payment method must be valid and authorized
387
+ - Inventory must be available before order confirmation
388
+ - Shipping address must be deliverable
389
+
390
+ ## Business Rules
391
+ - Orders cannot be cancelled after shipping
392
+ - Refunds processed within 30 days
393
+ - Bulk orders get 10% discount
394
+ - Free shipping for orders over $50
395
+
396
+ ## Error Handling
397
+ - Insufficient inventory: suggest alternatives
398
+ - Payment failure: retry up to 3 times
399
+ - Invalid address: prompt for correction
400
+ - System errors: queue for manual review
216
401
  ```
217
402
 
218
- ### Custom Healing Strategies
403
+ #### 🔧 Configuration for Markdown Files
404
+
405
+ Update your `config/code_healer.yml` to include these files:
219
406
 
220
407
  ```yaml
221
- # Use Claude Code Terminal for local development
408
+ business_context:
409
+ enabled: true
410
+
411
+ # Sources for business context (markdown files)
412
+ sources:
413
+ - "docs/business_rules.md"
414
+ - "docs/user_management.md"
415
+ - "docs/order_processing.md"
416
+ - "README.md" # Project documentation
417
+ - "docs/API.md" # API documentation
418
+
419
+ claude_code:
420
+ business_context_sources:
421
+ - "docs/business_rules.md"
422
+ - "docs/user_management.md"
423
+ - "docs/order_processing.md"
424
+ - "config/business_rules.yml" # YAML format also supported
425
+ ```
426
+
427
+ #### 📝 Markdown File Best Practices
428
+
429
+ 1. **Use clear headings** (`#`, `##`, `###`) for structure
430
+ 2. **Include specific examples** of valid/invalid data
431
+ 3. **Document error scenarios** and expected responses
432
+ 4. **Keep it concise** but comprehensive
433
+ 5. **Update regularly** as business rules evolve
434
+ 6. **Use consistent formatting** for better AI parsing
435
+
436
+ #### 🎯 How AI Uses Markdown Context
437
+
438
+ When CodeHealer encounters an error, it:
439
+ 1. **Reads relevant markdown files** based on the error context
440
+ 2. **Extracts business rules** that apply to the failing code
441
+ 3. **Generates fixes** that respect your business logic
442
+ 4. **Ensures compliance** with your domain standards
443
+ 5. **Maintains consistency** with existing code patterns
444
+
445
+ ### 🤖 Custom Healing Strategies
446
+
447
+ #### API Strategy (OpenAI)
448
+ ```yaml
222
449
  evolution_strategy:
223
- method: claude_code_terminal
450
+ method: "api"
451
+ fallback_to_api: false # No fallback needed
452
+
453
+ api:
454
+ provider: "openai"
455
+ model: "gpt-4"
456
+ max_tokens: 3000 # Increase for complex fixes
457
+ temperature: 0.05 # More deterministic
458
+ ```
459
+
460
+ #### Claude Code Terminal Strategy
461
+ ```yaml
462
+ evolution_strategy:
463
+ method: "claude_code_terminal"
464
+ fallback_to_api: true # Fallback if Claude fails
465
+
466
+ claude_code:
467
+ enabled: true
468
+ timeout: 600 # 10 minutes for complex fixes
469
+ max_file_changes: 15 # Allow more file modifications
470
+ include_tests: true # Include test files in analysis
471
+ ```
472
+
473
+ #### Hybrid Strategy
474
+ ```yaml
475
+ evolution_strategy:
476
+ method: "hybrid"
224
477
  fallback_to_api: true
225
478
 
479
+ # Claude Code for local development
226
480
  claude_code:
227
481
  enabled: true
228
- command_template: "claude --print '{prompt}' --output-format text"
482
+ timeout: 300
483
+
484
+ # OpenAI API for production/fallback
485
+ api:
486
+ provider: "openai"
487
+ model: "gpt-4"
488
+ max_tokens: 2000
229
489
  ```
230
490
 
231
491
  ## 🛠️ Development
@@ -245,6 +505,56 @@ gem build code_healer.gemspec
245
505
  bundle exec rspec
246
506
  ```
247
507
 
508
+ ## ⚠️ Configuration Best Practices
509
+
510
+ ### 🎯 Class Selection
511
+ - **Start conservative**: Only allow classes you're comfortable with auto-evolving
512
+ - **Exclude core classes**: Never allow `ApplicationController`, `ApplicationRecord`, etc.
513
+ - **Test thoroughly**: Verify allowed classes work as expected before production
514
+
515
+ ### 🔐 Security Considerations
516
+ - **API keys**: Store in environment variables, never in code
517
+ - **GitHub tokens**: Use minimal required permissions (`repo`, `workflow`)
518
+ - **Business context**: Be careful with sensitive business rules in markdown files
519
+
520
+ ### 🚀 Performance Optimization
521
+ - **Claude Code timeout**: Set appropriate timeouts (300-600 seconds)
522
+ - **Max file changes**: Limit to prevent excessive modifications
523
+ - **Sidekiq queue**: Use dedicated queue for evolution jobs
524
+
525
+ ### 🔧 Troubleshooting Common Issues
526
+
527
+ #### "No backtrace available" Error
528
+ ```yaml
529
+ # Ensure backtrace is enabled in Sidekiq config
530
+ sidekiq:
531
+ backtrace: true
532
+ ```
533
+
534
+ #### Pull Request Creation Fails
535
+ ```yaml
536
+ # Verify GitHub token has correct permissions
537
+ # Check target branch exists
538
+ git:
539
+ pr_target_branch: "main" # Must exist in remote
540
+ ```
541
+
542
+ #### Claude Code Not Responding
543
+ ```yaml
544
+ # Increase timeout and verify command template
545
+ claude_code:
546
+ timeout: 600
547
+ command_template: "claude --print '{prompt}' --output-format text"
548
+ ```
549
+
550
+ #### Business Context Not Loading
551
+ ```yaml
552
+ # Ensure markdown files exist and are readable
553
+ business_context:
554
+ enabled: true
555
+ # Check file paths are correct
556
+ ```
557
+
248
558
  ## 📚 Documentation
249
559
 
250
560
  - [Installation Guide](docs/INSTALLATION.md)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CodeHealer
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code_healer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Deepan Kumar