Class: Ace::Assign::Models::Step

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/assign/models/step.rb

Overview

Step data model representing a work queue item.

Pure data carrier with no business logic (ATOM pattern). All attributes are immutable after initialization.

Examples:

step = Step.new(
  number: "010",
  name: "init-project",
  status: :pending,
  instructions: "Create project structure..."
)

Constant Summary collapse

STATUSES =

Valid status values

%i[pending in_progress done failed].freeze
VALID_CONTEXTS =

Valid context values for execution context

%w[fork].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number:, name:, status:, instructions:, report: nil, error: nil, started_at: nil, completed_at: nil, added_by: nil, parent: nil, file_path: nil, source: nil, skill: nil, workflow: nil, context: nil, batch_parent: nil, parallel: nil, max_parallel: nil, fork_retry_limit: nil, fork_options: nil, fork_launch_pid: nil, fork_tracked_pids: nil, fork_pid_updated_at: nil, fork_pid_file: nil, stall_reason: nil) ⇒ Step

Returns a new instance of Step.

Parameters:

  • number (String)

    Step number (e.g., “010”, “010.01”)

  • name (String)

    Step name

  • status (Symbol)

    Step status (:pending, :in_progress, :done, :failed)

  • instructions (String)

    Step instructions (markdown)

  • report (String, nil) (defaults to: nil)

    Completion report content

  • error (String, nil) (defaults to: nil)

    Error message (if failed)

  • started_at (Time, nil) (defaults to: nil)

    When work started

  • completed_at (Time, nil) (defaults to: nil)

    When completed/failed

  • added_by (String, nil) (defaults to: nil)

    How step was added (nil, “dynamic”, “retry_of:NNN”)

  • parent (String, nil) (defaults to: nil)

    Parent step number (for sub-steps)

  • file_path (String, nil) (defaults to: nil)

    Path to step file

  • skill (String, nil) (defaults to: nil)

    Skill reference for this step (e.g., “ace-task-work”)

  • context (String, nil) (defaults to: nil)

    Execution context (“fork” for Task tool execution)

  • batch_parent (Boolean, nil) (defaults to: nil)

    Whether step is a batch scheduling parent

  • parallel (Boolean, nil) (defaults to: nil)

    Batch scheduling mode hint (true=parallel, false=sequential)

  • max_parallel (Integer, nil) (defaults to: nil)

    Max concurrent children for parallel batches

  • fork_retry_limit (Integer, nil) (defaults to: nil)

    Retry attempts allowed per failed child

  • fork_options (Hash, nil) (defaults to: nil)

    Fork execution options from frontmatter (e.g. “…” )

  • fork_launch_pid (Integer, nil) (defaults to: nil)

    PID of the process that launched the fork run

  • fork_tracked_pids (Array<Integer>, nil) (defaults to: nil)

    Observed subprocess/descendant PIDs during fork execution

  • fork_pid_updated_at (Time, nil) (defaults to: nil)

    Timestamp when fork PID metadata was last updated

  • fork_pid_file (String, nil) (defaults to: nil)

    Path to fork PID metadata file

  • stall_reason (String, nil) (defaults to: nil)

    Last agent message captured when fork stalled



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/ace/assign/models/step.rb', line 55

def initialize(number:, name:, status:, instructions:, report: nil, error: nil,
  started_at: nil, completed_at: nil, added_by: nil, parent: nil,
  file_path: nil, source: nil, skill: nil, workflow: nil, context: nil,
  batch_parent: nil, parallel: nil, max_parallel: nil, fork_retry_limit: nil,
  fork_options: nil,
  fork_launch_pid: nil, fork_tracked_pids: nil, fork_pid_updated_at: nil,
  fork_pid_file: nil, stall_reason: nil)
  validate_status!(status)
  validate_context!(context) if context
  validate_boolean!(:batch_parent, batch_parent)
  validate_boolean!(:parallel, parallel)
  validate_positive_integer!(:max_parallel, max_parallel)
  validate_non_negative_integer!(:fork_retry_limit, fork_retry_limit)
  validate_hash!(:fork_options, fork_options)

  @number = number.freeze
  @name = name.freeze
  @status = status
  @instructions = instructions.freeze
  @report = report&.freeze
  @error = error&.freeze
  @started_at = started_at
  @completed_at = completed_at
  @added_by = added_by&.freeze
  @parent = parent&.freeze
  @file_path = file_path&.freeze
  @source = source&.freeze
  @skill = skill&.freeze
  @workflow = workflow&.freeze
  @context = context&.freeze
  @batch_parent = batch_parent.nil? ? nil : !!batch_parent
  @parallel = parallel.nil? ? nil : !!parallel
  @max_parallel = max_parallel&.to_i
  @fork_retry_limit = fork_retry_limit&.to_i
  @fork_options = normalize_fork_options(fork_options)
  @fork_launch_pid = fork_launch_pid&.to_i
  @fork_tracked_pids = Array(fork_tracked_pids).map(&:to_i).uniq.sort.freeze
  @fork_pid_updated_at = fork_pid_updated_at
  @fork_pid_file = fork_pid_file&.freeze
  @stall_reason = stall_reason&.freeze
