Class: Legion::Extensions::Agentic::Memory::Archaeology::Helpers::Artifact
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Memory::Archaeology::Helpers::Artifact
- Defined in:
- lib/legion/extensions/agentic/memory/archaeology/helpers/artifact.rb
Instance Attribute Summary collapse
-
#artifact_type ⇒ Object
(also: #type)
readonly
Returns the value of attribute artifact_type.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#contextual_links ⇒ Object
readonly
Returns the value of attribute contextual_links.
-
#depth_level ⇒ Object
readonly
Returns the value of attribute depth_level.
-
#discovered_at ⇒ Object
readonly
Returns the value of attribute discovered_at.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#integrity ⇒ Object
Returns the value of attribute integrity.
-
#origin_epoch ⇒ Object
readonly
Returns the value of attribute origin_epoch.
-
#preservation_quality ⇒ Object
Returns the value of attribute preservation_quality.
Instance Method Summary collapse
- #ancient? ⇒ Boolean
- #decay!(rate: Constants::PRESERVATION_DECAY) ⇒ Object
- #fragment? ⇒ Boolean
-
#initialize(type:, domain:, content:, depth_level:, preservation: nil, integrity: nil, origin_epoch: nil, contextual_links: nil) ⇒ Artifact
constructor
A new instance of Artifact.
- #integrity_label ⇒ Object
- #link_to(other_id) ⇒ Object
- #preservation ⇒ Object
- #preservation=(val) ⇒ Object
- #preservation_label ⇒ Object
- #restore!(boost: 0.15) ⇒ Object
- #to_h ⇒ Object
- #well_preserved? ⇒ Boolean
Constructor Details
#initialize(type:, domain:, content:, depth_level:, preservation: nil, integrity: nil, origin_epoch: nil, contextual_links: nil) ⇒ Artifact
Returns a new instance of Artifact.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/legion/extensions/agentic/memory/archaeology/helpers/artifact.rb', line 19 def initialize(type:, domain:, content:, depth_level:, preservation: nil, integrity: nil, origin_epoch: nil, contextual_links: nil) validate_type!(type) validate_domain!(domain) validate_depth!(depth_level) @id = SecureRandom.uuid @artifact_type = type.to_sym @domain = domain.to_sym @content = content.to_s @depth_level = depth_level.to_sym pres = (preservation || Constants::DEFAULT_PRESERVATION).to_f @preservation_quality = pres.clamp(0.0, 1.0).round(10) @integrity = (integrity || derive_integrity).clamp(0.0, 1.0).round(10) @discovered_at = Time.now.utc @origin_epoch = origin_epoch || (Time.now.utc - rand(0..31_536_000)) @contextual_links = Array(contextual_links).dup end |
Instance Attribute Details
#artifact_type ⇒ Object (readonly) Also known as: type
Returns the value of attribute artifact_type.
12 13 14 |
# File 'lib/legion/extensions/agentic/memory/archaeology/helpers/artifact.rb', line 12 def artifact_type @artifact_type end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
12 13 14 |
# File 'lib/legion/extensions/agentic/memory/archaeology/helpers/artifact.rb', line 12 def content @content end |
#contextual_links ⇒ Object (readonly)
Returns the value of attribute contextual_links.
12 13 14 |
# File 'lib/legion/extensions/agentic/memory/archaeology/helpers/artifact.rb', line 12 def contextual_links @contextual_links end |
#depth_level ⇒ Object (readonly)
Returns the value of attribute depth_level.
12 13 14 |
# File 'lib/legion/extensions/agentic/memory/archaeology/helpers/artifact.rb', line 12 def depth_level @depth_level end |
#discovered_at ⇒ Object (readonly)
Returns the value of attribute discovered_at.
12 13 14 |
# File 'lib/legion/extensions/agentic/memory/archaeology/helpers/artifact.rb', line 12 def discovered_at @discovered_at end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
12 13 14 |
# File 'lib/legion/extensions/agentic/memory/archaeology/helpers/artifact.rb', line 12 def domain @domain end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
12 13 14 |
# File 'lib/legion/extensions/agentic/memory/archaeology/helpers/artifact.rb', line 12 def id @id end |
#integrity ⇒ Object
Returns the value of attribute integrity.
15 16 17 |
# File 'lib/legion/extensions/agentic/memory/archaeology/helpers/artifact.rb', line 15 def integrity @integrity end |
#origin_epoch ⇒ Object (readonly)
Returns the value of attribute origin_epoch.
12 13 14 |
# File 'lib/legion/extensions/agentic/memory/archaeology/helpers/artifact.rb', line 12 def origin_epoch @origin_epoch end |
#preservation_quality ⇒ Object
Returns the value of attribute preservation_quality.
15 16 17 |
# File 'lib/legion/extensions/agentic/memory/archaeology/helpers/artifact.rb', line 15 def preservation_quality @preservation_quality end |
Instance Method Details
#ancient? ⇒ Boolean
67 68 69 |
# File 'lib/legion/extensions/agentic/memory/archaeology/helpers/artifact.rb', line 67 def ancient? (Time.now.utc - @origin_epoch) > 15_552_000 end |
#decay!(rate: Constants::PRESERVATION_DECAY) ⇒ Object
47 48 49 50 51 |
# File 'lib/legion/extensions/agentic/memory/archaeology/helpers/artifact.rb', line 47 def decay!(rate: Constants::PRESERVATION_DECAY) @preservation_quality = (@preservation_quality - rate.abs).clamp(0.0, 1.0).round(10) @integrity = (@integrity - (rate.abs * 0.5)).clamp(0.0, 1.0).round(10) self end |
#fragment? ⇒ Boolean
59 60 61 |
# File 'lib/legion/extensions/agentic/memory/archaeology/helpers/artifact.rb', line 59 def fragment? @preservation_quality < 0.3 end |
#integrity_label ⇒ Object
75 76 77 |
# File 'lib/legion/extensions/agentic/memory/archaeology/helpers/artifact.rb', line 75 def integrity_label match_label(Constants::INTEGRITY_LABELS, @integrity) end |
#link_to(other_id) ⇒ Object
79 80 81 |
# File 'lib/legion/extensions/agentic/memory/archaeology/helpers/artifact.rb', line 79 def link_to(other_id) @contextual_links << other_id unless @contextual_links.include?(other_id) end |
#preservation ⇒ Object
39 40 41 |
# File 'lib/legion/extensions/agentic/memory/archaeology/helpers/artifact.rb', line 39 def preservation @preservation_quality end |
#preservation=(val) ⇒ Object
43 44 45 |
# File 'lib/legion/extensions/agentic/memory/archaeology/helpers/artifact.rb', line 43 def preservation=(val) @preservation_quality = val.to_f.clamp(0.0, 1.0).round(10) end |
#preservation_label ⇒ Object
71 72 73 |
# File 'lib/legion/extensions/agentic/memory/archaeology/helpers/artifact.rb', line 71 def preservation_label match_label(Constants::PRESERVATION_LABELS, @preservation_quality) end |
#restore!(boost: 0.15) ⇒ Object
53 54 55 56 57 |
# File 'lib/legion/extensions/agentic/memory/archaeology/helpers/artifact.rb', line 53 def restore!(boost: 0.15) @preservation_quality = (@preservation_quality + boost.abs).clamp(0.0, 1.0).round(10) @integrity = (@integrity + (boost.abs * 0.5)).clamp(0.0, 1.0).round(10) self end |
#to_h ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/legion/extensions/agentic/memory/archaeology/helpers/artifact.rb', line 83 def to_h { id: @id, type: @artifact_type, artifact_type: @artifact_type, domain: @domain, content: @content, depth_level: @depth_level, preservation: @preservation_quality, preservation_quality: @preservation_quality, preservation_label: preservation_label, integrity: @integrity, integrity_label: integrity_label, discovered_at: @discovered_at, origin_epoch: @origin_epoch, contextual_links: @contextual_links, fragment: fragment?, well_preserved: well_preserved?, ancient: ancient? } end |
#well_preserved? ⇒ Boolean
63 64 65 |
# File 'lib/legion/extensions/agentic/memory/archaeology/helpers/artifact.rb', line 63 def well_preserved? @preservation_quality > 0.7 end |