Class: Legion::Extensions::Agentic::Defense::Phantom::Helpers::PhantomLimb

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

Constant Summary collapse

ADAPT_DECAY_MULTIPLIER =
2.5

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(capability_name:, capability_domain:) ⇒ PhantomLimb

Returns a new instance of PhantomLimb.



17
18
19
20
21
22
23
24
25
26
# File 'lib/legion/extensions/agentic/defense/phantom/helpers/phantom_limb.rb', line 17

def initialize(capability_name:, capability_domain:)
  @id                 = SecureRandom.uuid
  @capability_name    = capability_name
  @capability_domain  = capability_domain
  @removed_at         = Time.now.utc
  @intensity          = Constants::INITIAL_INTENSITY
  @activation_count   = 0
  @last_triggered     = nil
  @trigger_history    = []
end

Instance Attribute Details

#activation_countObject (readonly)

Returns the value of attribute activation_count.



14
15
16
# File 'lib/legion/extensions/agentic/defense/phantom/helpers/phantom_limb.rb', line 14

def activation_count
  @activation_count
end

#capability_domainObject (readonly)

Returns the value of attribute capability_domain.



14
15
16
# File 'lib/legion/extensions/agentic/defense/phantom/helpers/phantom_limb.rb', line 14

def capability_domain
  @capability_domain
end

#capability_nameObject (readonly)

Returns the value of attribute capability_name.



14
15
16
# File 'lib/legion/extensions/agentic/defense/phantom/helpers/phantom_limb.rb', line 14

def capability_name
  @capability_name
end

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'lib/legion/extensions/agentic/defense/phantom/helpers/phantom_limb.rb', line 14

def id
  @id
end

#last_triggeredObject (readonly)

Returns the value of attribute last_triggered.



14
15
16
# File 'lib/legion/extensions/agentic/defense/phantom/helpers/phantom_limb.rb', line 14

def last_triggered
  @last_triggered
end

#removed_atObject (readonly)

Returns the value of attribute removed_at.



14
15
16
# File 'lib/legion/extensions/agentic/defense/phantom/helpers/phantom_limb.rb', line 14

def removed_at
  @removed_at
end

#trigger_historyObject (readonly)

Returns the value of attribute trigger_history.



14
15
16
# File 'lib/legion/extensions/agentic/defense/phantom/helpers/phantom_limb.rb', line 14

def trigger_history
  @trigger_history
end

Instance Method Details

#adapt!Object



61
62
63
64
65
66
# File 'lib/legion/extensions/agentic/defense/phantom/helpers/phantom_limb.rb', line 61

def adapt!
  return if resolved?

  accelerated = Constants::INTENSITY_DECAY * ADAPT_DECAY_MULTIPLIER
  @intensity  = (@intensity - accelerated).clamp(Constants::MIN_INTENSITY, 1.0)
end

#decay!Object



55
56
57
58
59
# File 'lib/legion/extensions/agentic/defense/phantom/helpers/phantom_limb.rb', line 55

def decay!
  return if resolved?

  @intensity = (@intensity - Constants::INTENSITY_DECAY).clamp(Constants::MIN_INTENSITY, 1.0)
end

#intensityObject



28
29
30
# File 'lib/legion/extensions/agentic/defense/phantom/helpers/phantom_limb.rb', line 28

def intensity
  @intensity.round(10)
end

#resolved?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/legion/extensions/agentic/defense/phantom/helpers/phantom_limb.rb', line 68

def resolved?
  @intensity <= Constants::MIN_INTENSITY
end

#stateObject



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

def state
  Constants.state_for(@intensity)
end

#to_hObject



72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/legion/extensions/agentic/defense/phantom/helpers/phantom_limb.rb', line 72

def to_h
  {
    id:                @id,
    capability_name:   @capability_name,
    capability_domain: @capability_domain,
    removed_at:        @removed_at,
    intensity:         intensity,
    activation_count:  @activation_count,
    last_triggered:    @last_triggered,
    state:             state,
    resolved:          resolved?
  }
end

#trigger!(stimulus) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/legion/extensions/agentic/defense/phantom/helpers/phantom_limb.rb', line 36

def trigger!(stimulus)
  return false if resolved?

  @activation_count += 1
  prev_triggered = @last_triggered
  @last_triggered = Time.now.utc
  signal = PhantomSignal.new(
    phantom_limb_id:      @id,
    stimulus:             stimulus,
    trigger_type:         classify_trigger(stimulus, prev_triggered),
    intensity_at_trigger: @intensity
  )
  @trigger_history << signal
  @trigger_history.shift while @trigger_history.size > 50
  boost = (@intensity * 0.05).clamp(0.0, 0.1)
  @intensity = (@intensity + boost).clamp(Constants::MIN_INTENSITY, 1.0)
  signal
end