rails-ai-context 4.3.2 → 4.3.3

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.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +72 -53
  3. data/CLAUDE.md +1 -1
  4. data/README.md +268 -197
  5. data/demo-trace.gif +0 -0
  6. data/demo-trace.tape +21 -0
  7. data/demo.gif +0 -0
  8. data/demo.tape +33 -0
  9. data/docs/GUIDE.md +9 -9
  10. data/lib/generators/rails_ai_context/install/install_generator.rb +2 -1
  11. data/lib/rails_ai_context/configuration.rb +1 -1
  12. data/lib/rails_ai_context/doctor.rb +4 -2
  13. data/lib/rails_ai_context/fingerprinter.rb +2 -1
  14. data/lib/rails_ai_context/introspectors/accessibility_introspector.rb +2 -1
  15. data/lib/rails_ai_context/introspectors/action_mailbox_introspector.rb +2 -1
  16. data/lib/rails_ai_context/introspectors/action_text_introspector.rb +2 -1
  17. data/lib/rails_ai_context/introspectors/active_storage_introspector.rb +6 -3
  18. data/lib/rails_ai_context/introspectors/api_introspector.rb +8 -4
  19. data/lib/rails_ai_context/introspectors/asset_pipeline_introspector.rb +6 -3
  20. data/lib/rails_ai_context/introspectors/auth_introspector.rb +14 -7
  21. data/lib/rails_ai_context/introspectors/config_introspector.rb +12 -6
  22. data/lib/rails_ai_context/introspectors/controller_introspector.rb +20 -10
  23. data/lib/rails_ai_context/introspectors/convention_detector.rb +2 -1
  24. data/lib/rails_ai_context/introspectors/design_token_introspector.rb +8 -4
  25. data/lib/rails_ai_context/introspectors/devops_introspector.rb +6 -3
  26. data/lib/rails_ai_context/introspectors/engine_introspector.rb +4 -2
  27. data/lib/rails_ai_context/introspectors/frontend_framework_introspector.rb +2 -1
  28. data/lib/rails_ai_context/introspectors/i18n_introspector.rb +2 -1
  29. data/lib/rails_ai_context/introspectors/job_introspector.rb +8 -4
  30. data/lib/rails_ai_context/introspectors/middleware_introspector.rb +4 -2
  31. data/lib/rails_ai_context/introspectors/migration_introspector.rb +2 -1
  32. data/lib/rails_ai_context/introspectors/model_introspector.rb +20 -10
  33. data/lib/rails_ai_context/introspectors/multi_database_introspector.rb +12 -6
  34. data/lib/rails_ai_context/introspectors/performance_introspector.rb +6 -3
  35. data/lib/rails_ai_context/introspectors/route_introspector.rb +4 -2
  36. data/lib/rails_ai_context/introspectors/schema_introspector.rb +14 -7
  37. data/lib/rails_ai_context/introspectors/seeds_introspector.rb +2 -1
  38. data/lib/rails_ai_context/introspectors/stimulus_introspector.rb +8 -4
  39. data/lib/rails_ai_context/introspectors/test_introspector.rb +8 -4
  40. data/lib/rails_ai_context/introspectors/turbo_introspector.rb +22 -11
  41. data/lib/rails_ai_context/introspectors/view_introspector.rb +8 -4
  42. data/lib/rails_ai_context/introspectors/view_template_introspector.rb +10 -5
  43. data/lib/rails_ai_context/tasks/rails_ai_context.rake +8 -4
  44. data/lib/rails_ai_context/tools/analyze_feature.rb +66 -19
  45. data/lib/rails_ai_context/tools/diagnose.rb +4 -2
  46. data/lib/rails_ai_context/tools/get_callbacks.rb +4 -2
  47. data/lib/rails_ai_context/tools/get_concern.rb +12 -6
  48. data/lib/rails_ai_context/tools/get_controllers.rb +10 -5
  49. data/lib/rails_ai_context/tools/get_conventions.rb +4 -2
  50. data/lib/rails_ai_context/tools/get_design_system.rb +2 -1
  51. data/lib/rails_ai_context/tools/get_env.rb +8 -4
  52. data/lib/rails_ai_context/tools/get_helper_methods.rb +6 -3
  53. data/lib/rails_ai_context/tools/get_job_pattern.rb +2 -1
  54. data/lib/rails_ai_context/tools/get_model_details.rb +10 -5
  55. data/lib/rails_ai_context/tools/get_partial_interface.rb +14 -7
  56. data/lib/rails_ai_context/tools/get_schema.rb +2 -1
  57. data/lib/rails_ai_context/tools/get_service_pattern.rb +2 -1
  58. data/lib/rails_ai_context/tools/get_stimulus.rb +2 -1
  59. data/lib/rails_ai_context/tools/get_test_info.rb +4 -2
  60. data/lib/rails_ai_context/tools/get_turbo_map.rb +22 -11
  61. data/lib/rails_ai_context/tools/get_view.rb +6 -3
  62. data/lib/rails_ai_context/tools/migration_advisor.rb +2 -1
  63. data/lib/rails_ai_context/tools/onboard.rb +2 -1
  64. data/lib/rails_ai_context/tools/performance_check.rb +2 -1
  65. data/lib/rails_ai_context/tools/runtime_info.rb +10 -5
  66. data/lib/rails_ai_context/tools/search_code.rb +8 -4
  67. data/lib/rails_ai_context/tools/search_docs.rb +2 -1
  68. data/lib/rails_ai_context/tools/session_context.rb +2 -1
  69. data/lib/rails_ai_context/tools/validate.rb +16 -8
  70. data/lib/rails_ai_context/version.rb +1 -1
  71. metadata +5 -1
