code_sage 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 +4 -4
- data/.code_sage.yml +38 -0
- data/CHANGELOG.md +38 -8
- data/Gemfile.lock +1 -1
- data/README.md +66 -31
- data/lib/code_sage/cli.rb +8 -2
- data/lib/code_sage/config.rb +29 -2
- data/lib/code_sage/reviewer.rb +150 -4
- data/lib/code_sage/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2373e4df03b94ff9250c649d452c2c71b8b011bdb72c8323ade0c2050f93f9d
|
4
|
+
data.tar.gz: 19b5c35ee826b396a10d8534d3524731918c7dc179cfc37d47d6d25fa23d90fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c288c141dba2e6c283196c0880bd9578e7f843712820ce2a291a60c3ed7a44f280f6dca63e275b224d9d2e5f92105e05878a68b51ceaa5feb0691e989fa4c86
|
7
|
+
data.tar.gz: 8585510f9d203134152740e1af4ea70727492c813e30eb58a3d86ecffecde2abcf7ba19519ffa8371f6c6917d60a67f673e09d73e7014f1e4469505cc32e9cb4
|
data/.code_sage.yml
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
llm:
|
2
|
+
provider: qwen
|
3
|
+
model: qwen3:1.7b
|
4
|
+
temperature: 0.2
|
5
|
+
|
6
|
+
git:
|
7
|
+
default_branch: main
|
8
|
+
include_patterns:
|
9
|
+
- "*.rb"
|
10
|
+
- "*.rake"
|
11
|
+
- "Gemfile"
|
12
|
+
- "Rakefile"
|
13
|
+
exclude_patterns:
|
14
|
+
- "spec/**/*"
|
15
|
+
- "test/**/*"
|
16
|
+
|
17
|
+
review:
|
18
|
+
focus_areas:
|
19
|
+
- security
|
20
|
+
- performance
|
21
|
+
- maintainability
|
22
|
+
- best_practices
|
23
|
+
severity_levels:
|
24
|
+
- low
|
25
|
+
- medium
|
26
|
+
- high
|
27
|
+
- critical
|
28
|
+
|
29
|
+
output:
|
30
|
+
format: json
|
31
|
+
verbose: false
|
32
|
+
colors: false
|
33
|
+
|
34
|
+
auto_fix:
|
35
|
+
enabled: true
|
36
|
+
confirm_before_apply: true
|
37
|
+
create_backups: true
|
38
|
+
backup_extension: ".backup"
|
data/CHANGELOG.md
CHANGED
@@ -7,18 +7,48 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
## [0.1.1] - 2025-01-08
|
11
|
+
|
10
12
|
### Added
|
11
|
-
-
|
12
|
-
-
|
13
|
-
-
|
14
|
-
-
|
15
|
-
-
|
16
|
-
-
|
17
|
-
-
|
13
|
+
- **Auto-fix functionality**: AI-powered automatic code correction
|
14
|
+
- `--auto-fix` flag to enable automatic code fixes
|
15
|
+
- `--confirm-fixes` / `--no-confirm-fixes` options for confirmation control
|
16
|
+
- Intelligent detection of files needing fixes based on review findings
|
17
|
+
- Automatic backup creation before applying fixes
|
18
|
+
- Safe code extraction and validation
|
19
|
+
- **Enhanced configuration system**:
|
20
|
+
- Local configuration file support (`.code_sage.yml` in current directory)
|
21
|
+
- Improved config priority: CLI explicit > local config > global config > defaults
|
22
|
+
- New `auto_fix` configuration section with safety options
|
23
|
+
- Better config file detection and informative messages
|
24
|
+
- **Improved output format handling**:
|
25
|
+
- Configuration-based default output format
|
26
|
+
- CLI format options properly override config settings
|
27
|
+
- More consistent format application across commands
|
28
|
+
|
29
|
+
### Enhanced
|
30
|
+
- **Reviewer system**:
|
31
|
+
- Better LLM prompt engineering for code fixes
|
32
|
+
- More robust error handling in auto-fix workflow
|
33
|
+
- Enhanced verbose output with configuration information
|
34
|
+
- **Configuration management**:
|
35
|
+
- `config_info` and `show_config_info` methods for better visibility
|
36
|
+
- Smarter config file resolution (local > global > defaults)
|
37
|
+
- More informative config-related messages
|
38
|
+
|
39
|
+
### Fixed
|
40
|
+
- Output format from configuration file now properly applied
|
41
|
+
- Config file loading order and priority issues resolved
|
42
|
+
- Better error handling in git analysis and LLM interactions
|
18
43
|
|
19
44
|
## [0.1.0] - 2025-01-XX
|
20
45
|
|
21
46
|
### Added
|
22
47
|
- Initial release of CodeSage
|
23
48
|
- Basic code review functionality
|
24
|
-
- CLI interface for easy usage
|
49
|
+
- CLI interface for easy usage
|
50
|
+
- Git integration using Rugged
|
51
|
+
- LLM-powered code review using llm_chain
|
52
|
+
- Multiple output formats (console, JSON, markdown)
|
53
|
+
- Ruby code analysis and review
|
54
|
+
- Comprehensive reporting system
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -74,6 +74,11 @@ $ code_sage review -v
|
|
74
74
|
|
75
75
|
# Review with custom configuration
|
76
76
|
$ code_sage review -c ~/.my_code_sage_config.yml
|
77
|
+
|
78
|
+
# Auto-fix functionality (NEW in v0.1.1)
|
79
|
+
$ code_sage review --auto-fix # With confirmation
|
80
|
+
$ code_sage review --auto-fix --no-confirm-fixes # Without confirmation
|
81
|
+
$ code_sage review -f lib/my_file.rb --auto-fix -v # Verbose auto-fix
|
77
82
|
```
|
78
83
|
|
79
84
|
### Configuration
|
@@ -117,6 +122,12 @@ output:
|
|
117
122
|
format: console
|
118
123
|
verbose: false
|
119
124
|
colors: true
|
125
|
+
|
126
|
+
auto_fix:
|
127
|
+
enabled: false
|
128
|
+
confirm_before_apply: true
|
129
|
+
create_backups: true
|
130
|
+
backup_extension: ".backup"
|
120
131
|
```
|
121
132
|
|
122
133
|
#### Configuration Examples
|
@@ -162,6 +173,58 @@ $ code_sage config --key llm.model --value qwen2:7b
|
|
162
173
|
$ code_sage config --reset
|
163
174
|
```
|
164
175
|
|
176
|
+
### Auto-Fix Functionality (NEW in v0.1.1)
|
177
|
+
|
178
|
+
CodeSage can now automatically apply AI-suggested fixes to your Ruby code based on review findings.
|
179
|
+
|
180
|
+
#### How it works:
|
181
|
+
1. **Analysis**: CodeSage reviews your code and identifies issues
|
182
|
+
2. **Detection**: Files with fixable issues are automatically detected
|
183
|
+
3. **AI Fixing**: LLM generates corrected code maintaining original functionality
|
184
|
+
4. **Safety**: Creates backup files before applying any changes
|
185
|
+
5. **Confirmation**: Optional interactive confirmation before applying fixes
|
186
|
+
|
187
|
+
#### Usage Examples:
|
188
|
+
|
189
|
+
```bash
|
190
|
+
# Basic auto-fix with confirmation
|
191
|
+
$ code_sage review -f lib/my_file.rb --auto-fix
|
192
|
+
|
193
|
+
# Auto-fix without confirmation (use with caution)
|
194
|
+
$ code_sage review -f lib/my_file.rb --auto-fix --no-confirm-fixes
|
195
|
+
|
196
|
+
# Auto-fix multiple files with verbose output
|
197
|
+
$ code_sage review -f lib/*.rb --auto-fix -v
|
198
|
+
|
199
|
+
# Auto-fix with custom format output
|
200
|
+
$ code_sage review --auto-fix --format json
|
201
|
+
```
|
202
|
+
|
203
|
+
#### Configuration:
|
204
|
+
|
205
|
+
Enable auto-fix by default in your configuration:
|
206
|
+
|
207
|
+
```yaml
|
208
|
+
auto_fix:
|
209
|
+
enabled: true # Enable auto-fix by default
|
210
|
+
confirm_before_apply: false # Skip confirmation prompts
|
211
|
+
create_backups: true # Always create backups (recommended)
|
212
|
+
backup_extension: ".bak" # Custom backup file extension
|
213
|
+
```
|
214
|
+
|
215
|
+
#### Safety Features:
|
216
|
+
- **Automatic Backups**: Original files are backed up before modifications
|
217
|
+
- **Confirmation Prompts**: Interactive confirmation before applying changes (by default)
|
218
|
+
- **Validation**: Generated code is validated before application
|
219
|
+
- **Verbose Logging**: Detailed information about fixes applied
|
220
|
+
|
221
|
+
#### What gets fixed:
|
222
|
+
- Nil safety issues in string interpolation
|
223
|
+
- Missing error handling (division by zero, etc.)
|
224
|
+
- Security vulnerabilities (unsafe eval usage)
|
225
|
+
- Performance improvements (inefficient algorithms)
|
226
|
+
- Ruby best practices and idioms
|
227
|
+
|
165
228
|
### Programmatic Usage
|
166
229
|
|
167
230
|
You can also use CodeSage programmatically in your Ruby code:
|
@@ -196,6 +259,8 @@ Perform a code review on your repository.
|
|
196
259
|
- `-c, --config PATH` - Path to configuration file
|
197
260
|
- `-v, --verbose` - Verbose output
|
198
261
|
- `--rag` - Enable RAG (Retrieval Augmented Generation) functionality
|
262
|
+
- `--auto-fix` - Automatically apply AI-suggested fixes to files (NEW in v0.1.1)
|
263
|
+
- `--confirm-fixes` / `--no-confirm-fixes` - Confirm before applying fixes (default: true)
|
199
264
|
|
200
265
|
### `config`
|
201
266
|
|
@@ -246,34 +311,4 @@ ollama pull llama2:7b
|
|
246
311
|
|
247
312
|
# Start Ollama server
|
248
313
|
ollama serve
|
249
|
-
```
|
250
|
-
|
251
|
-
#### Other Providers
|
252
|
-
- **Anthropic**: Set `ANTHROPIC_API_KEY`
|
253
|
-
- **Google**: Set `GOOGLE_API_KEY`
|
254
|
-
- **Qwen**: Available through Ollama
|
255
|
-
|
256
|
-
## Dependencies
|
257
|
-
|
258
|
-
- `llm_chain` - For LLM integration
|
259
|
-
- `thor` - CLI framework
|
260
|
-
- `colorize` - Terminal colors
|
261
|
-
- `rugged` - Git integration
|
262
|
-
|
263
|
-
## Development
|
264
|
-
|
265
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
266
|
-
|
267
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
268
|
-
|
269
|
-
## Contributing
|
270
|
-
|
271
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/FuryCow/code_sage.
|
272
|
-
|
273
|
-
## License
|
274
|
-
|
275
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
276
|
-
|
277
|
-
## Changelog
|
278
|
-
|
279
|
-
See [CHANGELOG.md](CHANGELOG.md) for version history and changes.
|
314
|
+
```
|
data/lib/code_sage/cli.rb
CHANGED
@@ -11,6 +11,8 @@ module CodeSage
|
|
11
11
|
option :verbose, aliases: '-v', type: :boolean, desc: "Verbose output"
|
12
12
|
option :rag, type: :boolean,
|
13
13
|
desc: "Enable RAG (Retrieval Augmented Generation) functionality (requires vector database)"
|
14
|
+
option :auto_fix, aliases: '--auto-fix', type: :boolean, desc: "Automatically apply suggested fixes to files"
|
15
|
+
option :confirm_fixes, aliases: '--confirm-fixes', type: :boolean, default: true, desc: "Confirm before applying fixes (default: true)"
|
14
16
|
def review
|
15
17
|
puts "š® CodeSage - Wisdom for your code".colorize(:cyan)
|
16
18
|
puts
|
@@ -20,9 +22,12 @@ module CodeSage
|
|
20
22
|
branch: options[:branch] || 'main',
|
21
23
|
files: options[:files],
|
22
24
|
format: options[:format],
|
25
|
+
format_explicit: ARGV.include?('--format') || ARGV.any? { |arg| arg.start_with?('--format=') },
|
23
26
|
config_path: options[:config],
|
24
27
|
verbose: options[:verbose],
|
25
|
-
enable_rag: options[:rag] || false
|
28
|
+
enable_rag: options[:rag] || false,
|
29
|
+
auto_fix: options[:auto_fix] || false,
|
30
|
+
confirm_fixes: options[:confirm_fixes] != false
|
26
31
|
)
|
27
32
|
|
28
33
|
result = reviewer.review
|
@@ -50,6 +55,7 @@ module CodeSage
|
|
50
55
|
config_instance = Config.new
|
51
56
|
|
52
57
|
if options[:show]
|
58
|
+
config_instance.show_config_info
|
53
59
|
puts "š CodeSage Configuration".colorize(:cyan).bold
|
54
60
|
puts "=" * 50
|
55
61
|
puts YAML.dump(config_instance.data)
|
@@ -61,7 +67,7 @@ module CodeSage
|
|
61
67
|
config_instance.save!
|
62
68
|
puts "ā
Configuration updated: #{options[:key]} = #{options[:value]}".colorize(:green)
|
63
69
|
else
|
64
|
-
|
70
|
+
config_instance.show_config_info
|
65
71
|
puts "Use --show to display configuration"
|
66
72
|
puts "Use --key KEY --value VALUE to update settings"
|
67
73
|
puts "Use --reset to restore defaults"
|
data/lib/code_sage/config.rb
CHANGED
@@ -23,6 +23,12 @@ module CodeSage
|
|
23
23
|
'format' => 'console',
|
24
24
|
'verbose' => false,
|
25
25
|
'colors' => true
|
26
|
+
},
|
27
|
+
'auto_fix' => {
|
28
|
+
'enabled' => false,
|
29
|
+
'confirm_before_apply' => true,
|
30
|
+
'create_backups' => true,
|
31
|
+
'backup_extension' => '.backup'
|
26
32
|
}
|
27
33
|
}.freeze
|
28
34
|
|
@@ -53,11 +59,32 @@ module CodeSage
|
|
53
59
|
@data = DEFAULT_CONFIG.dup
|
54
60
|
save!
|
55
61
|
end
|
62
|
+
|
63
|
+
def config_info
|
64
|
+
if File.exist?(@config_path)
|
65
|
+
"Using config file: #{@config_path}"
|
66
|
+
else
|
67
|
+
"No config file found, using defaults"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def show_config_info
|
72
|
+
puts "š #{config_info}".colorize(:cyan)
|
73
|
+
end
|
56
74
|
|
57
75
|
private
|
58
76
|
|
59
77
|
def default_config_path
|
60
|
-
|
78
|
+
# Š”Š½Š°ŃŠ°Š»Š° ŠøŃŠµŠ¼ в ŃŠµŠŗŃŃŠµŠ¹ Š“ŠøŃŠµŠŗŃŠ¾ŃŠøŠø
|
79
|
+
local_config = File.expand_path('.code_sage.yml')
|
80
|
+
return local_config if File.exist?(local_config)
|
81
|
+
|
82
|
+
# ŠŃли не найГен, ŠøŃŠµŠ¼ в Š“Š¾Š¼Š°ŃŠ½ŠµŠ¹ папке
|
83
|
+
global_config = File.expand_path('~/.code_sage.yml')
|
84
|
+
return global_config if File.exist?(global_config)
|
85
|
+
|
86
|
+
# ŠŃли ни оГин не найГен, Š²Š¾Š·Š²ŃŠ°Ńаем ŠæŃŃŃ Šŗ Š»Š¾ŠŗŠ°Š»ŃŠ½Š¾Š¼Ń Š“Š»Ń ŃŠ¾Š·Š“аниŃ
|
87
|
+
local_config
|
61
88
|
end
|
62
89
|
|
63
90
|
def load_config
|
@@ -68,7 +95,7 @@ module CodeSage
|
|
68
95
|
DEFAULT_CONFIG.dup
|
69
96
|
end
|
70
97
|
rescue => e
|
71
|
-
puts "Warning: Could not load config file #{@config_path}: #{e.message}".colorize(:
|
98
|
+
puts "Warning: Could not load config file #{@config_path}: #{e.message}".colorize(:red)
|
72
99
|
DEFAULT_CONFIG.dup
|
73
100
|
end
|
74
101
|
|
data/lib/code_sage/reviewer.rb
CHANGED
@@ -9,13 +9,31 @@ module CodeSage
|
|
9
9
|
branch: 'main',
|
10
10
|
files: nil,
|
11
11
|
format: 'console',
|
12
|
+
format_explicit: false,
|
12
13
|
config_path: nil,
|
13
14
|
verbose: false,
|
14
|
-
enable_rag: false # ŠŃŠŗŠ»ŃŃŠ°ŠµŠ¼ RAG по ŃŠ¼Š¾Š»ŃаниŃ
|
15
|
+
enable_rag: false, # ŠŃŠŗŠ»ŃŃŠ°ŠµŠ¼ RAG по ŃŠ¼Š¾Š»ŃаниŃ
|
16
|
+
auto_fix: false,
|
17
|
+
confirm_fixes: true
|
15
18
|
}.merge(options)
|
16
19
|
|
20
|
+
# Load configuration first
|
21
|
+
@config = @options[:config_path] ? Config.new(@options[:config_path]) : Config.new
|
22
|
+
|
23
|
+
# Show config info in verbose mode
|
24
|
+
if @options[:verbose]
|
25
|
+
@config.show_config_info
|
26
|
+
end
|
27
|
+
|
28
|
+
# Determine output format: CLI explicit > config > CLI default
|
29
|
+
output_format = if @options[:format_explicit]
|
30
|
+
@options[:format]
|
31
|
+
else
|
32
|
+
@config.data['output']['format'] || @options[:format]
|
33
|
+
end
|
34
|
+
|
17
35
|
@git_analyzer = GitAnalyzer.new(@options)
|
18
|
-
@formatter = ReportFormatter.new(
|
36
|
+
@formatter = ReportFormatter.new(output_format)
|
19
37
|
@llm_chain = setup_llm_chain
|
20
38
|
end
|
21
39
|
|
@@ -42,6 +60,11 @@ module CodeSage
|
|
42
60
|
report = generate_report(reviews)
|
43
61
|
output_report(report)
|
44
62
|
|
63
|
+
# Apply auto-fixes if requested
|
64
|
+
if @options[:auto_fix]
|
65
|
+
apply_fixes(reviews)
|
66
|
+
end
|
67
|
+
|
45
68
|
{ success: true, reviews: reviews, report: report }
|
46
69
|
rescue => e
|
47
70
|
{ success: false, error: e.message }
|
@@ -50,8 +73,8 @@ module CodeSage
|
|
50
73
|
private
|
51
74
|
|
52
75
|
def setup_llm_chain
|
53
|
-
#
|
54
|
-
config = @
|
76
|
+
# Use already loaded configuration
|
77
|
+
config = @config
|
55
78
|
|
56
79
|
llm_config = config.data['llm']
|
57
80
|
provider = llm_config['provider'] || 'openai'
|
@@ -222,5 +245,128 @@ module CodeSage
|
|
222
245
|
formatted_report = @formatter.format(report)
|
223
246
|
puts formatted_report
|
224
247
|
end
|
248
|
+
|
249
|
+
def apply_fixes(reviews)
|
250
|
+
puts "\nš§ Auto-fixing mode enabled".colorize(:cyan).bold
|
251
|
+
|
252
|
+
files_to_fix = []
|
253
|
+
|
254
|
+
reviews.each do |review|
|
255
|
+
next unless review[:review].include?('issue') || review[:review].include?('problem') ||
|
256
|
+
review[:review].include?('fix') || review[:review].include?('improvement')
|
257
|
+
|
258
|
+
files_to_fix << review[:file]
|
259
|
+
end
|
260
|
+
|
261
|
+
if files_to_fix.empty?
|
262
|
+
puts "ā
No files need auto-fixing".colorize(:green)
|
263
|
+
return
|
264
|
+
end
|
265
|
+
|
266
|
+
puts "š Files to fix: #{files_to_fix.join(', ')}"
|
267
|
+
|
268
|
+
if @options[:confirm_fixes]
|
269
|
+
print "Do you want to apply auto-fixes? (y/N): "
|
270
|
+
response = STDIN.gets.chomp.downcase
|
271
|
+
return unless response == 'y' || response == 'yes'
|
272
|
+
end
|
273
|
+
|
274
|
+
files_to_fix.each do |file_path|
|
275
|
+
puts "š§ Fixing #{file_path}..." if @options[:verbose]
|
276
|
+
|
277
|
+
begin
|
278
|
+
fixed_content = get_fixed_content(file_path)
|
279
|
+
if fixed_content && fixed_content != File.read(file_path)
|
280
|
+
apply_fix_to_file(file_path, fixed_content)
|
281
|
+
puts "ā
Fixed #{file_path}".colorize(:green)
|
282
|
+
else
|
283
|
+
puts "ā ļø No changes needed for #{file_path}".colorize(:yellow)
|
284
|
+
end
|
285
|
+
rescue => e
|
286
|
+
puts "ā Error fixing #{file_path}: #{e.message}".colorize(:red)
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
def get_fixed_content(file_path)
|
292
|
+
return nil unless File.exist?(file_path)
|
293
|
+
|
294
|
+
content = File.read(file_path)
|
295
|
+
prompt = build_fix_prompt(file_path, content)
|
296
|
+
|
297
|
+
puts "š¤ Generating fixes for #{file_path}..." if @options[:verbose]
|
298
|
+
|
299
|
+
# Use LLM to get fixed content
|
300
|
+
full_prompt = "#{build_fix_system_message}\n\n#{prompt}"
|
301
|
+
fixed_content = @llm_chain.ask(full_prompt)
|
302
|
+
|
303
|
+
# Extract Ruby code from the response
|
304
|
+
extract_ruby_code(fixed_content)
|
305
|
+
end
|
306
|
+
|
307
|
+
def apply_fix_to_file(file_path, fixed_content)
|
308
|
+
# Create backup
|
309
|
+
backup_path = "#{file_path}.backup.#{Time.now.to_i}"
|
310
|
+
File.write(backup_path, File.read(file_path))
|
311
|
+
|
312
|
+
# Apply fixes
|
313
|
+
File.write(file_path, fixed_content)
|
314
|
+
|
315
|
+
puts "š¾ Backup created: #{backup_path}" if @options[:verbose]
|
316
|
+
end
|
317
|
+
|
318
|
+
def build_fix_system_message
|
319
|
+
<<~PROMPT
|
320
|
+
You are CodeSage, an expert Ruby developer specializing in code fixes and improvements.
|
321
|
+
|
322
|
+
Your task is to:
|
323
|
+
1. Analyze the provided Ruby code
|
324
|
+
2. Apply all necessary fixes for issues found
|
325
|
+
3. Improve code quality, security, and performance
|
326
|
+
4. Return ONLY the corrected Ruby code
|
327
|
+
|
328
|
+
Guidelines:
|
329
|
+
- Fix syntax errors and bugs
|
330
|
+
- Improve Ruby idioms and best practices
|
331
|
+
- Enhance security and performance
|
332
|
+
- Maintain original functionality
|
333
|
+
- Keep the same file structure and class/module names
|
334
|
+
- Add necessary require statements if missing
|
335
|
+
|
336
|
+
IMPORTANT: Return ONLY the corrected Ruby code without any explanations,
|
337
|
+
markdown formatting, or additional text. The response should be valid Ruby code that can be saved directly to a file.
|
338
|
+
PROMPT
|
339
|
+
end
|
340
|
+
|
341
|
+
def build_fix_prompt(file_path, content)
|
342
|
+
<<~PROMPT
|
343
|
+
Please fix the following Ruby file:
|
344
|
+
|
345
|
+
File: #{file_path}
|
346
|
+
|
347
|
+
Current code:
|
348
|
+
```ruby
|
349
|
+
#{content}
|
350
|
+
```
|
351
|
+
|
352
|
+
Apply all necessary fixes and improvements while maintaining the original functionality.
|
353
|
+
Return only the corrected Ruby code.
|
354
|
+
PROMPT
|
355
|
+
end
|
356
|
+
|
357
|
+
def extract_ruby_code(response)
|
358
|
+
# Remove markdown code blocks if present
|
359
|
+
cleaned = response.gsub(/```ruby\s*\n/, '').gsub(/```\s*$/, '')
|
360
|
+
|
361
|
+
# Remove leading/trailing whitespace
|
362
|
+
cleaned = cleaned.strip
|
363
|
+
|
364
|
+
# Validate that it looks like Ruby code (basic check)
|
365
|
+
if cleaned.include?('class ') || cleaned.include?('module ') || cleaned.include?('def ') || cleaned.include?('require')
|
366
|
+
cleaned
|
367
|
+
else
|
368
|
+
nil
|
369
|
+
end
|
370
|
+
end
|
225
371
|
end
|
226
372
|
end
|
data/lib/code_sage/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: code_sage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- FuryCow
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-07-
|
11
|
+
date: 2025-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: llm_chain
|
@@ -130,6 +130,7 @@ executables:
|
|
130
130
|
extensions: []
|
131
131
|
extra_rdoc_files: []
|
132
132
|
files:
|
133
|
+
- ".code_sage.yml"
|
133
134
|
- ".github/workflows/gem.yml"
|
134
135
|
- ".gitignore"
|
135
136
|
- ".rspec"
|