Class: Legion::Extensions::Agentic::Integration::Tapestry::Helpers::Thread

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/integration/tapestry/helpers/thread.rb

Constant Summary collapse

COLOR_MAP =
{
  experience: :gold,
  belief:     :silver,
  memory:     :blue,
  emotion:    :crimson,
  narrative:  :violet
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(thread_type:, domain:, content:, strength: nil, color: nil) ⇒ Thread

Returns a new instance of Thread.



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/thread.rb', line 22

def initialize(thread_type:, domain:, content:,
               strength: nil, color: nil)
  validate_thread_type!(thread_type)
  @id          = SecureRandom.uuid
  @thread_type = thread_type.to_sym
  @domain      = domain.to_sym
  @content     = content.to_s
  @strength    = (strength || 0.5).to_f.clamp(0.0, 1.0).round(10)
  @color       = (color || default_color(thread_type)).to_sym
  @created_at  = Time.now.utc
  @tapestry_id = nil
end

Instance Attribute Details

#colorObject (readonly)

Returns the value of attribute color.



10
11
12
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/thread.rb', line 10

def color
  @color
end

#contentObject (readonly)

Returns the value of attribute content.



10
11
12
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/thread.rb', line 10

def content
  @content
end

#created_atObject (readonly)

Returns the value of attribute created_at.



10
11
12
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/thread.rb', line 10

def created_at
  @created_at
end

#domainObject (readonly)

Returns the value of attribute domain.



10
11
12
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/thread.rb', line 10

def domain
  @domain
end

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/thread.rb', line 10

def id
  @id
end

#strengthObject

Returns the value of attribute strength.



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

def strength
  @strength
end

#tapestry_idObject (readonly)

Returns the value of attribute tapestry_id.



10
11
12
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/thread.rb', line 10

def tapestry_id
  @tapestry_id
end

#thread_typeObject (readonly)

Returns the value of attribute thread_type.



10
11
12
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/thread.rb', line 10

def thread_type
  @thread_type
end

Instance Method Details

#fray!(rate: Constants::FRAY_RATE) ⇒ Object



50
51
52
53
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/thread.rb', line 50

def fray!(rate: Constants::FRAY_RATE)
  @strength = (@strength - rate.abs).clamp(0.0, 1.0).round(10)
  self
end

#loose?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/thread.rb', line 67

def loose?
  @tapestry_id.nil?
end

#reinforce!(rate: Constants::TENSION_RATE) ⇒ Object



45
46
47
48
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/thread.rb', line 45

def reinforce!(rate: Constants::TENSION_RATE)
  @strength = (@strength + rate.abs).clamp(0.0, 1.0).round(10)
  self
end

#snap?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/thread.rb', line 55

def snap?
  @strength <= 0.0
end

#taut?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/thread.rb', line 59

def taut?
  @strength >= 0.9
end

#thread_integrityObject



71
72
73
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/thread.rb', line 71

def thread_integrity
  Constants.label_for(Constants::INTEGRITY_LABELS, @strength)
end

#to_hObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/thread.rb', line 75

def to_h
  {
    id:               @id,
    thread_type:      @thread_type,
    domain:           @domain,
    content:          @content,
    strength:         @strength,
    color:            @color,
    thread_integrity: thread_integrity,
    woven:            woven?,
    loose:            loose?,
    snap:             snap?,
    taut:             taut?,
    tapestry_id:      @tapestry_id,
    created_at:       @created_at
  }
end

#unwoven!Object



40
41
42
43
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/thread.rb', line 40

def unwoven!
  @tapestry_id = nil
  self
end

#woven?Boolean

Returns:

  • (Boolean)


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

def woven?
  !@tapestry_id.nil?
end

#woven_into!(tapestry_id) ⇒ Object



35
36
37
38
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/thread.rb', line 35

def woven_into!(tapestry_id)
  @tapestry_id = tapestry_id
  self
end