@@ -202,14 +202,20 @@ module RailsAiContext
202
202
  lines << "## Services (#{found.size})"
203
203
  found.each do |path|
204
204
  relative = path.sub("#{root}/", "")
205
- source = File.read(path, encoding: "UTF-8", invalid: :replace, undef: :replace) rescue next
205
+ source = begin
206
+ File.read(path, encoding: "UTF-8", invalid: :replace, undef: :replace)
207
+ rescue => e
208
+ $stderr.puts "[rails-ai-context] discover_services failed: #{e.message}" if ENV["DEBUG"]
209
+ next
210
+ end
206
211
  line_count = source.lines.size
207
212
  methods = source.scan(/\A\s*def (?:self\.)?(\w+)/m).flatten.reject { |m| m == "initialize" }
208
213
  lines << "- `#{relative}` (#{line_count} lines)"
209
214
  lines << " Methods: #{methods.first(20).join(', ')}" if methods.any?
210
215
  end
211
216
  lines << ""
212
- rescue
217
+ rescue => e
218
+ $stderr.puts "[rails-ai-context] discover_services failed: #{e.message}" if ENV["DEBUG"]
213
219
  nil
214
220
  end
215
221
 
@@ -226,13 +232,19 @@ module RailsAiContext
226
232
  lines << "## Jobs (#{found.size})"
227
233
  found.each do |path|
228
234
  relative = path.sub("#{root}/", "")
