code_healer 0.1.16 → 0.1.17

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: bc8423f76ddef06527d9b8e70a219d0e958ee89e3f352d6bd816697d7d7bb49d
4
- data.tar.gz: c37a4b4101bcda99e166364629d6075c64244f4ef9d04e12b22dccbc5a176f61
3
+ metadata.gz: 87529c94cd83d16eef532144bb5d03d7f9ac588fdbf8cfe89ae167e6722cf329
4
+ data.tar.gz: b0d57d027ebf3e59e1e5515d27148aa5887c4ed6110a5b4de6af57e1785105f7
5
5
  SHA512:
6
- metadata.gz: bea3163ae16b27e735c3aa21c89f2c7a4ffcaf7245c4eca00c39ea17896370ac5870116fa7d6f0499f8aa72fe3bf837d9d3164e4e27f175522dfc9998bc568ff
7
- data.tar.gz: ecf0d683184721228fb6dc3e9d444bac88b2bc5aceb2488890af4356700b5442baf79f058eaee4169e103574eed690b905bc49e8acea4d6c1ea4be6cfc9d2268
6
+ metadata.gz: 7e543125b2ac69159ca0a244ea7249c2fcc38c5947acaf6ff82b3955aec7b35dbf425adcb5bcb3ac89766ec3b01ba2d5668d44ced1c57741d8407e9af8af921d
7
+ data.tar.gz: d67d88d8c80f0ddb0b712131cb7841e7903055cc8db86e1ce46ee18bbfb8a3b5de18e78221b12234577b77bf927588c5a78716f548833ec1146635b661843c95
data/CHANGELOG.md CHANGED
@@ -5,6 +5,19 @@ 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
+ ## [Unreleased]
9
+
10
+ ## [0.1.17] - 2025-08-21
11
+
12
+ ### Added
13
+ - **Interactive Demo Mode Setup**: Added comprehensive demo mode configuration options to the interactive setup script.
14
+ - **Demo Mode Features**: Timeout reduction (60s), sticky workspace, Claude session persistence, and conditional test/PR skipping.
15
+ - **Setup Script Enhancements**: Better user guidance for demo mode configuration and performance optimization.
16
+
17
+ ### Changed
18
+ - **Setup Script**: Enhanced with demo mode questions and configuration generation.
19
+ - **Configuration Generation**: Automatically generates optimized settings for conference demonstrations.
20
+
8
21
  ## [0.1.16] - 2025-08-21
9
22
 
10
23
  ### Added
@@ -11,10 +11,16 @@ module CodeHealer
11
11
  puts "File: #{file_path}"
12
12
 
13
13
  begin
14
- # Build comprehensive prompt
14
+ # Build concise, demo-optimized prompt (no repo-wide scan, no tests)
15
15
  prompt = BusinessContextManager.build_claude_code_prompt(
16
16
  error, class_name, method_name, file_path
17
17
  )
18
+ prompt << "\n\nStrict instructions:" \
19
+ "\n- Do NOT scan the entire codebase." \
20
+ "\n- Work only with the provided file/method context and backtrace." \
21
+ "\n- Return a unified diff (no prose)." \
22
+ "\n- Keep changes minimal and safe." \
23
+ "\n- Do NOT create or run tests." if CodeHealer::ConfigManager.demo_mode?
18
24
 
19
25
  # Execute Claude Code command
20
26
  success = execute_claude_code_fix(prompt, class_name, method_name)
@@ -111,8 +117,10 @@ module CodeHealer
111
117
  command = command_template.gsub('{prompt}', escaped_prompt)
112
118
 
113
119
  # Add additional options if configured
114
- if config['include_tests']
120
+ if config['include_tests'] && !CodeHealer::ConfigManager.demo_mode?
115
121
  command += " --append-system-prompt 'Include tests when fixing the code'"
122
+ else
123
+ command += " --append-system-prompt 'Do NOT create or modify tests'"
116
124
  end
117
125
 
118
126
  if config['max_file_changes']
@@ -122,8 +130,8 @@ module CodeHealer
122
130
  # Add file editing permissions
123
131
  command += " --permission-mode acceptEdits --allowedTools Edit"
124
132
 
125
- # Add current directory access
126
- command += " --add-dir ."
133
+ # Add current directory access but advise not to scan everything
134
+ command += " --add-dir . --append-system-prompt 'Do not scan the whole repo; open only files explicitly referenced.'"
127
135
 
128
136
  command
129
137
  end
