Class: RosettAi::Thor::Tasks::Workflow
- Inherits:
-
Thor
- Object
- Thor
- RosettAi::Thor::Tasks::Workflow
- 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.
Instance Method Summary collapse
-
#execute(name) ⇒ void
Execute the named workflow.
-
#list ⇒ void
List available items.
-
#simulate(name) ⇒ void
Simulate workflow execution without applying changes.
-
#validate(name) ⇒ Array<Hash>
Validate the input and return any errors.
Instance Method Details
#execute(name) ⇒ void
This method returns an undefined value.
Execute the named workflow.
130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/rosett_ai/thor/tasks/workflow.rb', line 130 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: [:resume]) if [:format] == 'json' puts JSON.pretty_generate(summary) else render_table(summary) end exit 1 if summary[:status] == 'fail' end |
#list ⇒ void
This method returns an undefined value.
List available items.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rosett_ai/thor/tasks/workflow.rb', line 32 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) ⇒ void
This method returns an undefined value.
Simulate workflow execution without applying changes.
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/rosett_ai/thor/tasks/workflow.rb', line 96 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) ⇒ Array<Hash>
Validate the input and return any errors.
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/rosett_ai/thor/tasks/workflow.rb', line 69 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 |