Class: Legion::Extensions::Agentic::Defense::Immunology::Helpers::Threat

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source:, tactic:, content_hash:, threat_level: 0.5) ⇒ Threat

Returns a new instance of Threat.



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

def initialize(source:, tactic:, content_hash:, threat_level: 0.5)
  @id             = SecureRandom.uuid
  @source         = source
  @tactic         = tactic
  @content_hash   = content_hash
  @threat_level   = threat_level.clamp(0.0, 1.0)
  @quarantined    = false
  @exposure_count = 0
  @created_at     = Time.now.utc
end

Instance Attribute Details

#content_hashObject (readonly)

Returns the value of attribute content_hash.



12
13
14
# File 'lib/legion/extensions/agentic/defense/immunology/helpers/threat.rb', line 12

def content_hash
  @content_hash
end

#created_atObject (readonly)

Returns the value of attribute created_at.



12
13
14
# File 'lib/legion/extensions/agentic/defense/immunology/helpers/threat.rb', line 12

def created_at
  @created_at
end

#exposure_countObject

Returns the value of attribute exposure_count.



13
14
15
# File 'lib/legion/extensions/agentic/defense/immunology/helpers/threat.rb', line 13

def exposure_count
  @exposure_count
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/legion/extensions/agentic/defense/immunology/helpers/threat.rb', line 12

def id
  @id
end

#quarantinedObject

Returns the value of attribute quarantined.



13
14
15
# File 'lib/legion/extensions/agentic/defense/immunology/helpers/threat.rb', line 13

def quarantined
  @quarantined
end

#sourceObject (readonly)

Returns the value of attribute source.



12
13
14
# File 'lib/legion/extensions/agentic/defense/immunology/helpers/threat.rb', line 12

def source
  @source
end

#tacticObject (readonly)

Returns the value of attribute tactic.



12
13
14
# File 'lib/legion/extensions/agentic/defense/immunology/helpers/threat.rb', line 12

def tactic
  @tactic
end

#threat_levelObject

Returns the value of attribute threat_level.



13
14
15
# File 'lib/legion/extensions/agentic/defense/immunology/helpers/threat.rb', line 13

def threat_level
  @threat_level
end

Instance Method Details

#escalate!(amount: 0.1) ⇒ Object



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

def escalate!(amount: 0.1)
  @threat_level = (@threat_level + amount).clamp(0.0, 1.0).round(10)
end

#expose!Object



38
39
40
41
42
# File 'lib/legion/extensions/agentic/defense/immunology/helpers/threat.rb', line 38

def expose!
  @exposure_count += 1
  reduction = (0.05 / (@exposure_count + 1)).round(10)
  @threat_level = (@threat_level - reduction).clamp(0.0, 1.0).round(10)
end

#quarantine!Object



30
31
32
# File 'lib/legion/extensions/agentic/defense/immunology/helpers/threat.rb', line 30

def quarantine!
  @quarantined = true
end

#release!Object



34
35
36
# File 'lib/legion/extensions/agentic/defense/immunology/helpers/threat.rb', line 34

def release!
  @quarantined = false
end

#threat_labelObject



26
27
28
# File 'lib/legion/extensions/agentic/defense/immunology/helpers/threat.rb', line 26

def threat_label
  Constants::THREAT_LABELS.find { |range, _| range.cover?(@threat_level) }&.last || :negligible
end

#to_hObject



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

def to_h
  {
    id:             @id,
    source:         @source,
    tactic:         @tactic,
    content_hash:   @content_hash,
    threat_level:   @threat_level,
    threat_label:   threat_label,
    quarantined:    @quarantined,
    exposure_count: @exposure_count,
    created_at:     @created_at
  }
end