229
- source = File.read(path, encoding: "UTF-8", invalid: :replace, undef: :replace) rescue next
235
+ source = begin
236
+ File.read(path, encoding: "UTF-8", invalid: :replace, undef: :replace)
237
+ rescue => e
238
+ $stderr.puts "[rails-ai-context] discover_jobs failed: #{e.message}" if ENV["DEBUG"]
239
+ next
240
+ end
230
241
  queue = source.match(/queue_as\s+[:'"](\w+)/)&.captures&.first || "default"
231
242
  retries = source.match(/retry_on.*attempts:\s*(\d+)/)&.captures&.first
232
243
  lines << "- `#{relative}` (queue: #{queue}#{retries ? ", retries: #{retries}" : ""})"
233
244
  end
234
245
  lines << ""
235
- rescue
246
+ rescue => e
247
+ $stderr.puts "[rails-ai-context] discover_jobs failed: #{e.message}" if ENV["DEBUG"]
236
248
  nil
237
249
  end
238
250
 
@@ -249,7 +261,12 @@ module RailsAiContext
249
261
  lines << "## Views (#{found.size})"
250
262
  found.each do |path|
251
263
  relative = path.sub("#{views_dir}/", "")
252
- source = File.read(path, encoding: "UTF-8", invalid: :replace, undef: :replace) rescue next
264
+ source = begin
265
+ File.read(path, encoding: "UTF-8", invalid: :replace, undef: :replace)
266
+ rescue => e
267
+ $stderr.puts "[rails-ai-context] discover_views failed: #{e.message}" if ENV["DEBUG"]
268
+ next
269
+ end
253
270
  line_count = source.lines.size
254
271
  partials = source.scan(/render\s+(?:partial:\s*)?["']([^"']+)["']/).flatten
255
272
  stimulus = source.scan(/data-controller=["']([^"']+)["']/).flat_map { |m| m.first.split }
@@ -259,7 +276,8 @@ module RailsAiContext
259
276
  lines << detail
260
277
  end
261
278
  lines << ""
262
- rescue
279
+ rescue => e
280
+ $stderr.puts "[rails-ai-context] discover_views failed: #{e.message}" if ENV["DEBUG"]
263
281
  nil
264
282
  end
265
283
 
@@ -315,13 +333,19 @@ module RailsAiContext
315
333
  lines << "## Tests (#{found.size})"
316
334
  found.each do |path|
317
335
  relative = path.sub("#{root}/", "")
318
- source = File.read(path, encoding: "UTF-8", invalid: :replace, undef: :replace) rescue next
336
+ source = begin
337
+ File.read(path, encoding: "UTF-8", invalid: :replace, undef: :replace)
338
+ rescue => e
339
+ $stderr.puts "[rails-ai-context] discover_tests failed: #{e.message}" if ENV["DEBUG"]
340
+ next
341
+ end
319
342
  test_count = source.scan(/\b(?:it|test|should)\b/).size
320
343
  lines << "- `#{relative}` (#{test_count} tests)"
321
344
  end
322
345
  lines << ""
323
346
  found
324
- rescue
347
+ rescue => e
348
+ $stderr.puts "[rails-ai-context] discover_tests failed: #{e.message}" if ENV["DEBUG"]
325
349
  []
326
350
  end
327
351
 
@@ -377,7 +401,8 @@ module RailsAiContext
377
401
  lines << "## Test Coverage Gaps"
378
402
  gaps.each { |g| lines << "- #{g}" }
379
403
  lines << ""
380
- rescue
404
+ rescue => e
405
+ $stderr.puts "[rails-ai-context] discover_test_gaps failed: #{e.message}" if ENV["DEBUG"]
381
406
  nil
382
407
  end
383
408
 
@@ -392,14 +417,20 @@ module RailsAiContext
392
417
  # Fallback: read source file
393
418
  path = Rails.root.join("app", "controllers", "#{parent_class.underscore}.rb")
394
419
  return [] unless File.exist?(path)
395
- source = File.read(path, encoding: "UTF-8") rescue nil
420
+ source = begin
421
+ File.read(path, encoding: "UTF-8")
422
+ rescue => e
423
+ $stderr.puts "[rails-ai-context] detect_parent_filters_for_analyze failed: #{e.message}" if ENV["DEBUG"]
424
+ nil
425
+ end
396
426
  return [] unless source
397
427
 
398
428
  source.each_line.filter_map do |line|
399
429
  next if line.include?("only:") || line.include?("except:")
400
430
  { name: $1 } if line.match(/\A\s*before_action\s+:(\w+)/)
401
431
  end
402
- rescue
432
+ rescue => e
433
+ $stderr.puts "[rails-ai-context] detect_parent_filters_for_analyze failed: #{e.message}" if ENV["DEBUG"]
403
434
  []
404
435
  end
405
436
 
@@ -444,7 +475,8 @@ module RailsAiContext
444
475
  lines << "## Concerns"
445
476
  concerns.sort.each { |name, count| lines << "- **#{name}** (used by #{count} model#{'s' if count > 1})" }
446
477
  lines << ""
447
- rescue
478
+ rescue => e
479
+ $stderr.puts "[rails-ai-context] discover_concerns failed: #{e.message}" if ENV["DEBUG"]
448
480
  nil
449
481
  end
450
482
 
@@ -481,7 +513,8 @@ module RailsAiContext
481
513
  lines << "- `#{relative}`"
482
514
  end
483
515
  lines << ""
484
- rescue
516
+ rescue => e
517
+ $stderr.puts "[rails-ai-context] discover_channels failed: #{e.message}" if ENV["DEBUG"]
485
518
  nil
486
519
  end
487
520
 
@@ -496,12 +529,18 @@ module RailsAiContext
496
529
  lines << "## Mailers (#{found.size})"
497
530
  found.each do |path|
498
531
  relative = path.sub("#{root}/", "")
499
- source = File.read(path, encoding: "UTF-8", invalid: :replace, undef: :replace) rescue next
532
+ source = begin
533
+ File.read(path, encoding: "UTF-8", invalid: :replace, undef: :replace)
534
+ rescue => e
535
+ $stderr.puts "[rails-ai-context] discover_mailers failed: #{e.message}" if ENV["DEBUG"]
536
+ next
537
+ end
500
538
  methods = source.scan(/\A\s*def (\w+)/m).flatten.reject { |m| m == "initialize" }
501
539
  lines << "- `#{relative}` — #{methods.join(', ')}" if methods.any?
502
540
  end
503
541
  lines << ""
504
- rescue
542
+ rescue => e
543
+ $stderr.puts "[rails-ai-context] discover_mailers failed: #{e.message}" if ENV["DEBUG"]
505
544
  nil
506
545
  end
507
546
 
@@ -519,7 +558,8 @@ module RailsAiContext
519
558
  lines << "- `#{f[:file]}`: #{f[:issue]}"
520
559
  end
521
560
  lines << ""
522
- rescue
561
+ rescue => e
562
+ $stderr.puts "[rails-ai-context] discover_accessibility failed: #{e.message}" if ENV["DEBUG"]
523
563
  nil
524
564
  end
525
565
 
@@ -543,7 +583,8 @@ module RailsAiContext
543
583
  lines << "- **#{c[:name]}**#{slot_info}#{used_in}"
544
584
  end
545
585
  lines << ""
546
- rescue
586
+ rescue => e
587
+ $stderr.puts "[rails-ai-context] discover_components failed: #{e.message}" if ENV["DEBUG"]
547
588
  nil
548
589
  end
549
590
 
@@ -556,7 +597,12 @@ module RailsAiContext
556
597
  dirs.each do |dir|
557
598
  Dir.glob(File.join(dir, "**", "*.rb")).each do |path|
558
599
  next unless File.basename(path, ".rb").include?(pattern) || path.downcase.include?(pattern)
559
- source = File.read(path, encoding: "UTF-8", invalid: :replace, undef: :replace) rescue next
600
+ source = begin
601
+ File.read(path, encoding: "UTF-8", invalid: :replace, undef: :replace)
602
+ rescue => e
603
+ $stderr.puts "[rails-ai-context] discover_env_dependencies failed: #{e.message}" if ENV["DEBUG"]
604
+ next
605
+ end
560
606
  source.scan(/ENV\[["']([^"']+)["']\]|ENV\.fetch\(["']([^"']+)["']\)/).each do |m|
561
607
  env_vars << (m[0] || m[1])
562
608
  end
@@ -567,7 +613,8 @@ module RailsAiContext
567
613
  lines << "## Environment Dependencies"
568
614
  env_vars.sort.each { |v| lines << "- `#{v}`" }
569
615
  lines << ""
570
- rescue
616
+ rescue => e
617
+ $stderr.puts "[rails-ai-context] discover_env_dependencies failed: #{e.message}" if ENV["DEBUG"]
571
618
  nil
572
619
  end
573
620
  end
@@ -377,7 +377,8 @@ module RailsAiContext
377
377
  end
378
378
 
379
379
  lines
380
- rescue
380
+ rescue => e
381
+ $stderr.puts "[rails-ai-context] gather_git_context failed: #{e.message}" if ENV["DEBUG"]
381
382
  []
382
383
  end
383
384
 
@@ -390,7 +391,8 @@ module RailsAiContext
390
391
  return [] if text.include?("Log file is empty") || text.include?("not found") || text.include?("No entries")
391
392
 
392
393
  [ "## Recent Error Logs", text, "" ]
393
- rescue
394
+ rescue => e
395
+ $stderr.puts "[rails-ai-context] gather_log_context failed: #{e.message}" if ENV["DEBUG"]
394
396
  []
395
397
  end
396
398
  end
@@ -257,7 +257,8 @@ module RailsAiContext
257
257
  start_line: start_idx + 1,
258
258
  end_line: end_idx + 1
259
259
  }
260
- rescue
260
+ rescue => e
261
+ $stderr.puts "[rails-ai-context] extract_method_source failed: #{e.message}" if ENV["DEBUG"]
261
262
  nil
262
263
  end
263
264
 
@@ -294,7 +295,8 @@ module RailsAiContext
294
295
  end
295
296
 
296
297
  concern_callbacks
297
- rescue
298
+ rescue => e
299
+ $stderr.puts "[rails-ai-context] find_concern_callbacks failed: #{e.message}" if ENV["DEBUG"]
298
300
  {}
299
301
  end
300
302
  end
@@ -294,7 +294,8 @@ module RailsAiContext
294
294
  end
295
295
 
296
296
  methods
297
- rescue
297
+ rescue => e
298
+ $stderr.puts "[rails-ai-context] parse_public_methods failed: #{e.message}" if ENV["DEBUG"]
298
299
  []
299
300
  end
300
301
 
@@ -332,7 +333,8 @@ module RailsAiContext
332
333
  end
333
334
 
334
335
  methods
335
- rescue
336
+ rescue => e
337
+ $stderr.puts "[rails-ai-context] parse_class_methods failed: #{e.message}" if ENV["DEBUG"]
336
338
  []
337
339
  end
338
340
 
@@ -364,7 +366,8 @@ module RailsAiContext
364
366
  end
365
367
 
366
368
  macros
367
- rescue
369
+ rescue => e
370
+ $stderr.puts "[rails-ai-context] parse_concern_macros failed: #{e.message}" if ENV["DEBUG"]
368
371
  []
369
372
  end
370
373
 
@@ -379,7 +382,8 @@ module RailsAiContext
379
382
  end
380
383
 
381
384
  callbacks
382
- rescue
385
+ rescue => e
386
+ $stderr.puts "[rails-ai-context] parse_concern_callbacks failed: #{e.message}" if ENV["DEBUG"]
383
387
  []
384
388
  end
385
389
 
@@ -405,7 +409,8 @@ module RailsAiContext
405
409
  end
406
410
 
407
411
  result.join("\n")
408
- rescue
412
+ rescue => e
413
+ $stderr.puts "[rails-ai-context] extract_method_source failed: #{e.message}" if ENV["DEBUG"]
409
414
  nil
410
415
  end
411
416
 
@@ -448,7 +453,8 @@ module RailsAiContext
448
453
  end
449
454
 
450
455
  includers.sort
451
- rescue
456
+ rescue => e
457
+ $stderr.puts "[rails-ai-context] find_includers failed: #{e.message}" if ENV["DEBUG"]
452
458
  []
453
459
  end
454
460
  end
@@ -301,7 +301,8 @@ module RailsAiContext
301
301
  next unless body
302
302
  { name: method_name, code: body[:code], start_line: body[:start_line], end_line: body[:end_line] }
303
303
  end.first(5) # Limit to 5 to avoid overwhelming response
304
- rescue
304
+ rescue => e
305
+ $stderr.puts "[rails-ai-context] detect_called_private_methods failed: #{e.message}" if ENV["DEBUG"]
305
306
  []
306
307
  end
307
308
 
@@ -332,7 +333,8 @@ module RailsAiContext
332
333
  end
333
334
  end
334
335
  filters
335
- rescue
336
+ rescue => e
337
+ $stderr.puts "[rails-ai-context] detect_parent_filters failed: #{e.message}" if ENV["DEBUG"]
336
338
  []
337
339
  end
338
340
 
@@ -359,7 +361,8 @@ module RailsAiContext
359
361
  end
360
362
  end
361
363
  skipped
362
- rescue
364
+ rescue => e
365
+ $stderr.puts "[rails-ai-context] detect_skipped_filters failed: #{e.message}" if ENV["DEBUG"]
363
366
  []
364
367
  end
365
368
 
@@ -415,7 +418,8 @@ module RailsAiContext
415
418
  end
416
419
 
417
420
  { redirects: redirects.uniq, renders: renders.uniq, side_effects: side_effects.uniq }
418
- rescue
421
+ rescue => e
422
+ $stderr.puts "[rails-ai-context] extract_render_map failed: #{e.message}" if ENV["DEBUG"]
419
423
  { redirects: [], renders: [], side_effects: [] }
420
424
  end
421
425
 
@@ -443,7 +447,8 @@ module RailsAiContext
443
447
  start_line: start_idx + 1,
444
448
  end_line: end_idx + 1
445
449
  }
