Module: RubyCoded::Chat::State::ToolConfirmation

Included in:
RubyCoded::Chat::State
Defined in:
lib/ruby_coded/chat/state/tool_confirmation.rb

Overview

Manages the tool confirmation flow as inline chat messages. When a destructive tool is requested, a :tool_pending message is added to the conversation; the user approves or rejects via keyboard, and the message is updated in place.

The user can press [a] to approve all future tool calls for the current session, bypassing individual confirmations.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#tool_cvObject (readonly)

Returns the value of attribute tool_cv.



14
15
16
# File 'lib/ruby_coded/chat/state/tool_confirmation.rb', line 14

def tool_cv
  @tool_cv
end

Instance Method Details

#auto_approve_tools?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/ruby_coded/chat/state/tool_confirmation.rb', line 28

def auto_approve_tools?
  @auto_approve_tools
end

#awaiting_tool_confirmation?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/ruby_coded/chat/state/tool_confirmation.rb', line 24

def awaiting_tool_confirmation?
  @mode == :tool_confirmation
end

#clear_tool_confirmation!Object



79
80
81
82
83
84
# File 'lib/ruby_coded/chat/state/tool_confirmation.rb', line 79

def clear_tool_confirmation!
  @mutex.synchronize do
    reset_pending_tool
    @dirty = true
  end
end

#disable_auto_approve!Object



36
37
38
# File 'lib/ruby_coded/chat/state/tool_confirmation.rb', line 36

def disable_auto_approve!
  @auto_approve_tools = false
end

#enable_auto_approve!Object



32
33
34
# File 'lib/ruby_coded/chat/state/tool_confirmation.rb', line 32

def enable_auto_approve!
  @auto_approve_tools = true
end

#init_tool_confirmationObject



16
17
18
19
20
21
22
# File 'lib/ruby_coded/chat/state/tool_confirmation.rb', line 16

def init_tool_confirmation
  @pending_tool_name = nil
  @pending_tool_args = nil
  @tool_confirmation_response = nil
  @auto_approve_tools = false
  @tool_cv = ConditionVariable.new
end

#pending_tool_argsObject



44
45
46
# File 'lib/ruby_coded/chat/state/tool_confirmation.rb', line 44

def pending_tool_args
  @pending_tool_args
end

#pending_tool_nameObject



40
41
42
# File 'lib/ruby_coded/chat/state/tool_confirmation.rb', line 40

def pending_tool_name
  @pending_tool_name
end

#request_tool_confirmation!(tool_name, tool_args, risk_label: "WRITE") ⇒ Object



59
60
61
62
63
64
65
66
67
68
# File 'lib/ruby_coded/chat/state/tool_confirmation.rb', line 59

def request_tool_confirmation!(tool_name, tool_args, risk_label: "WRITE")
  pending_text = format_tool_pending_text(tool_name, tool_args, risk_label)

  @mutex.synchronize do
    set_pending_tool(tool_name, tool_args)
    append_tool_pending_message(pending_text)
  end

  scroll_to_bottom
end

#resolve_tool_confirmation!(decision) ⇒ Object



70
71
72
73
74
75
76
77
# File 'lib/ruby_coded/chat/state/tool_confirmation.rb', line 70

def resolve_tool_confirmation!(decision)
  @mutex.synchronize do
    finalize_pending_message(decision)
    reset_pending_tool
    @message_generation += 1
    @dirty = true
  end
end

#tool_confirmation_responseObject



48
49
50
# File 'lib/ruby_coded/chat/state/tool_confirmation.rb', line 48

def tool_confirmation_response
  @mutex.synchronize { @tool_confirmation_response }
end

#tool_confirmation_response=(value) ⇒ Object



52
53
54
55
56
57
# File 'lib/ruby_coded/chat/state/tool_confirmation.rb', line 52

def tool_confirmation_response=(value)
  @mutex.synchronize do
    @tool_confirmation_response = value
    @tool_cv.signal
  end
end