Module: Girb::IrbDebugHook

Defined in:
lib/girb/irb_integration.rb

Overview

IRB::Debug.setupをフックして、debug gem初期化後にgirb統合をセットアップ

Instance Method Summary collapse

Instance Method Details

#setup(irb) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/girb/irb_integration.rb', line 15

def setup(irb)
  result = super
  if result && defined?(DEBUGGER__::SESSION)
    # DebugIntegrationを動的に読み込む
    require_relative "debug_integration" unless defined?(Girb::DebugIntegration)
    Girb::DebugIntegration.setup_if_needed

    # Instead of using auto_continue (which causes deadlocks with API calls),
    # inject a qq command to continue the conversation through normal command flow
    if defined?(Girb::AutoContinue) && Girb::AutoContinue.active?
      Girb::AutoContinue.reset!
      # Include original user question so AI remembers the task
      original_question = Girb::IrbIntegration.pending_user_question
      Girb::IrbIntegration.pending_user_question = nil
      if original_question
        continuation = "(auto-continue: Transitioned to debug mode. The first debug command has already been executed. " \
                       "Do NOT re-issue the same command.\n" \
                       "Original instruction: \"#{original_question}\"\n" \
                       "Proceed to the next step. e.g., continue execution or inspect results.)"
      else
        continuation = "(auto-continue: Transitioned to debug mode. The first debug command has already been executed. " \
                       "Proceed to the next step.)"
      end
      Girb::DebugIntegration.add_pending_debug_command("qq #{continuation}")
    end
  end
  result
end