446
- rescue
450
+ rescue => e
451
+ $stderr.puts "[rails-ai-context] extract_method_with_lines failed: #{e.message}" if ENV["DEBUG"]
447
452
  nil
448
453
  end
449
454
 
@@ -374,7 +374,8 @@ module RailsAiContext
374
374
  end
375
375
 
376
376
  info
377
- rescue
377
+ rescue => e
378
+ $stderr.puts "[rails-ai-context] detect_locale_info failed: #{e.message}" if ENV["DEBUG"]
378
379
  []
379
380
  end
380
381
 
@@ -431,7 +432,8 @@ module RailsAiContext
431
432
  sections << "Detected from: #{detected_in.first(3).join(', ')}"
432
433
 
433
434
  sections
434
- rescue
435
+ rescue => e
436
+ $stderr.puts "[rails-ai-context] detect_test_pattern failed: #{e.message}" if ENV["DEBUG"]
435
437
  []
436
438
  end
437
439
  end
@@ -370,7 +370,8 @@ module RailsAiContext
370
370
  end
371
371
 
372
372
  lines
373
- rescue
373
+ rescue => e
374
+ $stderr.puts "[rails-ai-context] render_layout_patterns failed: #{e.message}" if ENV["DEBUG"]
374
375
  []
375
376
  end
