Class: Legion::Extensions::Agentic::Executive::GoalManagement::Helpers::Goal

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb

Constant Summary

Constants included from Constants

Constants::CONFLICT_LABELS, Constants::CONFLICT_THRESHOLD, Constants::DEFAULT_PRIORITY, Constants::GOAL_STATUSES, Constants::MAX_DEPTH, Constants::MAX_GOALS, Constants::PRIORITY_BOOST, Constants::PRIORITY_DECAY, Constants::PRIORITY_LABELS, Constants::PROGRESS_LABELS, Constants::PROGRESS_THRESHOLD

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content:, parent_id: nil, domain: :general, priority: DEFAULT_PRIORITY, deadline: nil) ⇒ Goal

Returns a new instance of Goal.



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 18

def initialize(content:, parent_id: nil, domain: :general, priority: DEFAULT_PRIORITY, deadline: nil)
  @id           = SecureRandom.uuid
  @content      = content
  @parent_id    = parent_id
  @sub_goal_ids = []
  @status       = :proposed
  @priority     = priority.clamp(0.0, 1.0)
  @progress     = 0.0
  @domain       = domain
  @deadline     = deadline
  @created_at   = Time.now
  @updated_at   = Time.now
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



14
15
16
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 14

def content
  @content
end

#created_atObject (readonly)

Returns the value of attribute created_at.



14
15
16
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 14

def created_at
  @created_at
end

#deadlineObject (readonly)

Returns the value of attribute deadline.



14
15
16
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 14

def deadline
  @deadline
end

#domainObject (readonly)

Returns the value of attribute domain.



14
15
16
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 14

def domain
  @domain
end

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 14

def id
  @id
end

#parent_idObject (readonly)

Returns the value of attribute parent_id.



14
15
16
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 14

def parent_id
  @parent_id
end

#priorityObject (readonly)

Returns the value of attribute priority.



14
15
16
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 14

def priority
  @priority
end

#progressObject (readonly)

Returns the value of attribute progress.



14
15
16
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 14

def progress
  @progress
end

#statusObject (readonly)

Returns the value of attribute status.



14
15
16
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 14

def status
  @status
end

#sub_goal_idsObject (readonly)

Returns the value of attribute sub_goal_ids.



14
15
16
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 14

def sub_goal_ids
  @sub_goal_ids
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.



14
15
16
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 14

def updated_at
  @updated_at
end

Instance Method Details

#abandon!Object



49
50
51
52
53
54
55
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 49

def abandon!
  return false if %i[completed abandoned].include?(@status)

  @status     = :abandoned
  @updated_at = Time.now
  true
end

#activate!Object



32
33
34
35
36
37
38
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 32

def activate!
  return false unless %i[proposed blocked].include?(@status)

  @status     = :active
  @updated_at = Time.now
  true
end

#active?Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 111

def active?
  @status == :active
end

#add_sub_goal(goal_id) ⇒ Object



91
92
93
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 91

def add_sub_goal(goal_id)
  @sub_goal_ids << goal_id unless @sub_goal_ids.include?(goal_id)
end

#advance_progress!(amount) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 73

def advance_progress!(amount)
  return false if %i[completed abandoned].include?(@status)

  @progress   = (@progress + amount).clamp(0.0, 1.0).round(10)
  @updated_at = Time.now
  true
end

#block!Object



57
58
59
60
61
62
63
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 57

def block!
  return false unless @status == :active

  @status     = :blocked
  @updated_at = Time.now
  true
end

#blocked?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 103

def blocked?
  @status == :blocked
end

#boost_priority!Object



81
82
83
84
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 81

def boost_priority!
  @priority   = (@priority + PRIORITY_BOOST).clamp(0.0, 1.0).round(10)
  @updated_at = Time.now
end

#complete!Object



40
41
42
43
44
45
46
47
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 40

def complete!
  return false unless %i[active blocked].include?(@status)

  @status     = :completed
  @progress   = 1.0
  @updated_at = Time.now
  true
end

#completed?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 107

def completed?
  @status == :completed
end

#decay_priority!Object



86
87
88
89
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 86

def decay_priority!
  @priority   = (@priority - PRIORITY_DECAY).clamp(0.0, 1.0).round(10)
  @updated_at = Time.now
end

#leaf?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 99

def leaf?
  @sub_goal_ids.empty?
end

#overdue?Boolean

Returns:

  • (Boolean)


115
116
117
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 115

def overdue?
  !@deadline.nil? && Time.now > @deadline
end

#priority_labelObject



119
120
121
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 119

def priority_label
  PRIORITY_LABELS.find { |l| l[:range].cover?(@priority) }&.fetch(:label, :trivial) || :trivial
end

#progress_labelObject



123
124
125
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 123

def progress_label
  PROGRESS_LABELS.find { |l| l[:range].cover?(@progress) }&.fetch(:label, :not_started) || :not_started
end

#root?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 95

def root?
  @parent_id.nil?
end

#to_hObject



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 127

def to_h
  {
    id:             @id,
    content:        @content,
    parent_id:      @parent_id,
    sub_goal_ids:   @sub_goal_ids.dup,
    status:         @status,
    priority:       @priority,
    priority_label: priority_label,
    progress:       @progress,
    progress_label: progress_label,
    domain:         @domain,
    deadline:       @deadline,
    overdue:        overdue?,
    root:           root?,
    leaf:           leaf?,
    created_at:     @created_at,
    updated_at:     @updated_at
  }
end

#unblock!Object



65
66
67
68
69
70
71
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 65

def unblock!
  return false unless @status == :blocked

  @status     = :active
  @updated_at = Time.now
  true
end