Class: RosettAi::Thor::Tasks::Workflow

Inherits:
Thor
  • Object
show all
Defined in:
lib/rosett_ai/thor/tasks/workflow.rb

Overview

CLI task for rai workflow — declarative workflow execution.

Provides commands to list, validate, simulate, and run workflows. Workflows are YAML files defining multi-step automation sequences.

Author:

  • hugo

  • claude

Instance Method Summary collapse

Instance Method Details

#execute(name) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/rosett_ai/thor/tasks/workflow.rb', line 116

def execute(name)
  path = resolve_workflow(name)
  audit_path = resolve_audit_log_path(name)
  engine = RosettAi::Workflow::Engine.new(workflow_path: path, audit_log_path: audit_path)
  summary = engine.execute(resume: options[:resume])

  if options[:format] == 'json'
    puts JSON.pretty_generate(summary)
  else
    render_table(summary)
  end

  exit 1 if summary[:status] == 'fail'
end

#listObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rosett_ai/thor/tasks/workflow.rb', line 30

def list
  files = discover_workflows
  if files.empty?
    warn ::I18n.t('rosett_ai.workflow.no_files')
    return
  end

  rows = files.filter_map do |path|
    data = load_workflow_safe(path)
    next unless data

    [data['name'] || File.basename(path, '.yml'), data['version'] || '-',
     data.fetch('steps', []).size, path.to_s]
  end

  table = ::Terminal::Table.new(
    title: ::I18n.t('rosett_ai.workflow.list_title'),
    headings: [::I18n.t('rosett_ai.workflow.name'), ::I18n.t('rosett_ai.workflow.version'),
               ::I18n.t('rosett_ai.workflow.steps_count'), ::I18n.t('rosett_ai.workflow.path')],
    rows: rows
  )
  puts table
end

#simulate(name) ⇒ Object



86
87
88
89
90
91
92
93
94
95
# File 'lib/rosett_ai/thor/tasks/workflow.rb', line 86

def simulate(name)
  path = resolve_workflow(name)
  engine = RosettAi::Workflow::Engine.new(workflow_path: path)
  descriptions = engine.simulate

  puts ::I18n.t('rosett_ai.workflow.simulate_header', name: name)
  descriptions.each_with_index do |desc, idx|
    puts "  #{idx + 1}. #{desc}"
  end
end

#validate(name) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/rosett_ai/thor/tasks/workflow.rb', line 63

def validate(name)
  path = resolve_workflow(name)
  engine = RosettAi::Workflow::Engine.new(workflow_path: path)
  errors = engine.validate

  if errors.empty?
    puts Rainbow(::I18n.t('rosett_ai.workflow.valid', name: name)).green
  else
    warn Rainbow(::I18n.t('rosett_ai.workflow.invalid', name: name)).red
    errors.each { |err| warn "  - #{err}" }
    exit 2
  end
end