376
377
 
@@ -442,7 +442,8 @@ module RailsAiContext
442
442
  end
443
443
 
444
444
  services.uniq { |s| "#{s[:name]}:#{s[:file]}" }
445
- rescue
445
+ rescue => e
446
+ $stderr.puts "[rails-ai-context] detect_http_clients failed: #{e.message}" if ENV["DEBUG"]
446
447
  []
447
448
  end
448
449
 
@@ -459,7 +460,8 @@ module RailsAiContext
459
460
  return nil if parts.size < 2
460
461
  # Use the main domain part
461
462
  parts[-2]&.capitalize
462
- rescue
463
+ rescue => e
464
+ $stderr.puts "[rails-ai-context] extract_service_name_from_url failed: #{e.message}" if ENV["DEBUG"]
463
465
  nil
464
466
  end
465
467
  end
@@ -484,7 +486,8 @@ module RailsAiContext
484
486
  end
485
487
 
486
488
  vars.to_a.sort
487
- rescue
489
+ rescue => e
490
+ $stderr.puts "[rails-ai-context] find_env_vars_with_prefix failed: #{e.message}" if ENV["DEBUG"]
488
491
  []
489
492
  end
490
493
 
@@ -639,7 +642,8 @@ module RailsAiContext
639
642
 
640
643
  private_class_method def self.safe_read(path)
