Class: Legion::Extensions::Agentic::Self::NarrativeArc::Helpers::Arc

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/self/narrative_arc/helpers/arc.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title:, domain: :general, initial_tension: Constants::DEFAULT_TENSION) ⇒ Arc

Returns a new instance of Arc.



15
16
17
18
19
20
21
22
23
24
# File 'lib/legion/extensions/agentic/self/narrative_arc/helpers/arc.rb', line 15

def initialize(title:, domain: :general, initial_tension: Constants::DEFAULT_TENSION)
  @arc_id       = SecureRandom.uuid
  @title        = title
  @domain       = domain
  @beats        = []
  @arc_phase    = :building
  @tension_level = initial_tension.clamp(0.0, 1.0)
  @created_at   = Time.now.utc
  @resolved_at  = nil
end

Instance Attribute Details

#arc_idObject (readonly)

Returns the value of attribute arc_id.



12
13
14
# File 'lib/legion/extensions/agentic/self/narrative_arc/helpers/arc.rb', line 12

def arc_id
  @arc_id
end

#arc_phaseObject (readonly)

Returns the value of attribute arc_phase.



12
13
14
# File 'lib/legion/extensions/agentic/self/narrative_arc/helpers/arc.rb', line 12

def arc_phase
  @arc_phase
end

#beatsObject (readonly)

Returns the value of attribute beats.



12
13
14
# File 'lib/legion/extensions/agentic/self/narrative_arc/helpers/arc.rb', line 12

def beats
  @beats
end

#created_atObject (readonly)

Returns the value of attribute created_at.



12
13
14
# File 'lib/legion/extensions/agentic/self/narrative_arc/helpers/arc.rb', line 12

def created_at
  @created_at
end

#domainObject (readonly)

Returns the value of attribute domain.



12
13
14
# File 'lib/legion/extensions/agentic/self/narrative_arc/helpers/arc.rb', line 12

def domain
  @domain
end

#resolved_atObject (readonly)

Returns the value of attribute resolved_at.



12
13
14
# File 'lib/legion/extensions/agentic/self/narrative_arc/helpers/arc.rb', line 12

def resolved_at
  @resolved_at
end

#tension_levelObject (readonly)

Returns the value of attribute tension_level.



12
13
14
# File 'lib/legion/extensions/agentic/self/narrative_arc/helpers/arc.rb', line 12

def tension_level
  @tension_level
end

#titleObject (readonly)

Returns the value of attribute title.



12
13
14
# File 'lib/legion/extensions/agentic/self/narrative_arc/helpers/arc.rb', line 12

def title
  @title
end

Instance Method Details

#add_beat!(beat) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/legion/extensions/agentic/self/narrative_arc/helpers/arc.rb', line 26

def add_beat!(beat)
  return false if @beats.size >= Constants::MAX_BEATS_PER_ARC
  return false if complete?

  @beats << beat
  adjust_tension_for_beat(beat)
  advance_phase!
  true
end

#advance_phase!Object



36
37
38
39
40
41
# File 'lib/legion/extensions/agentic/self/narrative_arc/helpers/arc.rb', line 36

def advance_phase!
  new_phase = detect_phase
  @arc_phase = new_phase if new_phase != @arc_phase
  @resolved_at = Time.now.utc if @arc_phase == :complete
  @arc_phase
end

#climaxed?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/legion/extensions/agentic/self/narrative_arc/helpers/arc.rb', line 51

def climaxed?
  @tension_level >= Constants::CLIMAX_THRESHOLD || @arc_phase == :peak
end

#complete?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/legion/extensions/agentic/self/narrative_arc/helpers/arc.rb', line 59

def complete?
  @arc_phase == :complete
end

#drama_labelObject



76
77
78
# File 'lib/legion/extensions/agentic/self/narrative_arc/helpers/arc.rb', line 76

def drama_label
  Constants.label_for(Constants::DRAMA_LABELS, dramatic_score)
end

#dramatic_scoreObject



63
64
65
66
67
68
69
70
# File 'lib/legion/extensions/agentic/self/narrative_arc/helpers/arc.rb', line 63

def dramatic_score
  return 0.0 if @beats.empty?

  tension_contrib = @tension_level * 0.4
  beat_count_contrib = [@beats.size.to_f / Constants::MAX_BEATS_PER_ARC, 1.0].min * 0.3
  intensity_contrib = average_beat_intensity * 0.3
  (tension_contrib + beat_count_contrib + intensity_contrib).round(10)
end

#resolved?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/legion/extensions/agentic/self/narrative_arc/helpers/arc.rb', line 55

def resolved?
  @arc_phase == :complete
end

#tension_fall!(amount = Constants::TENSION_FALL) ⇒ Object



47
48
49
# File 'lib/legion/extensions/agentic/self/narrative_arc/helpers/arc.rb', line 47

def tension_fall!(amount = Constants::TENSION_FALL)
  @tension_level = (@tension_level - amount).round(10).clamp(0.0, 1.0)
end

#tension_labelObject



72
73
74
# File 'lib/legion/extensions/agentic/self/narrative_arc/helpers/arc.rb', line 72

def tension_label
  Constants.label_for(Constants::TENSION_LABELS, @tension_level)
end

#tension_rise!(amount = Constants::TENSION_RISE) ⇒ Object



43
44
45
# File 'lib/legion/extensions/agentic/self/narrative_arc/helpers/arc.rb', line 43

def tension_rise!(amount = Constants::TENSION_RISE)
  @tension_level = (@tension_level + amount).round(10).clamp(0.0, 1.0)
end

#to_hObject



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/legion/extensions/agentic/self/narrative_arc/helpers/arc.rb', line 80

def to_h
  {
    arc_id:         @arc_id,
    title:          @title,
    domain:         @domain,
    arc_phase:      @arc_phase,
    tension_level:  @tension_level,
    beat_count:     @beats.size,
    dramatic_score: dramatic_score,
    tension_label:  tension_label,
    drama_label:    drama_label,
    created_at:     @created_at,
    resolved_at:    @resolved_at
  }
end