Class: Girb::DebugSessionHistory

Inherits:
Object
  • Object
show all
Defined in:
lib/girb/debug_session_history.rb

Overview

デバッグセッション中の入力とAI会話を管理するクラス

Defined Under Namespace

Classes: Entry

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDebugSessionHistory

Returns a new instance of DebugSessionHistory.



49
50
51
52
# File 'lib/girb/debug_session_history.rb', line 49

def initialize
  @entries = []
  @pending_ai_entry = nil
end

Instance Attribute Details

#entriesObject (readonly)

Returns the value of attribute entries.



47
48
49
# File 'lib/girb/debug_session_history.rb', line 47

def entries
  @entries
end

Class Method Details

.ai_conversationsObject



38
39
40
# File 'lib/girb/debug_session_history.rb', line 38

def ai_conversations
  instance.ai_conversations
end

.entriesObject



30
31
32
# File 'lib/girb/debug_session_history.rb', line 30

def entries
  instance.entries
end

.format_history(count = 20) ⇒ Object



42
43
44
# File 'lib/girb/debug_session_history.rb', line 42

def format_history(count = 20)
  instance.format_history(count)
end

.instanceObject



9
10
11
# File 'lib/girb/debug_session_history.rb', line 9

def instance
  @instance ||= new
end

.recent(count = 20) ⇒ Object



34
35
36
# File 'lib/girb/debug_session_history.rb', line 34

def recent(count = 20)
  instance.recent(count)
end

.record_ai_question(question) ⇒ Object



22
23
24
# File 'lib/girb/debug_session_history.rb', line 22

def record_ai_question(question)
  instance.record_ai_question(question)
end

.record_ai_response(response) ⇒ Object



26
27
28
# File 'lib/girb/debug_session_history.rb', line 26

def record_ai_response(response)
  instance.record_ai_response(response)
end

.record_command(command) ⇒ Object

委譲メソッド



18
19
20
# File 'lib/girb/debug_session_history.rb', line 18

def record_command(command)
  instance.record_command(command)
end

.reset!Object



13
14
15
# File 'lib/girb/debug_session_history.rb', line 13

def reset!
  @instance = new
end

Instance Method Details

#ai_conversationsObject

AI会話のみを取得



92
93
94
# File 'lib/girb/debug_session_history.rb', line 92

def ai_conversations
  @entries.select { |e| e.type == :ai_question && e.response }
end

#format_history(count = 20) ⇒ Object

フォーマットされた履歴を取得



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/girb/debug_session_history.rb', line 97

def format_history(count = 20)
  recent(count).map do |entry|
    case entry.type
    when :command
      "[cmd] #{entry.content}"
    when :ai_question
      if entry.response
        response_preview = truncate(entry.response, 150)
        "[ai] Q: #{entry.content}\n     A: #{response_preview}"
      else
        "[ai] Q: #{entry.content} (pending...)"
      end
    end
  end.join("\n")
end

#recent(count = 20) ⇒ Object

最近のエントリを取得



87
88
89
# File 'lib/girb/debug_session_history.rb', line 87

def recent(count = 20)
  @entries.last(count)
end

#record_ai_question(question) ⇒ Object

AI質問を記録(回答は後から追加)



67
68
69
70
71
72
73
74
75
76
# File 'lib/girb/debug_session_history.rb', line 67

def record_ai_question(question)
  entry = Entry.new(
    type: :ai_question,
    content: question,
    response: nil,
    timestamp: Time.now
  )
  @entries << entry
  @pending_ai_entry = entry
end

#record_ai_response(response) ⇒ Object

AI回答を記録



79
80
81
82
83
84
# File 'lib/girb/debug_session_history.rb', line 79

def record_ai_response(response)
  if @pending_ai_entry
    @pending_ai_entry.response = response
    @pending_ai_entry = nil
  end
end

#record_command(command) ⇒ Object

デバッガーコマンドを記録



55
56
57
58
59
60
61
62
63
64
# File 'lib/girb/debug_session_history.rb', line 55

def record_command(command)
  return if command.nil? || command.strip.empty?

  @entries << Entry.new(
    type: :command,
    content: command.strip,
    response: nil,
    timestamp: Time.now
  )
end