641
644
  File.read(path, encoding: "UTF-8", invalid: :replace, undef: :replace)
642
- rescue
645
+ rescue => e
646
+ $stderr.puts "[rails-ai-context] safe_read failed: #{e.message}" if ENV["DEBUG"]
643
647
  nil
644
648
  end
645
649
 
@@ -220,7 +220,8 @@ module RailsAiContext
220
220
  end
221
221
 
222
222
  methods
223
- rescue
223
+ rescue => e
224
+ $stderr.puts "[rails-ai-context] parse_helper_methods failed: #{e.message}" if ENV["DEBUG"]
224
225
  []
225
226
  end
226
227
 
@@ -250,7 +251,8 @@ module RailsAiContext
250
251
  end
251
252
 
252
253
  references
253
- rescue
254
+ rescue => e
255
+ $stderr.puts "[rails-ai-context] find_view_references failed: #{e.message}" if ENV["DEBUG"]
254
256
  {}
255
257
  end
256
258
 
@@ -303,7 +305,8 @@ module RailsAiContext
303
305
  end
304
306
 
305
307
  detected
306
- rescue
308
+ rescue => e
309
+ $stderr.puts "[rails-ai-context] detect_framework_helpers failed: #{e.message}" if ENV["DEBUG"]
307
310
  {}
