Class: Roast::Workflow::StepExecutorWithReporting
- Inherits:
-
Object
- Object
- Roast::Workflow::StepExecutorWithReporting
- Defined in:
- lib/roast/workflow/step_executor_with_reporting.rb
Overview
Decorator that adds token consumption reporting to step execution
Instance Method Summary collapse
- #execute(step, **options) ⇒ Object
-
#execute_steps(workflow_steps) ⇒ Object
Override execute_steps to ensure reporting happens for each step.
-
#initialize(base_executor, context, output: $stderr) ⇒ StepExecutorWithReporting
constructor
A new instance of StepExecutorWithReporting.
-
#method_missing(method, *args, **kwargs, &block) ⇒ Object
Delegate all other methods to the base executor.
- #respond_to_missing?(method, include_private = false) ⇒ Boolean
Constructor Details
#initialize(base_executor, context, output: $stderr) ⇒ StepExecutorWithReporting
Returns a new instance of StepExecutorWithReporting.
7 8 9 10 11 12 |
# File 'lib/roast/workflow/step_executor_with_reporting.rb', line 7 def initialize(base_executor, context, output: $stderr) @base_executor = base_executor @context = context @reporter = StepCompletionReporter.new(output: output) @name_extractor = StepNameExtractor.new end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, **kwargs, &block) ⇒ Object
Delegate all other methods to the base executor
55 56 57 58 59 60 61 |
# File 'lib/roast/workflow/step_executor_with_reporting.rb', line 55 def method_missing(method, *args, **kwargs, &block) if @base_executor.respond_to?(method) @base_executor.send(method, *args, **kwargs, &block) else super end end |
Instance Method Details
#execute(step, **options) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/roast/workflow/step_executor_with_reporting.rb', line 14 def execute(step, **) # Track tokens before execution tokens_before = @context.workflow.context_manager&.total_tokens || 0 # Execute the step result = @base_executor.execute(step, **) # Report token consumption after successful execution tokens_after = @context.workflow.context_manager&.total_tokens || 0 tokens_consumed = tokens_after - tokens_before step_type = StepTypeResolver.resolve(step, @context) step_name = @name_extractor.extract(step, step_type) @reporter.report(step_name, tokens_consumed, tokens_after) result end |
#execute_steps(workflow_steps) ⇒ Object
Override execute_steps to ensure reporting happens for each step
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/roast/workflow/step_executor_with_reporting.rb', line 33 def execute_steps(workflow_steps) workflow_steps.each_with_index do |step, index| is_last_step = (index == workflow_steps.length - 1) case step when Hash execute(step, is_last_step:) when Array execute(step, is_last_step:) when String execute(step, is_last_step:) # Handle pause after string steps if @context.workflow.pause_step_name == step Kernel.binding.irb # rubocop:disable Lint/Debugger end else # For other types, delegate to base executor execute(step, is_last_step:) end end end |
#respond_to_missing?(method, include_private = false) ⇒ Boolean
63 64 65 |
# File 'lib/roast/workflow/step_executor_with_reporting.rb', line 63 def respond_to_missing?(method, include_private = false) @base_executor.respond_to?(method, include_private) || super end |