end

Instance Attribute Details

#added_byObject (readonly)

Returns the value of attribute added_by.



25
26
27
# File 'lib/ace/assign/models/step.rb', line 25

def added_by
  @added_by
end

#batch_parentObject (readonly)

Returns the value of attribute batch_parent.



25
26
27
# File 'lib/ace/assign/models/step.rb', line 25

def batch_parent
  @batch_parent
end

#completed_atObject (readonly)

Returns the value of attribute completed_at.



25
26
27
# File 'lib/ace/assign/models/step.rb', line 25

def completed_at
  @completed_at
end

#contextObject (readonly)

Returns the value of attribute context.



25
26
27
# File 'lib/ace/assign/models/step.rb', line 25

def context
  @context
end

#errorObject (readonly)

Returns the value of attribute error.



25
26
27
# File 'lib/ace/assign/models/step.rb', line 25

def error
  @error
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



25
26
27
# File 'lib/ace/assign/models/step.rb', line 25

def file_path
  @file_path
end

#fork_launch_pidObject (readonly)

Returns the value of attribute fork_launch_pid.



25
26
27
# File 'lib/ace/assign/models/step.rb', line 25

def fork_launch_pid
  @fork_launch_pid
end

#fork_optionsObject (readonly)

Returns the value of attribute fork_options.



25
26
27
# File 'lib/ace/assign/models/step.rb', line 25

def fork_options
  @fork_options
end

#fork_pid_fileObject (readonly)

Returns the value of attribute fork_pid_file.



25
26
27
# File 'lib/ace/assign/models/step.rb', line 25

def fork_pid_file
  @fork_pid_file
end

#fork_pid_updated_atObject (readonly)

Returns the value of attribute fork_pid_updated_at.



25
26
27
# File 'lib/ace/assign/models/step.rb', line 25

def fork_pid_updated_at
  @fork_pid_updated_at
end

#fork_retry_limitObject (readonly)

Returns the value of attribute fork_retry_limit.



25
26
27
# File 'lib/ace/assign/models/step.rb', line 25

def fork_retry_limit
  @fork_retry_limit
end

#fork_tracked_pidsObject (readonly)

Returns the value of attribute fork_tracked_pids.



25
26
27
# File 'lib/ace/assign/models/step.rb', line 25

def fork_tracked_pids
  @fork_tracked_pids
end

#instructionsObject (readonly)

Returns the value of attribute instructions.



25
26
27
# File 'lib/ace/assign/models/step.rb', line 25

def instructions
  @instructions
end

#max_parallelObject (readonly)

Returns the value of attribute max_parallel.



25
26
27
# File 'lib/ace/assign/models/step.rb', line 25

def max_parallel
  @max_parallel
end

#nameObject (readonly)

Returns the value of attribute name.



25
26
27
# File 'lib/ace/assign/models/step.rb', line 25

def name
  @name
end

#numberObject (readonly)

Returns the value of attribute number.



25
26
27
# File 'lib/ace/assign/models/step.rb', line 25

def number
  @number
end

#parallelObject (readonly)

Returns the value of attribute parallel.



25
26
27
# File 'lib/ace/assign/models/step.rb', line 25

def parallel
  @parallel
end

#parentObject (readonly)

Returns the value of attribute parent.