308
311
  end
309
312
  end
@@ -407,7 +407,8 @@ module RailsAiContext
407
407
 
408
408
  private_class_method def self.safe_read(path)
409
409
  File.read(path, encoding: "UTF-8", invalid: :replace, undef: :replace)
410
- rescue
410
+ rescue => e
411
+ $stderr.puts "[rails-ai-context] safe_read failed: #{e.message}" if ENV["DEBUG"]
411
412
  nil
412
413
  end
413
414
 
@@ -393,7 +393,8 @@ module RailsAiContext
393
393
  end
394
394
  end
395
395
  bodies
396
- rescue
396
+ rescue => e
397
+ $stderr.puts "[rails-ai-context] extract_custom_validate_bodies failed: #{e.message}" if ENV["DEBUG"]
397
398
  {}
398
399
  end
399
400
 
@@ -414,7 +415,8 @@ module RailsAiContext
414
415
  end
415
416
 
416
417
  methods.empty? ? nil : methods
417
- rescue
418
+ rescue => e
419
+ $stderr.puts "[rails-ai-context] extract_source_defined_methods failed: #{e.message}" if ENV["DEBUG"]
418
420
  nil
419
421
  end
420
422
 
@@ -439,7 +441,8 @@ module RailsAiContext
439
441
  end
440
442
 
441
443
  signatures
442
- rescue
444
+ rescue => e
445
+ $stderr.puts "[rails-ai-context] extract_method_signatures failed: #{e.message}" if ENV["DEBUG"]
443
446
  nil
444
447
  end
445
448
 
@@ -469,7 +472,8 @@ module RailsAiContext
469
472
  end
470
473
 
471
474
  methods.empty? ? nil : methods
472
- rescue
475
+ rescue => e
476
+ $stderr.puts "[rails-ai-context] extract_concern_methods failed: #{e.message}" if ENV["DEBUG"]
473
477
  nil
474
478
  end
475
479
 
@@ -512,7 +516,8 @@ module RailsAiContext
512
516
  sections << { start: current_start, end: source_lines.size, label: current_section } if current_section
513
517
 
514
518
  { path: path, total_lines: source_lines.size, sections: sections }
515
- rescue
519
+ rescue => e
520
+ $stderr.puts "[rails-ai-context] extract_model_structure failed: #{e.message}" if ENV["DEBUG"]
516
521
  nil
517
522
  end
518
523
  end
@@ -267,7 +267,8 @@ module RailsAiContext
267
267
  end
268
268
 
269
269
  locals.uniq
270
- rescue
270
+ rescue => e
271
+ $stderr.puts "[rails-ai-context] extract_magic_comment_locals failed: #{e.message}" if ENV["DEBUG"]
271
272
  []
272
273
  end
273
274
 
@@ -324,7 +325,8 @@ module RailsAiContext
324
325
 
325
326
  # Filter out things that are clearly method definitions or blocks
326
327
  locals.reject { |l| l.match?(/\A(each|map|select|reject|find|collect|do|end)\z/) }.to_a.sort
