Class: Legion::Extensions::Agentic::Integration::Boundary::Helpers::Boundary

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/integration/boundary/helpers/boundary.rb

Constant Summary

Constants included from Constants

Constants::BOUNDARY_TYPES, Constants::BREACH_THRESHOLD, Constants::DEFAULT_PERMEABILITY, Constants::INTEGRITY_LABELS, Constants::MAX_BOUNDARIES, Constants::MAX_VIOLATIONS, Constants::PERMEABILITY_BOOST, Constants::PERMEABILITY_DECAY, Constants::PERMEABILITY_LABELS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, boundary_type: :cognitive, permeability: DEFAULT_PERMEABILITY) ⇒ Boundary

Returns a new instance of Boundary.



17
18
19
20
21
22
23
24
# File 'lib/legion/extensions/agentic/integration/boundary/helpers/boundary.rb', line 17

def initialize(name:, boundary_type: :cognitive, permeability: DEFAULT_PERMEABILITY)
  @id           = SecureRandom.uuid
  @name         = name
  @boundary_type = boundary_type.to_sym
  @permeability = permeability.to_f.clamp(0.0, 1.0)
  @violations   = 0
  @created_at   = Time.now.utc
end

Instance Attribute Details

#boundary_typeObject (readonly)

Returns the value of attribute boundary_type.



14
15
16
# File 'lib/legion/extensions/agentic/integration/boundary/helpers/boundary.rb', line 14

def boundary_type
  @boundary_type
end

#created_atObject (readonly)

Returns the value of attribute created_at.



14
15
16
# File 'lib/legion/extensions/agentic/integration/boundary/helpers/boundary.rb', line 14

def created_at
  @created_at
end

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'lib/legion/extensions/agentic/integration/boundary/helpers/boundary.rb', line 14

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



14
15
16
# File 'lib/legion/extensions/agentic/integration/boundary/helpers/boundary.rb', line 14

def name
  @name
end

#permeabilityObject (readonly)

Returns the value of attribute permeability.



14
15
16
# File 'lib/legion/extensions/agentic/integration/boundary/helpers/boundary.rb', line 14

def permeability
  @permeability
end

#violationsObject (readonly)

Returns the value of attribute violations.



14
15
16
# File 'lib/legion/extensions/agentic/integration/boundary/helpers/boundary.rb', line 14

def violations
  @violations
end

Instance Method Details

#breached?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/legion/extensions/agentic/integration/boundary/helpers/boundary.rb', line 41

def breached?
  @permeability >= BREACH_THRESHOLD || integrity < 0.2
end

#close!(amount: PERMEABILITY_BOOST) ⇒ Object



50
51
52
53
# File 'lib/legion/extensions/agentic/integration/boundary/helpers/boundary.rb', line 50

def close!(amount: PERMEABILITY_BOOST)
  @permeability = (@permeability - amount).clamp(0.0, 1.0).round(10)
  self
end

#integrityObject



26
27
28
29
# File 'lib/legion/extensions/agentic/integration/boundary/helpers/boundary.rb', line 26

def integrity
  base = 1.0 - (@violations * 0.05)
  [base, 0.0].max.round(10)
end

#integrity_labelObject



31
32
33
34
# File 'lib/legion/extensions/agentic/integration/boundary/helpers/boundary.rb', line 31

def integrity_label
  match = INTEGRITY_LABELS.find { |range, _| range.cover?(integrity) }
  match ? match.last : :breached
end

#open!(amount: PERMEABILITY_BOOST) ⇒ Object



45
46
47
48
# File 'lib/legion/extensions/agentic/integration/boundary/helpers/boundary.rb', line 45

def open!(amount: PERMEABILITY_BOOST)
  @permeability = (@permeability + amount).clamp(0.0, 1.0).round(10)
  self
end

#permeability_labelObject



36
37
38
39
# File 'lib/legion/extensions/agentic/integration/boundary/helpers/boundary.rb', line 36

def permeability_label
  match = PERMEABILITY_LABELS.find { |range, _| range.cover?(@permeability) }
  match ? match.last : :sealed
end

#repair!Object



60
61
62
63
# File 'lib/legion/extensions/agentic/integration/boundary/helpers/boundary.rb', line 60

def repair!
  @violations = [(@violations - 1), 0].max
  self
end

#seal!Object



65
66
67
68
# File 'lib/legion/extensions/agentic/integration/boundary/helpers/boundary.rb', line 65

def seal!
  @permeability = 0.0
  self
end

#to_hObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/legion/extensions/agentic/integration/boundary/helpers/boundary.rb', line 70

def to_h
  {
    id:                 @id,
    name:               @name,
    boundary_type:      @boundary_type,
    permeability:       @permeability,
    permeability_label: permeability_label,
    integrity:          integrity,
    integrity_label:    integrity_label,
    breached:           breached?,
    violations:         @violations,
    created_at:         @created_at
  }
end

#violate!Object



55
56
57
58
# File 'lib/legion/extensions/agentic/integration/boundary/helpers/boundary.rb', line 55

def violate!
  @violations += 1
  self
end