@@ -0,0 +1,66 @@
1
+ require 'open3'
2
+
3
+ module CodeHealer
4
+ # Manages a persistent Claude Code Terminal session and one-time preload
5
+ class ClaudeSession
6
+ class << self
7
+ def start!
8
+ return if @started
9
+ return unless CodeHealer::ConfigManager.claude_code_enabled?
10
+
11
+ @started = true
12
+ preload_workspace
13
+ preload_context
14
+ rescue => e
15
+ @started = false
16
+ puts "⚠️ Failed to start Claude session preload: #{e.message}"
17
+ end
18
+
19
+ def with_session
20
+ start!
21
+ yield self
22
+ end
23
+
24
+ private
25
+
26
+ def preload_workspace
27
+ base = CodeHealer::ConfigManager.code_heal_directory_path
28
+ path = CodeHealer::ConfigManager.sticky_workspace? ? File.join(base, 'session_workspace') : base
29
+ @workspace_path = path
30
+
31
+ FileUtils.mkdir_p(base)
32
+ unless Dir.exist?(@workspace_path)
33
+ # First run: create empty workspace folder; HealingWorkspaceManager will clone on demand
34
+ FileUtils.mkdir_p(@workspace_path)
35
+ end
36
+ end
37
+
38
+ def preload_context
39
+ # Build a compact code map for the entire repo, excluding ignored paths
40
+ repo_root = Rails.root.to_s
41
+ ignore = CodeHealer::ConfigManager.claude_ignore_paths
42
+
43
+ files = Dir.chdir(repo_root) do
44
+ Dir.glob("**/*", File::FNM_DOTMATCH)
45
+ .select { |f| File.file?(f) }
46
+ .reject do |f|
47
+ # Skip current/parent, VCS metadata, and ignored dirs/files
48
+ f == '.' || f == '..' ||
49
+ ignore.any? { |ig| f == ig || f.start_with?("#{ig}/") || f.include?("/#{ig}/") }
50
+ end
51
+ end
52
+
53
+ map = files.map do |f|
54
+ { file: f, size: File.size?(File.join(repo_root, f)) || 0 }
55
+ end
56
+
57
+ cache_dir = Rails.root.join('tmp')
58
+ FileUtils.mkdir_p(cache_dir)
59
+ File.write(cache_dir.join('code_healer_context.json'), JSON.pretty_generate(map))
60
+ puts "🧠 Claude preload: indexed #{map.size} files (excluding ignores)"
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+
@@ -82,6 +82,22 @@ module CodeHealer
82
82
  config['claude_code'] || {}
83
83
  end
84
84
 
85
+ def claude_persist_session?
86
+ claude_code_settings['persist_session'] == true
87
+ end
88
+
89
+ def claude_preload_paths
90
+ claude_code_settings['preload_paths'] || [
91
+ 'app', 'lib', 'config', 'Gemfile', 'Gemfile.lock'
92
+ ]
93
+ end
94
+
95
+ def claude_ignore_paths
96
+ claude_code_settings['ignore'] || [
97
+ '.git', 'tmp', 'log', 'storage', 'node_modules', 'vendor', 'public', 'packs', '.bundle', 'bootsnap', 'cache'
98
+ ]
99
+ end
100
+
85
101
  # Business Context Configuration
86
102
  def business_context_enabled?
87
103
  config.dig('business_context', 'enabled') == true
@@ -96,6 +112,23 @@ module CodeHealer
96
112
  config['api'] || {}
97
113
  end
98
114
 
115
+ # Demo Configuration
116
+ def demo_settings
117
+ config['demo'] || {}
118
+ end
119
+
120
+ def demo_mode?
121
+ demo_settings['enabled'] == true
122
+ end
123
+
124
+ def demo_skip_tests?
125
+ demo_mode? && demo_settings['skip_tests'] != false
126
+ end
127
+
128
+ def demo_skip_pr?
129
+ demo_mode? && demo_settings['skip_pr'] != false
130
+ end
131
+
99
132
  def git_settings
100
133
  config['git'] || {}
101
134
  end
@@ -108,6 +141,11 @@ module CodeHealer
108
141
  def code_heal_directory_path
109
142
  code_heal_directory_config['path'] || '/tmp/code_healer_workspaces'
110
143
  end
144
+
145
+ def sticky_workspace?
146
+ cfg = code_heal_directory_config
147
+ cfg['sticky_workspace'] == true || cfg[:sticky_workspace] == true
148
+ end
111
149
 
112
150
  def auto_cleanup_workspaces?
113
151
  code_heal_directory_config['auto_cleanup'] != false
@@ -273,6 +311,11 @@ module CodeHealer
273
311
  'max_tokens' => 2000,
274
312
  'temperature' => 0.1
275
313
  },
