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

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/integration/boundary/helpers/boundary_engine.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 Method Summary collapse

Constructor Details

#initializeBoundaryEngine

Returns a new instance of BoundaryEngine.



12
13
14
# File 'lib/legion/extensions/agentic/integration/boundary/helpers/boundary_engine.rb', line 12

def initialize
  @boundaries = {}
end

Instance Method Details

#boundaries_by_type(boundary_type:) ⇒ Object



67
68
69
70
# File 'lib/legion/extensions/agentic/integration/boundary/helpers/boundary_engine.rb', line 67

def boundaries_by_type(boundary_type:)
  bt = boundary_type.to_sym
  @boundaries.values.select { |b| b.boundary_type == bt }
end

#boundary_reportObject



90
91
92
93
94
95
96
97
98
# File 'lib/legion/extensions/agentic/integration/boundary/helpers/boundary_engine.rb', line 90

def boundary_report
  {
    total_boundaries:     @boundaries.size,
    breached_count:       breached_boundaries.size,
    overall_integrity:    overall_integrity,
    overall_permeability: overall_permeability,
    most_violated:        most_violated(limit: 3).map(&:to_h)
  }
end

#breached_boundariesObject



63
64
65
# File 'lib/legion/extensions/agentic/integration/boundary/helpers/boundary_engine.rb', line 63

def breached_boundaries
  @boundaries.values.select(&:breached?)
end

#close_boundary(boundary_id:, amount: PERMEABILITY_BOOST) ⇒ Object



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

def close_boundary(boundary_id:, amount: PERMEABILITY_BOOST)
  boundary = @boundaries[boundary_id]
  return nil unless boundary

  boundary.close!(amount: amount)
end

#create_boundary(name:, boundary_type: :cognitive, permeability: DEFAULT_PERMEABILITY) ⇒ Object



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

def create_boundary(name:, boundary_type: :cognitive,
                    permeability: DEFAULT_PERMEABILITY)
  prune_if_needed
  boundary = Boundary.new(
    name:          name,
    boundary_type: boundary_type,
    permeability:  permeability
  )
  @boundaries[boundary.id] = boundary
  boundary
end

#most_violated(limit: 5) ⇒ Object



72
73
74
# File 'lib/legion/extensions/agentic/integration/boundary/helpers/boundary_engine.rb', line 72

def most_violated(limit: 5)
  @boundaries.values.sort_by { |b| -b.violations }.first(limit)
end

#open_boundary(boundary_id:, amount: PERMEABILITY_BOOST) ⇒ Object



28
29
30
31
32
33
# File 'lib/legion/extensions/agentic/integration/boundary/helpers/boundary_engine.rb', line 28

def open_boundary(boundary_id:, amount: PERMEABILITY_BOOST)
  boundary = @boundaries[boundary_id]
  return nil unless boundary

  boundary.open!(amount: amount)
end

#overall_integrityObject



76
77
78
79
80
81
# File 'lib/legion/extensions/agentic/integration/boundary/helpers/boundary_engine.rb', line 76

def overall_integrity
  return 1.0 if @boundaries.empty?

  scores = @boundaries.values.map(&:integrity)
  (scores.sum / scores.size).round(10)
end

#overall_permeabilityObject



83
84
85
86
87
88
# File 'lib/legion/extensions/agentic/integration/boundary/helpers/boundary_engine.rb', line 83

def overall_permeability
  return 0.5 if @boundaries.empty?

  perms = @boundaries.values.map(&:permeability)
  (perms.sum / perms.size).round(10)
end

#repair_boundary(boundary_id:) ⇒ Object



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

def repair_boundary(boundary_id:)
  boundary = @boundaries[boundary_id]
  return nil unless boundary

  boundary.repair!
end

#seal_boundary(boundary_id:) ⇒ Object



56
57
58
59
60
61
# File 'lib/legion/extensions/agentic/integration/boundary/helpers/boundary_engine.rb', line 56

def seal_boundary(boundary_id:)
  boundary = @boundaries[boundary_id]
  return nil unless boundary

  boundary.seal!
end

#to_hObject



100
101
102
103
104
105
106
107
# File 'lib/legion/extensions/agentic/integration/boundary/helpers/boundary_engine.rb', line 100

def to_h
  {
    total_boundaries:     @boundaries.size,
    breached_count:       breached_boundaries.size,
    overall_integrity:    overall_integrity,
    overall_permeability: overall_permeability
  }
end

#violate_boundary(boundary_id:) ⇒ Object



42
43
44
45
46
47
# File 'lib/legion/extensions/agentic/integration/boundary/helpers/boundary_engine.rb', line 42

def violate_boundary(boundary_id:)
  boundary = @boundaries[boundary_id]
  return nil unless boundary

  boundary.violate!
end