Class: Legion::Extensions::Agentic::Homeostasis::Weather::Helpers::Storm

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/homeostasis/weather/helpers/storm.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(condition:, front_ids: [], intensity: 0.5, coverage: 0.5) ⇒ Storm

Returns a new instance of Storm.

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
22
23
24
25
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/storm.rb', line 15

def initialize(condition:, front_ids: [], intensity: 0.5, coverage: 0.5)
  raise ArgumentError, "unknown condition: #{condition}" unless Constants::CONDITION_TYPES.include?(condition.to_sym)

  @id          = SecureRandom.uuid
  @condition   = condition.to_sym
  @front_ids   = Array(front_ids).dup
  @intensity   = intensity.clamp(0.0, 1.0)
  @coverage    = coverage.clamp(0.0, 1.0)
  @created_at  = Time.now.utc
  @insight_log = []
end

Instance Attribute Details

#conditionObject (readonly)

Returns the value of attribute condition.



12
13
14
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/storm.rb', line 12

def condition
  @condition
end

#coverageObject

Returns the value of attribute coverage.



13
14
15
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/storm.rb', line 13

def coverage
  @coverage
end

#created_atObject (readonly)

Returns the value of attribute created_at.



12
13
14
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/storm.rb', line 12

def created_at
  @created_at
end

#front_idsObject (readonly)

Returns the value of attribute front_ids.



12
13
14
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/storm.rb', line 12

def front_ids
  @front_ids
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/storm.rb', line 12

def id
  @id
end

#insight_logObject (readonly)

Returns the value of attribute insight_log.



12
13
14
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/storm.rb', line 12

def insight_log
  @insight_log
end

#intensityObject

Returns the value of attribute intensity.



13
14
15
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/storm.rb', line 13

def intensity
  @intensity
end

Instance Method Details

#clarity_labelObject



61
62
63
64
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/storm.rb', line 61

def clarity_label
  # Clarity is inverse of intensity: high intensity = low clarity
  Constants.label_for(Constants::CLARITY_LABELS, 1.0 - @intensity)
end

#clearing?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/storm.rb', line 57

def clearing?
  @intensity <= 0.25
end

#dissipate!(rate = Constants::DISSIPATION_RATE) ⇒ Object

Dissipate: storm weakens and clears



34
35
36
37
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/storm.rb', line 34

def dissipate!(rate = Constants::DISSIPATION_RATE)
  @intensity = (@intensity - rate.clamp(0.0, 1.0)).clamp(0.0, 1.0)
  @coverage  = (@coverage  - (rate * 0.5).clamp(0.0, 1.0)).clamp(0.0, 1.0)
end

#intensify!(rate = Constants::PRESSURE_CHANGE_RATE) ⇒ Object

Intensify: storm grows stronger



28
29
30
31
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/storm.rb', line 28

def intensify!(rate = Constants::PRESSURE_CHANGE_RATE)
  @intensity = (@intensity + rate.clamp(0.0, 1.0)).clamp(0.0, 1.0)
  @coverage  = (@coverage  + (rate * 0.5).clamp(0.0, 1.0)).clamp(0.0, 1.0)
end

#lightning_strike!(domain: nil) ⇒ Object

A lightning strike of sudden insight — random intensity, logged for audit



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/storm.rb', line 40

def lightning_strike!(domain: nil)
  insight_id = SecureRandom.uuid
  insight_intensity = rand.round(10)
  entry = {
    id:        insight_id,
    domain:    domain,
    intensity: insight_intensity,
    struck_at: Time.now.utc.iso8601
  }
  @insight_log << entry
  entry
end

#raging?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/storm.rb', line 53

def raging?
  @intensity >= 0.75
end

#to_hObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/storm.rb', line 66

def to_h
  {
    id:            @id,
    condition:     @condition,
    front_ids:     @front_ids,
    intensity:     @intensity.round(10),
    coverage:      @coverage.round(10),
    raging:        raging?,
    clearing:      clearing?,
    clarity:       clarity_label,
    insight_count: @insight_log.size,
    created_at:    @created_at.iso8601
  }
end