314
+ 'demo' => {
315
+ 'enabled' => false,
316
+ 'skip_tests' => true,
317
+ 'skip_pr' => true
318
+ },
276
319
  'git' => {
277
320
  'auto_commit' => true,
278
321
  'auto_push' => true,
@@ -106,16 +106,19 @@ module CodeHealer
106
106
  syntax_check = system("ruby -c #{find_ruby_files.join(' ')} 2>/dev/null")
107
107
  return false unless syntax_check
108
108
 
109
- # Run tests if available
110
- if File.exist?('Gemfile')
111
- bundle_check = system("bundle check >/dev/null 2>&1")
112
- return false unless bundle_check
113
-
114
- # Run tests if RSpec is available
115
- if File.exist?('spec') || File.exist?('test')
116
- test_result = system("bundle exec rspec --dry-run >/dev/null 2>&1") ||
117
- system("bundle exec rake test:prepare >/dev/null 2>&1")
118
- puts "🧪 Test preparation: #{test_result ? '✅' : '⚠️'}"
109
+ # Optionally skip heavy tests in demo mode
110
+ unless CodeHealer::ConfigManager.demo_skip_tests?
111
+ # Run tests if available
112
+ if File.exist?('Gemfile')
113
+ bundle_check = system("bundle check >/dev/null 2>&1")
114
+ return false unless bundle_check
115
+
116
+ # Run tests if RSpec is available
117
+ if File.exist?('spec') || File.exist?('test')
118
+ test_result = system("bundle exec rspec --dry-run >/dev/null 2>&1") ||
119
+ system("bundle exec rake test:prepare >/dev/null 2>&1")
120
+ puts "🧪 Test preparation: #{test_result ? '✅' : '⚠️'}"
121
+ end
119
122
  end
120
123
  end
121
124
 
@@ -170,7 +173,7 @@ module CodeHealer
170
173
  puts "📝 All changes committed in isolated workspace"
171
174
 
172
175
  # Create pull request if auto-create is enabled and no PR was already created
173
- if should_create_pull_request?
176
+ if should_create_pull_request? && !CodeHealer::ConfigManager.demo_skip_pr?
174
177
  puts "🔍 [WORKSPACE] Checking if PR was already created by evolution handler..."
175
178
  # Skip PR creation if we're in a healing workflow (PR likely already created)
176
179
  puts "🔍 [WORKSPACE] PR creation skipped - likely already created by evolution handler"
@@ -320,6 +320,35 @@ evolution_method = case evolution_method.downcase
320
320
 
321
321
  fallback_to_api = ask_for_yes_no("Fallback to API if Claude Code fails?", default: true)
322
322
 
323
+ # Demo Mode Configuration
324
+ puts
325
+ puts "🎭 Demo Mode Configuration:"
326
+ puts "Demo mode optimizes CodeHealer for fast demonstrations and presentations:"
327
+ puts "- Skips test generation for faster response times"
328
+ puts "- Skips pull request creation for immediate results"
329
+ puts "- Uses optimized Claude prompts for quick fixes"
330
+ puts
331
+
332
+ enable_demo_mode = ask_for_yes_no("Enable demo mode for fast demonstrations?", default: false)
333
+
334
+ demo_config = {}
335
+ if enable_demo_mode
336
+ demo_config[:skip_tests] = ask_for_yes_no("Skip test generation in demo mode?", default: true)
337
+ demo_config[:skip_pr] = ask_for_yes_no("Skip pull request creation in demo mode?", default: true)
338
+
339
+ puts
340
+ puts "🚀 Demo mode will significantly speed up healing operations!"
341
+ puts " Perfect for conference talks and live demonstrations."
342
+
343
+ # Add demo-specific instructions
344
+ puts
345
+ puts "📋 Demo Mode Features:"
346
+ puts " - Timeout reduced to 60 seconds for quick responses"
347
+ puts " - Sticky workspace enabled for faster context loading"
348
+ puts " - Claude session persistence for better performance"
349
+ puts " - Tests and PRs skipped for immediate results"
350
+ end
351
+
323
352
  # Create configuration files
324
353
  puts
325
354
  puts "📝 Step 3: Creating Configuration Files"
@@ -377,11 +406,18 @@ create_file_with_content('.env', env_content, dry_run: options[:dry_run])
377
406
 
378
407
  # Claude Code Terminal Configuration
379
408
  claude_code:
380
- enabled: #{evolution_method == 'claude_code_terminal' || evolution_method == 'hybrid'}
381
- timeout: 300 # Timeout in seconds
409
+ enabled: #{evolution_method == 'claude_code_terminal' || evolution_method == 'hybrid'}
410
+ timeout: #{enable_demo_mode ? 60 : 300} # Shorter timeout for demo mode
382
411
  max_file_changes: 10
383
- include_tests: true
384
- command_template: "claude --print '{prompt}' --output-format text --permission-mode acceptEdits --allowedTools Edit"
412
+ include_tests: #{!enable_demo_mode || !demo_config[:skip_tests]}
413
+ persist_session: true # Keep Claude session alive for faster responses
414
+ ignore:
415
+ - "tmp/"
416
+ - "log/"
417
+ - ".git/"
418
+ - "node_modules/"
419
+ - "vendor/"
420
+ command_template: "claude --print '{prompt}' --output-format text --permission-mode acceptEdits --allowedTools Edit"
385
421
  business_context_sources:
386
422
  - "config/business_rules.yml"
387
423
  - "docs/business_logic.md"
@@ -431,6 +467,12 @@ create_file_with_content('.env', env_content, dry_run: options[:dry_run])
431
467
  slack_webhook: ""
432
468
  email_notifications: false
433
469
 
470
+ # Demo Mode Configuration
471
+ demo:
472
+ enabled: #{enable_demo_mode}
473
+ skip_tests: #{demo_config[:skip_tests] || false}
474
+ skip_pr: #{demo_config[:skip_pr] || false}
475
+
434
476
  # Performance Configuration
435
477
  performance:
436
478
  max_concurrent_healing: 3
@@ -444,6 +486,7 @@ create_file_with_content('.env', env_content, dry_run: options[:dry_run])
444
486
  cleanup_after_hours: #{cleanup_after_hours}
445
487
  max_workspaces: 10
446
488
  clone_strategy: "branch" # Options: branch, full_repo
489
+ sticky_workspace: #{enable_demo_mode} # Reuse workspace for faster demo responses
447
490
  YAML
448
491
 
449
492
  create_file_with_content('config/code_healer.yml', config_content, dry_run: options[:dry_run])
@@ -519,10 +562,13 @@ puts " - .env file contains your actual API keys and is ignored by git"
519
562
  puts " - .env.example is safe to commit and shows the required format"
520
563
  puts " - Never commit .env files with real secrets to version control"
521
564
  puts
522
- puts "🏥 Code Heal Directory:"
523
- puts " - Your code will be cloned to: #{code_heal_directory}"
524
- puts " - This ensures safe, isolated healing without affecting your running server"
525
- puts " - Workspaces are automatically cleaned up after #{cleanup_after_hours} hours"
565
+ puts "🏥 Code Heal Directory:"
566
+ puts " - Your code will be cloned to: #{code_heal_directory}"
567
+ puts " - This ensures safe, isolated healing without affecting your running server"
568
+ puts " - Workspaces are automatically cleaned up after #{cleanup_after_hours} hours"
569
+ if enable_demo_mode
570
+ puts " - Demo mode: Sticky workspace enabled for faster context loading"
571
+ end
526
572
  puts
527
573
  puts "⚙️ Configuration:"
528
574
  puts " - code_healer.yml contains comprehensive settings with sensible defaults"
@@ -535,6 +581,10 @@ puts " - All features are pre-configured and ready to use"
535
581
  puts " - Or load .env file in your application.rb: load '.env' if File.exist?('.env')"
536
582
  puts
537
583
  puts "CodeHealer will now automatically detect and heal errors in your application!"
584
+ puts
585
+ puts "📊 Dashboard:"
586
+ puts " - Access your healing metrics at: /code_healer/dashboard"
587
+ puts " - API endpoints available at: /code_healer/api/dashboard/*"
538
588
  end
539
589
 
540
590
  puts
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CodeHealer
4
- VERSION = "0.1.16"
4
+ VERSION = "0.1.17"
5
5
  end
data/lib/code_healer.rb CHANGED
@@ -33,6 +33,7 @@ autoload :MCP, "code_healer/mcp"
33
33
  require_relative "code_healer/models/healing_metric"
34
34
  require_relative "code_healer/services/metrics_collector"
35
35
  require_relative "code_healer/controllers/dashboard_controller"
36
+ require_relative "code_healer/claude_session"
36
37
  autoload :Installer, "code_healer/installer"
37
38
 
38
39
  # Rails integration
@@ -78,5 +79,14 @@ if defined?(Rails)
78
79
  mount CodeHealer::Engine => "/code_healer"
79
80
  end
80
81
  end
82
+
83
+ # Preload Claude session and repository context once per boot
84
+ config.after_initialize do
85
+ begin
86
+ CodeHealer::ClaudeSession.start!
87
+ rescue => e
88
+ puts "⚠️ Claude preload failed: #{e.message}"
89
+ end
90
+ end
81
91
  end
82
92
  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.16
4
+ version: 0.1.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Deepan Kumar
@@ -363,6 +363,7 @@ files:
363
363
  - lib/code_healer/business_rule_applier.rb
364
364
  - lib/code_healer/claude_code_evolution_handler.rb
365
365
  - lib/code_healer/claude_error_monitor.rb
366
+ - lib/code_healer/claude_session.rb
366
367
  - lib/code_healer/config_manager.rb
367
368
  - lib/code_healer/context_aware_prompt_builder.rb
368
369
  - lib/code_healer/controllers/dashboard_controller.rb