Class: RosettAi::Workflow::Steps::ShellStep

Inherits:
Object
  • Object
show all
Defined in:
lib/rosett_ai/workflow/steps/shell_step.rb

Overview

Executes a shell command in array-form (no string interpolation).

Author:

  • hugo

  • claude

Instance Method Summary collapse

Constructor Details

#initialize(definition) ⇒ ShellStep

Returns a new instance of ShellStep.

Parameters:

  • definition (Hash)

    step definition from workflow YAML



15
16
17
18
19
# File 'lib/rosett_ai/workflow/steps/shell_step.rb', line 15

def initialize(definition)
  @definition = definition
  @command = definition.fetch('command')
  validate!
end

Instance Method Details

#describeString

Returns step description for dry-run.

Returns:

  • (String)

    step description for dry-run



22
23
24
# File 'lib/rosett_ai/workflow/steps/shell_step.rb', line 22

def describe
  "[shell] #{@definition['name']}#{@command.join(' ')}"
end

#executeHash

Executes the shell command.

Returns:

  • (Hash)

    execution result with :status and :message



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rosett_ai/workflow/steps/shell_step.rb', line 29

def execute
  start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  success = system(*@command)
  elapsed = ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - start) * 1000).round(1)

  if success
    { status: 'pass', message: "Completed: #{@command.join(' ')}", duration_ms: elapsed }
  else
    { status: 'fail', message: "Failed: #{@command.join(' ')} (exit #{$CHILD_STATUS&.exitstatus})",
      duration_ms: elapsed }
  end
end