25
26
27
# File 'lib/ace/assign/models/step.rb', line 25

def parent
  @parent
end

#reportObject (readonly)

Returns the value of attribute report.



25
26
27
# File 'lib/ace/assign/models/step.rb', line 25

def report
  @report
end

#skillObject (readonly)

Returns the value of attribute skill.



25
26
27
# File 'lib/ace/assign/models/step.rb', line 25

def skill
  @skill
end

#sourceObject (readonly)

Returns the value of attribute source.



25
26
27
# File 'lib/ace/assign/models/step.rb', line 25

def source
  @source
end

#stall_reasonObject (readonly)

Returns the value of attribute stall_reason.



25
26
27
# File 'lib/ace/assign/models/step.rb', line 25

def stall_reason
  @stall_reason
end

#started_atObject (readonly)

Returns the value of attribute started_at.



25
26
27
# File 'lib/ace/assign/models/step.rb', line 25

def started_at
  @started_at
end

#statusObject (readonly)

Returns the value of attribute status.



25
26
27
# File 'lib/ace/assign/models/step.rb', line 25

def status
  @status
end

#workflowObject (readonly)

Returns the value of attribute workflow.



25
26
27
# File 'lib/ace/assign/models/step.rb', line 25

def workflow
  @workflow
end

Instance Method Details

#complete?Boolean

Check if step is complete (done or failed)

Returns:

  • (Boolean)


99
100
101
# File 'lib/ace/assign/models/step.rb', line 99

def complete?
  %i[done failed].include?(status)
end

#fork?Boolean

Check if this step should run in a forked context (subagent)

Returns:

  • (Boolean)


117
118
119
# File 'lib/ace/assign/models/step.rb', line 117

def fork?
  context == "fork"
end

#fork_providerString?

Resolve per-step provider override from fork options.

Returns:

  • (String, nil)


123
124
125
126
127
128
129
# File 'lib/ace/assign/models/step.rb', line 123

def fork_provider
  return nil unless fork_options

  provider = fork_options["provider"]
  provider = provider.to_s.strip
  provider.empty? ? nil : provider
end

#retry?Boolean

Check if this is a retry of another step

Returns:

  • (Boolean)


111
112
113
# File 'lib/ace/assign/models/step.rb', line 111

def retry?
  added_by&.start_with?("retry_of:")
end

#retry_ofString?

Get the original step number if this is a retry

Returns:

  • (String, nil)

    Original step number



133
134
135
136
137
# File 'lib/ace/assign/models/step.rb', line 133

def retry_of
  return nil unless retry?

  added_by.sub("retry_of:", "")
end

#to_display_rowHash

Convert to display row for status table

Returns:

  • (Hash)

    Display row data



169
170
171
172
173
174
175
176
# File 'lib/ace/assign/models/step.rb', line 169

def to_display_row
  {
    file: File.basename(file_path || "#{number}-#{name}.st.md"),
    status: status.to_s,
    name: name,
    error: error
  }
end

#to_frontmatterHash

Convert to frontmatter hash for YAML serialization

Returns:

  • (Hash)

    Frontmatter data



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/ace/assign/models/step.rb', line 141

def to_frontmatter
  {
    "name" => name,
    "status" => status.to_s,
    "source" => source,
    "skill" => skill,
    "workflow" => workflow,
    "context" => context,
    "batch_parent" => batch_parent,
    "parallel" => parallel,
    "max_parallel" => max_parallel,
    "fork_retry_limit" => fork_retry_limit,
    "fork" => fork_options,
    "started_at" => started_at&.iso8601,
    "completed_at" => completed_at&.iso8601,
    "fork_launch_pid" => fork_launch_pid,
    "fork_tracked_pids" => fork_tracked_pids,
    "fork_pid_updated_at" => fork_pid_updated_at&.iso8601,
    "fork_pid_file" => fork_pid_file,
    "error" => error,
    "stall_reason" => stall_reason,
    "added_by" => added_by,
    "parent" => parent
  }.compact
end

#workable?Boolean

Check if step can be worked on

Returns:

  • (Boolean)


105
106
107
# File 'lib/ace/assign/models/step.rb', line 105

def workable?
  status == :pending || status == :in_progress
end