Class: Legion::Extensions::Agentic::Defense::Whirlpool::Helpers::WhirlpoolEngine
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Defense::Whirlpool::Helpers::WhirlpoolEngine
- Defined in:
- lib/legion/extensions/agentic/defense/whirlpool/helpers/whirlpool_engine.rb
Instance Attribute Summary collapse
-
#vortices ⇒ Object
readonly
Returns the value of attribute vortices.
Instance Method Summary collapse
- #clear ⇒ Object
- #create_vortex(vortex_type:, angular_velocity: 0.5, depth: 0.0, capture_radius: 0.5) ⇒ Object
- #deepest_vortices(limit: 3) ⇒ Object
- #dissipate_all!(rate: Constants::VELOCITY_DECAY) ⇒ Object
- #find_vortex(vortex_id) ⇒ Object
-
#initialize ⇒ WhirlpoolEngine
constructor
A new instance of WhirlpoolEngine.
- #inject_thought(vortex_id:, content:, domain: :general, distance_from_core: 1.0) ⇒ Object
- #remove_vortex(vortex_id) ⇒ Object
- #tick_all!(spiral_rate: nil) ⇒ Object
- #vortex_report ⇒ Object
Constructor Details
#initialize ⇒ WhirlpoolEngine
Returns a new instance of WhirlpoolEngine.
12 13 14 |
# File 'lib/legion/extensions/agentic/defense/whirlpool/helpers/whirlpool_engine.rb', line 12 def initialize @vortices = [] end |
Instance Attribute Details
#vortices ⇒ Object (readonly)
Returns the value of attribute vortices.
10 11 12 |
# File 'lib/legion/extensions/agentic/defense/whirlpool/helpers/whirlpool_engine.rb', line 10 def vortices @vortices end |
Instance Method Details
#clear ⇒ Object
82 83 84 85 |
# File 'lib/legion/extensions/agentic/defense/whirlpool/helpers/whirlpool_engine.rb', line 82 def clear @vortices = [] { cleared: true } end |
#create_vortex(vortex_type:, angular_velocity: 0.5, depth: 0.0, capture_radius: 0.5) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/legion/extensions/agentic/defense/whirlpool/helpers/whirlpool_engine.rb', line 16 def create_vortex(vortex_type:, angular_velocity: 0.5, depth: 0.0, capture_radius: 0.5) raise ArgumentError, "MAX_VORTICES (#{Constants::MAX_VORTICES}) reached" if @vortices.size >= Constants::MAX_VORTICES vortex = Vortex.new( vortex_type: vortex_type, angular_velocity: angular_velocity, depth: depth, capture_radius: capture_radius ) @vortices << vortex vortex end |
#deepest_vortices(limit: 3) ⇒ Object
57 58 59 |
# File 'lib/legion/extensions/agentic/defense/whirlpool/helpers/whirlpool_engine.rb', line 57 def deepest_vortices(limit: 3) @vortices.sort_by { |v| -v.depth }.first(limit).map(&:to_h) end |
#dissipate_all!(rate: Constants::VELOCITY_DECAY) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/legion/extensions/agentic/defense/whirlpool/helpers/whirlpool_engine.rb', line 50 def dissipate_all!(rate: Constants::VELOCITY_DECAY) before = @vortices.size @vortices.each { |v| v.dissipate!(rate: rate) } @vortices.reject!(&:dissipated?) { dissipated: before - @vortices.size, remaining: @vortices.size } end |
#find_vortex(vortex_id) ⇒ Object
72 73 74 |
# File 'lib/legion/extensions/agentic/defense/whirlpool/helpers/whirlpool_engine.rb', line 72 def find_vortex(vortex_id) @vortices.find { |v| v.vortex_id == vortex_id } end |
#inject_thought(vortex_id:, content:, domain: :general, distance_from_core: 1.0) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/legion/extensions/agentic/defense/whirlpool/helpers/whirlpool_engine.rb', line 29 def inject_thought(vortex_id:, content:, domain: :general, distance_from_core: 1.0) vortex = find_vortex(vortex_id) raise ArgumentError, "vortex not found: #{vortex_id}" unless vortex thought = CapturedThought.new( content: content, domain: domain, distance_from_core: distance_from_core ) vortex.capture!(thought) { vortex_id: vortex_id, thought_id: thought.thought_id, domain: domain } end |
#remove_vortex(vortex_id) ⇒ Object
76 77 78 79 80 |
# File 'lib/legion/extensions/agentic/defense/whirlpool/helpers/whirlpool_engine.rb', line 76 def remove_vortex(vortex_id) before = @vortices.size @vortices.reject! { |v| v.vortex_id == vortex_id } { removed: before - @vortices.size } end |
#tick_all!(spiral_rate: nil) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/legion/extensions/agentic/defense/whirlpool/helpers/whirlpool_engine.rb', line 42 def tick_all!(spiral_rate: nil) results = @vortices.map do |v| v.tick!(spiral_rate: spiral_rate) { vortex_id: v.vortex_id, depth: v.depth.round(10), active_thoughts: v.active_thoughts.size } end { ticked: @vortices.size, results: results } end |
#vortex_report ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/legion/extensions/agentic/defense/whirlpool/helpers/whirlpool_engine.rb', line 61 def vortex_report { total_vortices: @vortices.size, powerful_count: @vortices.count(&:powerful?), calm_count: @vortices.count(&:calm?), total_thoughts: @vortices.sum { |v| v.captured_thoughts.size }, core_thoughts: @vortices.sum { |v| v.thoughts_at_core.size }, deepest_vortices: deepest_vortices } end |