Class: Legion::Extensions::Agentic::Defense::Whirlpool::Helpers::Vortex

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/defense/whirlpool/helpers/vortex.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(vortex_type:, angular_velocity: 0.5, depth: 0.0, capture_radius: 0.5) ⇒ Vortex

Returns a new instance of Vortex.

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
20
21
22
23
# File 'lib/legion/extensions/agentic/defense/whirlpool/helpers/vortex.rb', line 13

def initialize(vortex_type:, angular_velocity: 0.5, depth: 0.0, capture_radius: 0.5)
  raise ArgumentError, "unknown vortex_type: #{vortex_type}" unless Constants::VORTEX_TYPES.include?(vortex_type)

  @vortex_id        = SecureRandom.uuid
  @vortex_type      = vortex_type
  @angular_velocity = angular_velocity.clamp(Constants::ANGULAR_VELOCITY_MIN, Constants::ANGULAR_VELOCITY_MAX)
  @depth            = depth.clamp(0.0, Constants::DEPTH_MAX)
  @capture_radius   = capture_radius.clamp(0.0, Constants::CAPTURE_RADIUS_MAX)
  @captured_thoughts = []
  @created_at = Time.now.utc
end

Instance Attribute Details

#angular_velocityObject (readonly)

Returns the value of attribute angular_velocity.



10
11
12
# File 'lib/legion/extensions/agentic/defense/whirlpool/helpers/vortex.rb', line 10

def angular_velocity
  @angular_velocity
end

#capture_radiusObject (readonly)

Returns the value of attribute capture_radius.



10
11
12
# File 'lib/legion/extensions/agentic/defense/whirlpool/helpers/vortex.rb', line 10

def capture_radius
  @capture_radius
end

#captured_thoughtsObject (readonly)

Returns the value of attribute captured_thoughts.



10
11
12
# File 'lib/legion/extensions/agentic/defense/whirlpool/helpers/vortex.rb', line 10

def captured_thoughts
  @captured_thoughts
end

#created_atObject (readonly)

Returns the value of attribute created_at.



10
11
12
# File 'lib/legion/extensions/agentic/defense/whirlpool/helpers/vortex.rb', line 10

def created_at
  @created_at
end

#depthObject (readonly)

Returns the value of attribute depth.



10
11
12
# File 'lib/legion/extensions/agentic/defense/whirlpool/helpers/vortex.rb', line 10

def depth
  @depth
end

#vortex_idObject (readonly)

Returns the value of attribute vortex_id.



10
11
12
# File 'lib/legion/extensions/agentic/defense/whirlpool/helpers/vortex.rb', line 10

def vortex_id
  @vortex_id
end

#vortex_typeObject (readonly)

Returns the value of attribute vortex_type.



10
11
12
# File 'lib/legion/extensions/agentic/defense/whirlpool/helpers/vortex.rb', line 10

def vortex_type
  @vortex_type
end

Instance Method Details

#active_thoughtsObject



61
62
63
# File 'lib/legion/extensions/agentic/defense/whirlpool/helpers/vortex.rb', line 61

def active_thoughts
  @captured_thoughts.reject(&:escaped?)
end

#calm?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/legion/extensions/agentic/defense/whirlpool/helpers/vortex.rb', line 49

def calm?
  @angular_velocity <= Constants::CALM_VELOCITY
end

#capture!(thought) ⇒ Object

Raises:

  • (ArgumentError)


25
26
27
28
29
30
# File 'lib/legion/extensions/agentic/defense/whirlpool/helpers/vortex.rb', line 25

def capture!(thought)
  raise ArgumentError, 'thought must be a CapturedThought' unless thought.is_a?(CapturedThought)

  @captured_thoughts << thought
  thought
end

#depth_labelObject



65
66
67
# File 'lib/legion/extensions/agentic/defense/whirlpool/helpers/vortex.rb', line 65

def depth_label
  Constants::DEPTH_LABELS.find { |entry| entry[:range].cover?(@depth) }&.fetch(:label, :surface) || :surface
end

#dissipate!(rate: Constants::VELOCITY_DECAY) ⇒ Object



39
40
41
42
43
# File 'lib/legion/extensions/agentic/defense/whirlpool/helpers/vortex.rb', line 39

def dissipate!(rate: Constants::VELOCITY_DECAY)
  @angular_velocity = (@angular_velocity - rate).clamp(0.0, Constants::ANGULAR_VELOCITY_MAX)
  @capture_radius   = (@capture_radius - (rate * 0.5)).clamp(0.0, Constants::CAPTURE_RADIUS_MAX)
  self
end

#dissipated?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/legion/extensions/agentic/defense/whirlpool/helpers/vortex.rb', line 53

def dissipated?
  @angular_velocity <= Constants::DISSIPATION_THRESHOLD
end

#powerful?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/legion/extensions/agentic/defense/whirlpool/helpers/vortex.rb', line 45

def powerful?
  @angular_velocity >= Constants::POWERFUL_VELOCITY
end

#thoughts_at_coreObject



57
58
59
# File 'lib/legion/extensions/agentic/defense/whirlpool/helpers/vortex.rb', line 57

def thoughts_at_core
  @captured_thoughts.select(&:at_core?)
end

#tick!(spiral_rate: nil) ⇒ Object



32
33
34
35
36
37
# File 'lib/legion/extensions/agentic/defense/whirlpool/helpers/vortex.rb', line 32

def tick!(spiral_rate: nil)
  rate = spiral_rate || (Constants::SPIRAL_RATE_DEFAULT * @angular_velocity)
  @captured_thoughts.each { |t| t.spiral!(rate: rate) }
  @depth = (@depth + (rate * 0.5)).clamp(0.0, Constants::DEPTH_MAX)
  self
end

#to_hObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/legion/extensions/agentic/defense/whirlpool/helpers/vortex.rb', line 69

def to_h
  {
    vortex_id:        @vortex_id,
    vortex_type:      @vortex_type,
    angular_velocity: @angular_velocity.round(10),
    depth:            @depth.round(10),
    capture_radius:   @capture_radius.round(10),
    depth_label:      depth_label,
    powerful:         powerful?,
    calm:             calm?,
    dissipated:       dissipated?,
    thought_count:    @captured_thoughts.size,
    core_count:       thoughts_at_core.size,
    created_at:       @created_at
  }
end