327
- rescue
328
+ rescue => e
329
+ $stderr.puts "[rails-ai-context] extract_local_variable_references failed: #{e.message}" if ENV["DEBUG"]
328
330
  []
329
331
  end
330
332
 
@@ -387,7 +389,8 @@ module RailsAiContext
387
389
  end
388
390
 
389
391
  sites
390
- rescue
392
+ rescue => e
393
+ $stderr.puts "[rails-ai-context] find_render_sites failed: #{e.message}" if ENV["DEBUG"]
391
394
  []
392
395
  end
393
396
 
@@ -414,7 +417,8 @@ module RailsAiContext
414
417
  end
415
418
 
416
419
  locals.uniq
417
- rescue
420
+ rescue => e
421
+ $stderr.puts "[rails-ai-context] extract_locals_from_render failed: #{e.message}" if ENV["DEBUG"]
418
422
  []
419
423
  end
420
424
 
@@ -443,7 +447,8 @@ module RailsAiContext
443
447
  end
444
448
 
445
449
  calls
446
- rescue
450
+ rescue => e
451
+ $stderr.puts "[rails-ai-context] extract_method_calls_on_locals failed: #{e.message}" if ENV["DEBUG"]
447
452
  {}
448
453
  end
449
454
 
@@ -456,13 +461,15 @@ module RailsAiContext
456
461
  parts[-1] = parts[-1].delete_prefix("_").sub(/\..*\z/, "")
457
462
  parts.join("/")
458
463
  end.sort.first(30)
459
- rescue
464
+ rescue => e
465
+ $stderr.puts "[rails-ai-context] find_available_partials failed: #{e.message}" if ENV["DEBUG"]
460
466
  []
461
467
  end
462
468
 
463
469
  private_class_method def self.safe_read(path)
464
470
  File.read(path, encoding: "UTF-8", invalid: :replace, undef: :replace)
465
- rescue
471
+ rescue => e
472
+ $stderr.puts "[rails-ai-context] safe_read failed: #{e.message}" if ENV["DEBUG"]
466
473
  nil
467
474
  end
468
475
 
@@ -205,7 +205,8 @@ module RailsAiContext
205
205
  return [] unless models.is_a?(Hash)
206
206
 
207
207
  models.select { |_, d| d.is_a?(Hash) && d[:table_name] == table_name }.keys
208
- rescue
208
+ rescue => e
209
+ $stderr.puts "[rails-ai-context] models_for_table failed: #{e.message}" if ENV["DEBUG"]
209
210
  []
210
211
  end
211
212
 
@@ -319,7 +319,8 @@ module RailsAiContext
319
319
 
320
320
  private_class_method def self.safe_read(path)
321
321
  File.read(path, encoding: "UTF-8", invalid: :replace, undef: :replace)
322
- rescue
322
+ rescue => e
323
+ $stderr.puts "[rails-ai-context] safe_read failed: #{e.message}" if ENV["DEBUG"]
323
324
  nil
324
325
  end
325
326
 
@@ -236,7 +236,8 @@ module RailsAiContext
236
236
  next unless content.include?(alt_pattern)
237
237
  path.sub("#{Rails.root}/app/views/", "")
238
238
  end.first(10)
239
- rescue
239
+ rescue => e
240
+ $stderr.puts "[rails-ai-context] find_views_using failed: #{e.message}" if ENV["DEBUG"]
240
241
  []
241
242
  end
242
243
 
@@ -333,7 +333,8 @@ module RailsAiContext
333
333
  end
334
334
 
335
335
  lines
336
- rescue
336
+ rescue => e
337
+ $stderr.puts "[rails-ai-context] generate_test_template failed: #{e.message}" if ENV["DEBUG"]
337
338
  []
338
339
  end
339
340
 
@@ -367,7 +368,8 @@ module RailsAiContext
367
368
  end
368
369
 
369
370
  lines.any? ? lines.join("\n") : nil
370
- rescue
371
+ rescue => e
372
+ $stderr.puts "[rails-ai-context] parse_factory_details failed: #{e.message}" if ENV["DEBUG"]
371
373
  nil
372
374
  end
373
375