Class: Legion::Extensions::Agentic::Executive::Planning::Helpers::PlanStep

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/executive/planning/helpers/plan_step.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action:, description: nil, depends_on: [], estimated_effort: 1) ⇒ PlanStep

Returns a new instance of PlanStep.



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/legion/extensions/agentic/executive/planning/helpers/plan_step.rb', line 16

def initialize(action:, description: nil, depends_on: [], estimated_effort: 1, **)
  @id               = SecureRandom.uuid
  @action           = action
  @description      = description
  @status           = :pending
  @depends_on       = Array(depends_on).dup
  @estimated_effort = estimated_effort
  @actual_effort    = nil
  @result           = nil
  @started_at       = nil
  @completed_at     = nil
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



12
13
14
# File 'lib/legion/extensions/agentic/executive/planning/helpers/plan_step.rb', line 12

def action
  @action
end

#actual_effortObject

Returns the value of attribute actual_effort.



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

def actual_effort
  @actual_effort
end

#completed_atObject (readonly)

Returns the value of attribute completed_at.



12
13
14
# File 'lib/legion/extensions/agentic/executive/planning/helpers/plan_step.rb', line 12

def completed_at
  @completed_at
end

#depends_onObject (readonly)

Returns the value of attribute depends_on.



12
13
14
# File 'lib/legion/extensions/agentic/executive/planning/helpers/plan_step.rb', line 12

def depends_on
  @depends_on
end

#descriptionObject (readonly)

Returns the value of attribute description.



12
13
14
# File 'lib/legion/extensions/agentic/executive/planning/helpers/plan_step.rb', line 12

def description
  @description
end

#estimated_effortObject (readonly)

Returns the value of attribute estimated_effort.



12
13
14
# File 'lib/legion/extensions/agentic/executive/planning/helpers/plan_step.rb', line 12

def estimated_effort
  @estimated_effort
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/legion/extensions/agentic/executive/planning/helpers/plan_step.rb', line 12

def id
  @id
end

#resultObject (readonly)

Returns the value of attribute result.



12
13
14
# File 'lib/legion/extensions/agentic/executive/planning/helpers/plan_step.rb', line 12

def result
  @result
end

#started_atObject (readonly)

Returns the value of attribute started_at.



12
13
14
# File 'lib/legion/extensions/agentic/executive/planning/helpers/plan_step.rb', line 12

def started_at
  @started_at
end

#statusObject

Returns the value of attribute status.



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

def status
  @status
end

Instance Method Details

#blocked?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/legion/extensions/agentic/executive/planning/helpers/plan_step.rb', line 41

def blocked?
  @status == :blocked
end

#complete!(result: nil) ⇒ Object



45
46
47
48
49
# File 'lib/legion/extensions/agentic/executive/planning/helpers/plan_step.rb', line 45

def complete!(result: nil)
  @status       = :completed
  @result       = result
  @completed_at = Time.now.utc
end

#durationObject



35
36
37
38
39
# File 'lib/legion/extensions/agentic/executive/planning/helpers/plan_step.rb', line 35

def duration
  return nil unless @started_at && @completed_at

  @completed_at - @started_at
end

#fail!(reason: nil) ⇒ Object



51
52
53
54
55
# File 'lib/legion/extensions/agentic/executive/planning/helpers/plan_step.rb', line 51

def fail!(reason: nil)
  @status       = :failed
  @result       = { reason: reason }
  @completed_at = Time.now.utc
end

#ready?(completed_step_ids) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
# File 'lib/legion/extensions/agentic/executive/planning/helpers/plan_step.rb', line 29

def ready?(completed_step_ids)
  return false if %i[completed failed skipped].include?(@status)

  @depends_on.all? { |dep_id| completed_step_ids.include?(dep_id) }
end

#start!Object



57
58
59
60
# File 'lib/legion/extensions/agentic/executive/planning/helpers/plan_step.rb', line 57

def start!
  @status     = :active
  @started_at = Time.now.utc
end

#to_hObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/legion/extensions/agentic/executive/planning/helpers/plan_step.rb', line 62

def to_h
  {
    id:               @id,
    action:           @action,
    description:      @description,
    status:           @status,
    depends_on:       @depends_on,
    estimated_effort: @estimated_effort,
    actual_effort:    @actual_effort,
    result:           @result,
    started_at:       @started_at,
    completed_at:     @completed_at
  }
end