Class: Legion::Extensions::Agentic::Attention::Lighthouse::Helpers::LighthouseEngine

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/attention/lighthouse/helpers/lighthouse_engine.rb

Instance Method Summary collapse

Constructor Details

#initializeLighthouseEngine

Returns a new instance of LighthouseEngine.



10
11
12
13
# File 'lib/legion/extensions/agentic/attention/lighthouse/helpers/lighthouse_engine.rb', line 10

def initialize
  @beacons   = {}
  @fog_banks = {}
end

Instance Method Details

#all_beaconsObject



90
91
92
# File 'lib/legion/extensions/agentic/attention/lighthouse/helpers/lighthouse_engine.rb', line 90

def all_beacons
  @beacons.values
end

#all_fog_banksObject



94
95
96
# File 'lib/legion/extensions/agentic/attention/lighthouse/helpers/lighthouse_engine.rb', line 94

def all_fog_banks
  @fog_banks.values
end

#brightest_beacons(limit: 5) ⇒ Object



59
60
61
62
63
64
# File 'lib/legion/extensions/agentic/attention/lighthouse/helpers/lighthouse_engine.rb', line 59

def brightest_beacons(limit: 5)
  @beacons.values
          .reject(&:extinguished?)
          .sort_by { |b| -b.luminosity }
          .first(limit)
end

#create_fog(fog_type:, domain:, density: nil, extent: nil) ⇒ Object

Raises:

  • (ArgumentError)


29
30
31
32
33
34
35
# File 'lib/legion/extensions/agentic/attention/lighthouse/helpers/lighthouse_engine.rb', line 29

def create_fog(fog_type:, domain:, density: nil, extent: nil)
  raise ArgumentError, 'too many fog banks' if @fog_banks.size >= Constants::MAX_FOG_BANKS

  fog = Fog.new(fog_type: fog_type, domain: domain, density: density, extent: extent)
  @fog_banks[fog.id] = fog
  fog
end

#densest_fogs(limit: 5) ⇒ Object



66
67
68
69
70
# File 'lib/legion/extensions/agentic/attention/lighthouse/helpers/lighthouse_engine.rb', line 66

def densest_fogs(limit: 5)
  @fog_banks.values
            .sort_by { |f| -f.density }
            .first(limit)
end

#dim_all!(rate: Constants::LUMINOSITY_RATE) ⇒ Object



47
48
49
50
51
52
# File 'lib/legion/extensions/agentic/attention/lighthouse/helpers/lighthouse_engine.rb', line 47

def dim_all!(rate: Constants::LUMINOSITY_RATE)
  @beacons.each_value { |b| b.dim!(rate: rate) }
  pruned = @beacons.select { |_, b| b.extinguished? }.keys
  pruned.each { |id| @beacons.delete(id) }
  { remaining: @beacons.size, pruned: pruned.size }
end

#light_beacon(beacon_type:, domain:, content:, luminosity: nil, sweep_angle: nil) ⇒ Object

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/legion/extensions/agentic/attention/lighthouse/helpers/lighthouse_engine.rb', line 15

def light_beacon(beacon_type:, domain:, content:, luminosity: nil, sweep_angle: nil)
  raise ArgumentError, 'too many beacons' if @beacons.size >= Constants::MAX_BEACONS

  beacon = Beacon.new(
    beacon_type: beacon_type,
    domain:      domain,
    content:     content,
    luminosity:  luminosity,
    sweep_angle: sweep_angle
  )
  @beacons[beacon.id] = beacon
  beacon
end

#sweep(beacon_id:, fog_id:) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/legion/extensions/agentic/attention/lighthouse/helpers/lighthouse_engine.rb', line 37

def sweep(beacon_id:, fog_id:)
  beacon = fetch_beacon(beacon_id)
  fog    = fetch_fog(fog_id)

  reduction = (beacon.luminosity * 0.5).round(10)
  fog.disperse!(rate: reduction)

  { beacon: beacon.to_h, fog: fog.to_h, reduction: reduction }
end

#thicken_all!(rate: Constants::FOG_DENSITY_RATE) ⇒ Object



54
55
56
57
# File 'lib/legion/extensions/agentic/attention/lighthouse/helpers/lighthouse_engine.rb', line 54

def thicken_all!(rate: Constants::FOG_DENSITY_RATE)
  @fog_banks.each_value { |f| f.thicken!(rate: rate) }
  { fog_banks: @fog_banks.size }
end

#visibility_reportObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/legion/extensions/agentic/attention/lighthouse/helpers/lighthouse_engine.rb', line 72

def visibility_report
  avg_luminosity = compute_average_luminosity
  avg_density    = compute_average_density
  net_visibility = (avg_luminosity - avg_density).clamp(0.0, 1.0).round(10)

  {
    total_beacons:    @beacons.size,
    total_fog_banks:  @fog_banks.size,
    avg_luminosity:   avg_luminosity,
    avg_density:      avg_density,
    net_visibility:   net_visibility,
    blazing_beacons:  @beacons.count { |_, b| b.blazing? },
    extinguished:     @beacons.count { |_, b| b.extinguished? },
    impenetrable_fog: @fog_banks.count { |_, f| f.impenetrable? },
    clearing_fog:     @fog_banks.count { |_, f| f.clearing? }
  }
end