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

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

Constant Summary collapse

ESCAPE_DISTANCE =
1.0
CORE_DISTANCE =
0.05

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content:, domain: :general, spiral_depth: 0.0, distance_from_core: 1.0) ⇒ CapturedThought

Returns a new instance of CapturedThought.



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

def initialize(content:, domain: :general, spiral_depth: 0.0, distance_from_core: 1.0)
  @thought_id        = SecureRandom.uuid
  @content           = content
  @domain            = domain
  @spiral_depth      = spiral_depth.clamp(0.0, Constants::DEPTH_MAX)
  @distance_from_core = distance_from_core.clamp(0.0, Constants::CAPTURE_RADIUS_MAX)
  @captured_at       = Time.now.utc
  @escaped           = false
end

Instance Attribute Details

#captured_atObject (readonly)

Returns the value of attribute captured_at.



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

def captured_at
  @captured_at
end

#contentObject (readonly)

Returns the value of attribute content.



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

def content
  @content
end

#distance_from_coreObject (readonly)

Returns the value of attribute distance_from_core.



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

def distance_from_core
  @distance_from_core
end

#domainObject (readonly)

Returns the value of attribute domain.



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

def domain
  @domain
end

#spiral_depthObject (readonly)

Returns the value of attribute spiral_depth.



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

def spiral_depth
  @spiral_depth
end

#thought_idObject (readonly)

Returns the value of attribute thought_id.



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

def thought_id
  @thought_id
end

Instance Method Details

#at_core?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/legion/extensions/agentic/defense/whirlpool/helpers/captured_thought.rb', line 32

def at_core?
  @distance_from_core <= CORE_DISTANCE
end

#depth_labelObject



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

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

#escape!Object



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

def escape!
  @escaped = true
end

#escaped?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/legion/extensions/agentic/defense/whirlpool/helpers/captured_thought.rb', line 36

def escaped?
  @escaped
end

#spiral!(rate: Constants::SPIRAL_RATE_DEFAULT) ⇒ Object



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

def spiral!(rate: Constants::SPIRAL_RATE_DEFAULT)
  return if @escaped

  @spiral_depth       = (@spiral_depth + rate).clamp(0.0, Constants::DEPTH_MAX)
  @distance_from_core = (@distance_from_core - rate).clamp(0.0, Constants::CAPTURE_RADIUS_MAX)
end

#to_hObject



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/legion/extensions/agentic/defense/whirlpool/helpers/captured_thought.rb', line 48

def to_h
  {
    thought_id:         @thought_id,
    content:            @content,
    domain:             @domain,
    spiral_depth:       @spiral_depth.round(10),
    distance_from_core: @distance_from_core.round(10),
    depth_label:        depth_label,
    at_core:            at_core?,
    escaped:            @escaped,
    captured_at:        @captured_at
  }
end