Class: Legion::Extensions::Agentic::Defense::Immunology::Helpers::Threat
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Defense::Immunology::Helpers::Threat
- Defined in:
- lib/legion/extensions/agentic/defense/immunology/helpers/threat.rb
Instance Attribute Summary collapse
-
#content_hash ⇒ Object
readonly
Returns the value of attribute content_hash.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#exposure_count ⇒ Object
Returns the value of attribute exposure_count.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#quarantined ⇒ Object
Returns the value of attribute quarantined.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#tactic ⇒ Object
readonly
Returns the value of attribute tactic.
-
#threat_level ⇒ Object
Returns the value of attribute threat_level.
Instance Method Summary collapse
- #escalate!(amount: 0.1) ⇒ Object
- #expose! ⇒ Object
-
#initialize(source:, tactic:, content_hash:, threat_level: 0.5) ⇒ Threat
constructor
A new instance of Threat.
- #quarantine! ⇒ Object
- #release! ⇒ Object
- #threat_label ⇒ Object
- #to_h ⇒ Object
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_hash ⇒ Object (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_at ⇒ Object (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_count ⇒ Object
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 |
#id ⇒ Object (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 |
#quarantined ⇒ Object
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 |
#source ⇒ Object (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 |
#tactic ⇒ Object (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_level ⇒ Object
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_label ⇒ Object
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_h ⇒ Object
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 |