Class: Legion::Extensions::Agentic::Executive::GoalManagement::Helpers::Goal
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Executive::GoalManagement::Helpers::Goal
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
Class Method 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.
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 37
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
@task_id = nil
@runner_mapping = nil
end
|
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
15
16
17
|
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 15
def content
@content
end
|
#created_at ⇒ Object
Returns the value of attribute created_at.
15
16
17
|
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 15
def created_at
@created_at
end
|
#deadline ⇒ Object
Returns the value of attribute deadline.
15
16
17
|
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 15
def deadline
@deadline
end
|
#domain ⇒ Object
Returns the value of attribute domain.
15
16
17
|
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 15
def domain
@domain
end
|
#id ⇒ Object
Returns the value of attribute id.
15
16
17
|
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 15
def id
@id
end
|
#parent_id ⇒ Object
Returns the value of attribute parent_id.
15
16
17
|
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 15
def parent_id
@parent_id
end
|
#priority ⇒ Object
Returns the value of attribute priority.
15
16
17
|
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 15
def priority
@priority
end
|
#progress ⇒ Object
Returns the value of attribute progress.
15
16
17
|
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 15
def progress
@progress
end
|
#runner_mapping ⇒ Object
Returns the value of attribute runner_mapping.
15
16
17
|
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 15
def runner_mapping
@runner_mapping
end
|
#status ⇒ Object
Returns the value of attribute status.
15
16
17
|
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 15
def status
@status
end
|
#sub_goal_ids ⇒ Object
Returns the value of attribute sub_goal_ids.
15
16
17
|
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 15
def sub_goal_ids
@sub_goal_ids
end
|
#task_id ⇒ Object
Returns the value of attribute task_id.
15
16
17
|
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 15
def task_id
@task_id
end
|
#updated_at ⇒ Object
Returns the value of attribute updated_at.
15
16
17
|
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 15
def updated_at
@updated_at
end
|
Class Method Details
.from_h(hash) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 19
def self.from_h(hash)
goal = allocate
goal.instance_variable_set(:@id, hash[:id])
goal.instance_variable_set(:@content, hash[:content])
goal.instance_variable_set(:@parent_id, hash[:parent_id])
goal.instance_variable_set(:@sub_goal_ids, hash[:sub_goal_ids] || [])
goal.instance_variable_set(:@status, hash[:status]&.to_sym || :proposed)
goal.instance_variable_set(:@priority, hash[:priority]&.to_f || 0.5)
goal.instance_variable_set(:@progress, (hash[:progress] || 0.0).to_f)
goal.instance_variable_set(:@domain, hash[:domain]&.to_sym || :general)
goal.instance_variable_set(:@deadline, hash[:deadline])
goal.instance_variable_set(:@task_id, hash[:task_id])
goal.instance_variable_set(:@runner_mapping, hash[:runner_mapping])
goal.instance_variable_set(:@created_at, hash[:created_at] ? Time.parse(hash[:created_at].to_s) : Time.now)
goal.instance_variable_set(:@updated_at, hash[:updated_at] ? Time.parse(hash[:updated_at].to_s) : Time.now)
goal
end
|
Instance Method Details
#abandon! ⇒ Object
70
71
72
73
74
75
76
|
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 70
def abandon!
return false if %i[completed abandoned].include?(@status)
@status = :abandoned
@updated_at = Time.now
true
end
|
#activate! ⇒ Object
53
54
55
56
57
58
59
|
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 53
def activate!
return false unless %i[proposed blocked].include?(@status)
@status = :active
@updated_at = Time.now
true
end
|
#active? ⇒ Boolean
138
139
140
|
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 138
def active?
@status == :active
end
|
#add_sub_goal(goal_id) ⇒ Object
118
119
120
|
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 118
def add_sub_goal(goal_id)
@sub_goal_ids << goal_id unless @sub_goal_ids.include?(goal_id)
end
|
#advance_progress!(amount) ⇒ Object
94
95
96
97
98
99
100
|
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 94
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
|
#assign_task!(task_id:, runner_mapping:) ⇒ Object
112
113
114
115
116
|
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 112
def assign_task!(task_id:, runner_mapping:)
@task_id = task_id
@runner_mapping = runner_mapping
@updated_at = Time.now
end
|
#block! ⇒ Object
78
79
80
81
82
83
84
|
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 78
def block!
return false unless @status == :active
@status = :blocked
@updated_at = Time.now
true
end
|
#blocked? ⇒ Boolean
130
131
132
|
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 130
def blocked?
@status == :blocked
end
|
#boost_priority! ⇒ Object
102
103
104
105
|
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 102
def boost_priority!
@priority = (@priority + PRIORITY_BOOST).clamp(0.0, 1.0).round(10)
@updated_at = Time.now
end
|
#complete! ⇒ Object
61
62
63
64
65
66
67
68
|
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 61
def complete!
return false unless %i[active blocked].include?(@status)
@status = :completed
@progress = 1.0
@updated_at = Time.now
true
end
|
#completed? ⇒ Boolean
134
135
136
|
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 134
def completed?
@status == :completed
end
|
#decay_priority! ⇒ Object
107
108
109
110
|
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 107
def decay_priority!
@priority = (@priority - PRIORITY_DECAY).clamp(0.0, 1.0).round(10)
@updated_at = Time.now
end
|
#leaf? ⇒ Boolean
126
127
128
|
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 126
def leaf?
@sub_goal_ids.empty?
end
|
#overdue? ⇒ Boolean
142
143
144
|
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 142
def overdue?
!@deadline.nil? && Time.now > @deadline
end
|
#priority_label ⇒ Object
146
147
148
|
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 146
def priority_label
PRIORITY_LABELS.find { |l| l[:range].cover?(@priority) }&.fetch(:label, :trivial) || :trivial
end
|
#progress_label ⇒ Object
150
151
152
|
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 150
def progress_label
PROGRESS_LABELS.find { |l| l[:range].cover?(@progress) }&.fetch(:label, :not_started) || :not_started
end
|
#root? ⇒ Boolean
122
123
124
|
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 122
def root?
@parent_id.nil?
end
|
#to_h ⇒ Object
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 154
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?,
task_id: @task_id,
runner_mapping: @runner_mapping,
created_at: @created_at,
updated_at: @updated_at
}
end
|
#unblock! ⇒ Object
86
87
88
89
90
91
92
|
# File 'lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb', line 86
def unblock!
return false unless @status == :blocked
@status = :active
@updated_at = Time.now
true
end
|