Class: Legion::Extensions::Agentic::Integration::Tapestry::Helpers::Tapestry
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Integration::Tapestry::Helpers::Tapestry
- Defined in:
- lib/legion/extensions/agentic/integration/tapestry/helpers/tapestry.rb
Instance Attribute Summary collapse
-
#capacity ⇒ Object
readonly
Returns the value of attribute capacity.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
-
#thread_ids ⇒ Object
readonly
Returns the value of attribute thread_ids.
Instance Method Summary collapse
- #age!(fray_rate: Constants::FRAY_RATE) ⇒ Object
- #coherence_score(threads) ⇒ Object
- #completeness ⇒ Object
- #completeness_label ⇒ Object
- #complexity_label(threads) ⇒ Object
- #empty? ⇒ Boolean
- #fraying?(threads) ⇒ Boolean
- #full? ⇒ Boolean
- #gap_count ⇒ Object
-
#initialize(name:, pattern:, capacity: 50) ⇒ Tapestry
constructor
A new instance of Tapestry.
- #masterwork?(threads) ⇒ Boolean
- #repair!(boost: 0.1) ⇒ Object
- #size ⇒ Object
- #to_h(threads = []) ⇒ Object
- #unravel_thread(thread_id) ⇒ Object
- #weave_thread(thread_id) ⇒ Object
Constructor Details
#initialize(name:, pattern:, capacity: 50) ⇒ Tapestry
Returns a new instance of Tapestry.
12 13 14 15 16 17 18 19 20 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/tapestry.rb', line 12 def initialize(name:, pattern:, capacity: 50) validate_pattern!(pattern) @id = SecureRandom.uuid @name = name.to_s @pattern = pattern.to_sym @capacity = capacity.to_i.clamp(1, 500) @thread_ids = [] @created_at = Time.now.utc end |
Instance Attribute Details
#capacity ⇒ Object (readonly)
Returns the value of attribute capacity.
10 11 12 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/tapestry.rb', line 10 def capacity @capacity end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
10 11 12 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/tapestry.rb', line 10 def created_at @created_at end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
10 11 12 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/tapestry.rb', line 10 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/tapestry.rb', line 10 def name @name end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
10 11 12 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/tapestry.rb', line 10 def pattern @pattern end |
#thread_ids ⇒ Object (readonly)
Returns the value of attribute thread_ids.
10 11 12 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/tapestry.rb', line 10 def thread_ids @thread_ids end |
Instance Method Details
#age!(fray_rate: Constants::FRAY_RATE) ⇒ Object
52 53 54 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/tapestry.rb', line 52 def age!(fray_rate: Constants::FRAY_RATE) fray_rate end |
#coherence_score(threads) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/tapestry.rb', line 74 def coherence_score(threads) return 0.0 if empty? placed = threads.select { |t| @thread_ids.include?(t.id) } return 0.0 if placed.empty? type_diversity = placed.map(&:thread_type).uniq.size.to_f / Constants::THREAD_TYPES.size avg_str = placed.sum(&:strength) / placed.size pattern_bonus = pattern_coherence_factor ((avg_str * 0.5) + (type_diversity * 0.3) + (pattern_bonus * 0.2)).clamp(0.0, 1.0).round(10) end |
#completeness ⇒ Object
46 47 48 49 50 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/tapestry.rb', line 46 def completeness return 0.0 if @capacity.zero? (@thread_ids.size.to_f / @capacity).clamp(0.0, 1.0).round(10) end |
#completeness_label ⇒ Object
86 87 88 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/tapestry.rb', line 86 def completeness_label Constants.label_for(Constants::INTEGRITY_LABELS, completeness) end |
#complexity_label(threads) ⇒ Object
90 91 92 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/tapestry.rb', line 90 def complexity_label(threads) Constants.label_for(Constants::COMPLEXITY_LABELS, coherence_score(threads)) end |
#empty? ⇒ Boolean
42 43 44 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/tapestry.rb', line 42 def empty? @thread_ids.empty? end |
#fraying?(threads) ⇒ Boolean
60 61 62 63 64 65 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/tapestry.rb', line 60 def (threads) return false if empty? avg = average_strength(threads) avg < 0.3 end |
#full? ⇒ Boolean
38 39 40 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/tapestry.rb', line 38 def full? @thread_ids.size >= @capacity end |
#gap_count ⇒ Object
94 95 96 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/tapestry.rb', line 94 def gap_count @capacity - @thread_ids.size end |
#masterwork?(threads) ⇒ Boolean
67 68 69 70 71 72 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/tapestry.rb', line 67 def masterwork?(threads) return false if empty? avg = average_strength(threads) avg >= 0.9 && completeness >= 0.9 end |
#repair!(boost: 0.1) ⇒ Object
56 57 58 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/tapestry.rb', line 56 def repair!(boost: 0.1) boost end |
#size ⇒ Object
34 35 36 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/tapestry.rb', line 34 def size @thread_ids.size end |
#to_h(threads = []) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/tapestry.rb', line 98 def to_h(threads = []) { id: @id, name: @name, pattern: @pattern, capacity: @capacity, size: size, completeness: completeness, completeness_label: completeness_label, coherence_score: coherence_score(threads), gap_count: gap_count, full: full?, empty: empty?, fraying: (threads), masterwork: masterwork?(threads), thread_ids: @thread_ids.dup, created_at: @created_at } end |
#unravel_thread(thread_id) ⇒ Object
30 31 32 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/tapestry.rb', line 30 def unravel_thread(thread_id) @thread_ids.delete(thread_id) ? true : false end |
#weave_thread(thread_id) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/tapestry.rb', line 22 def weave_thread(thread_id) return false if @thread_ids.include?(thread_id) return false if full? @thread_ids << thread_id true end |