Class: Legion::Extensions::Agentic::Memory::Paleontology::Helpers::PaleontologyEngine
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Memory::Paleontology::Helpers::PaleontologyEngine
- Defined in:
- lib/legion/extensions/agentic/memory/paleontology/helpers/paleontology_engine.rb
Instance Method Summary collapse
- #all_excavations ⇒ Object
- #all_fossils ⇒ Object
- #begin_excavation(target_stratum:) ⇒ Object
- #complete_excavation(excavation_id:) ⇒ Object
- #erode_all!(rate: Constants::FOSSILIZATION_RATE) ⇒ Object
- #excavate!(excavation_id:) ⇒ Object
- #extinction_timeline ⇒ Object
- #fossils_by_cause(cause) ⇒ Object
- #fossils_by_era(era) ⇒ Object
- #fossils_by_type(fossil_type) ⇒ Object
-
#initialize ⇒ PaleontologyEngine
constructor
A new instance of PaleontologyEngine.
- #keystone_fossils(limit: 10) ⇒ Object
- #link_lineage(fossil_id:, ancestor_id:) ⇒ Object
- #mass_extinction?(threshold: 5, window: 60) ⇒ Boolean
- #paleontology_report ⇒ Object
- #record_extinction(fossil_type:, domain:, content:, extinction_cause:, stratum_depth: 0, significance: nil) ⇒ Object
Constructor Details
#initialize ⇒ PaleontologyEngine
Returns a new instance of PaleontologyEngine.
10 11 12 13 14 |
# File 'lib/legion/extensions/agentic/memory/paleontology/helpers/paleontology_engine.rb', line 10 def initialize @fossils = {} @excavations = {} @extinction_log = [] end |
Instance Method Details
#all_excavations ⇒ Object
104 105 106 |
# File 'lib/legion/extensions/agentic/memory/paleontology/helpers/paleontology_engine.rb', line 104 def all_excavations @excavations.values end |
#all_fossils ⇒ Object
100 101 102 |
# File 'lib/legion/extensions/agentic/memory/paleontology/helpers/paleontology_engine.rb', line 100 def all_fossils @fossils.values end |
#begin_excavation(target_stratum:) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/legion/extensions/agentic/memory/paleontology/helpers/paleontology_engine.rb', line 33 def begin_excavation(target_stratum:) validate_capacity!(:excavations, Constants::MAX_EXCAVATIONS) exc = Excavation.new(target_stratum: target_stratum) @excavations[exc.id] = exc exc end |
#complete_excavation(excavation_id:) ⇒ Object
52 53 54 55 56 |
# File 'lib/legion/extensions/agentic/memory/paleontology/helpers/paleontology_engine.rb', line 52 def complete_excavation(excavation_id:) exc = fetch_excavation!(excavation_id) exc.complete! exc end |
#erode_all!(rate: Constants::FOSSILIZATION_RATE) ⇒ Object
58 59 60 61 62 |
# File 'lib/legion/extensions/agentic/memory/paleontology/helpers/paleontology_engine.rb', line 58 def erode_all!(rate: Constants::FOSSILIZATION_RATE) @fossils.each_value { |f| f.erode!(rate: rate) } prune_imprints! @fossils.size end |
#excavate!(excavation_id:) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/legion/extensions/agentic/memory/paleontology/helpers/paleontology_engine.rb', line 40 def excavate!(excavation_id:) exc = fetch_excavation!(excavation_id) raise ArgumentError, 'excavation already completed' if exc.completed? matching = stratum_fossils(exc.target_stratum) return nil if matching.empty? fossil = matching.sample exc.record_find!(fossil) fossil end |
#extinction_timeline ⇒ Object
90 91 92 |
# File 'lib/legion/extensions/agentic/memory/paleontology/helpers/paleontology_engine.rb', line 90 def extinction_timeline @extinction_log.sort_by { |e| e[:at] } end |
#fossils_by_cause(cause) ⇒ Object
75 76 77 |
# File 'lib/legion/extensions/agentic/memory/paleontology/helpers/paleontology_engine.rb', line 75 def fossils_by_cause(cause) @fossils.values.select { |f| f.extinction_cause == cause.to_sym } end |
#fossils_by_era(era) ⇒ Object
79 80 81 |
# File 'lib/legion/extensions/agentic/memory/paleontology/helpers/paleontology_engine.rb', line 79 def fossils_by_era(era) @fossils.values.select { |f| f.era == era.to_sym } end |
#fossils_by_type(fossil_type) ⇒ Object
71 72 73 |
# File 'lib/legion/extensions/agentic/memory/paleontology/helpers/paleontology_engine.rb', line 71 def fossils_by_type(fossil_type) @fossils.values.select { |f| f.fossil_type == fossil_type.to_sym } end |
#keystone_fossils(limit: 10) ⇒ Object
83 84 85 86 87 88 |
# File 'lib/legion/extensions/agentic/memory/paleontology/helpers/paleontology_engine.rb', line 83 def keystone_fossils(limit: 10) @fossils.values .select(&:keystone?) .sort_by { |f| -f.significance } .first(limit) end |
#link_lineage(fossil_id:, ancestor_id:) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/legion/extensions/agentic/memory/paleontology/helpers/paleontology_engine.rb', line 64 def link_lineage(fossil_id:, ancestor_id:) fossil = fetch_fossil!(fossil_id) fetch_fossil!(ancestor_id) fossil.link_lineage(ancestor_id) fossil end |
#mass_extinction?(threshold: 5, window: 60) ⇒ Boolean
94 95 96 97 98 |
# File 'lib/legion/extensions/agentic/memory/paleontology/helpers/paleontology_engine.rb', line 94 def mass_extinction?(threshold: 5, window: 60) cutoff = Time.now.utc - window recent = @extinction_log.count { |e| e[:at] >= cutoff } recent >= threshold end |
#paleontology_report ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/legion/extensions/agentic/memory/paleontology/helpers/paleontology_engine.rb', line 108 def paleontology_report { total_fossils: @fossils.size, total_excavations: @excavations.size, type_breakdown: count_by(:fossil_type, Constants::FOSSIL_TYPES), cause_breakdown: count_by(:extinction_cause, Constants::EXTINCTION_CAUSES), era_breakdown: count_by(:era, Constants::ERA_NAMES), avg_preservation: avg_field(:preservation), avg_significance: avg_field(:significance), keystone_count: @fossils.values.count(&:keystone?), imprint_count: @fossils.values.count(&:imprint?), ancient_count: @fossils.values.count(&:ancient?), mass_extinction: mass_extinction? } end |
#record_extinction(fossil_type:, domain:, content:, extinction_cause:, stratum_depth: 0, significance: nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/legion/extensions/agentic/memory/paleontology/helpers/paleontology_engine.rb', line 16 def record_extinction(fossil_type:, domain:, content:, extinction_cause:, stratum_depth: 0, significance: nil, **) validate_capacity!(:fossils, Constants::MAX_FOSSILS) fossil = Fossil.new( fossil_type: fossil_type, domain: domain, content: content, extinction_cause: extinction_cause, stratum_depth: stratum_depth, significance: significance ) @fossils[fossil.id] = fossil @extinction_log << { fossil_id: fossil.id, at: Time.now.utc } fossil end |