Class: RubyCoded::Chat::RuntimeMode

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_coded/chat/runtime_mode.rb

Overview

Value object representing the runtime mode of the assistant.

Modes are the single source of truth for tool availability, prompt selection, mutation permission, and confirmation policy. Bridges hold a RuntimeMode instance instead of independent boolean flags to avoid inconsistent combinations.

Constant Summary collapse

NAMES =
%i[chat agent plan].freeze
CHAT =
new(:chat)
AGENT =
new(:agent)
PLAN =
new(:plan)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ RuntimeMode

Returns a new instance of RuntimeMode.

Raises:

  • (ArgumentError)


16
17
18
19
20
# File 'lib/ruby_coded/chat/runtime_mode.rb', line 16

def initialize(name)
  raise ArgumentError, "unknown mode: #{name.inspect}" unless NAMES.include?(name)

  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Class Method Details

.agentObject



76
77
78
# File 'lib/ruby_coded/chat/runtime_mode.rb', line 76

def agent
  AGENT
end

.chatObject



72
73
74
# File 'lib/ruby_coded/chat/runtime_mode.rb', line 72

def chat
  CHAT
end

.for(value) ⇒ Object



84
85
86
87
88
89
90
91
92
93
# File 'lib/ruby_coded/chat/runtime_mode.rb', line 84

def for(value)
  return value if value.is_a?(RuntimeMode)

  case value.to_sym
  when :chat then CHAT
  when :agent then AGENT
  when :plan then PLAN
  else raise ArgumentError, "unknown mode: #{value.inspect}"
  end
end

.planObject



80
81
82
# File 'lib/ruby_coded/chat/runtime_mode.rb', line 80

def plan
  PLAN
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



58
59
60
# File 'lib/ruby_coded/chat/runtime_mode.rb', line 58

def ==(other)
  other.is_a?(RuntimeMode) && other.name == @name
end

#agent?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/ruby_coded/chat/runtime_mode.rb', line 26

def agent?
  @name == :agent
end

#allows_mutation?Boolean

Destructive/write tools are permitted only in agent mode.

Returns:

  • (Boolean)


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

def allows_mutation?
  agent?
end

#allows_tools?Boolean

Tools may be invoked in this mode (readonly for plan, full for agent).

Returns:

  • (Boolean)


35
36
37
# File 'lib/ruby_coded/chat/runtime_mode.rb', line 35

def allows_tools?
  agent? || plan?
end

#chat?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/ruby_coded/chat/runtime_mode.rb', line 22

def chat?
  @name == :chat
end

#hashObject



63
64
65
# File 'lib/ruby_coded/chat/runtime_mode.rb', line 63

def hash
  [self.class, @name].hash
end

#plan?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/ruby_coded/chat/runtime_mode.rb', line 30

def plan?
  @name == :plan
end

#requires_confirmation?Boolean

User confirmation is required for non-safe tools outside chat mode.

Returns:

  • (Boolean)


45
46
47
# File 'lib/ruby_coded/chat/runtime_mode.rb', line 45

def requires_confirmation?
  agent? || plan?
end

#skill_modeObject

Symbol used when querying skills for this mode.



50
51
52
# File 'lib/ruby_coded/chat/runtime_mode.rb', line 50

def skill_mode
  @name
end

#to_sObject



54
55
56
# File 'lib/ruby_coded/chat/runtime_mode.rb', line 54

def to_s
  @name.to_s
end