Class: Roast::Workflow::ConfigurationLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/roast/workflow/configuration_loader.rb

Overview

Handles loading and parsing of workflow configuration files

Class Method Summary collapse

Class Method Details

.extract_context_management(config_hash) ⇒ Hash

Extract context management configuration

Parameters:

  • config_hash (Hash)

    The configuration hash

Returns:

  • (Hash)

    The context management configuration with defaults



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/roast/workflow/configuration_loader.rb', line 150

def extract_context_management(config_hash)
  default_config = {
    enabled: true,
    strategy: "auto",
    threshold: 0.8,
    max_tokens: nil,
    retain_steps: [],
  }

  return default_config unless config_hash["context_management"].is_a?(Hash)

  config = config_hash["context_management"]
  {
    enabled: config.fetch("enabled", default_config[:enabled]),
    strategy: config.fetch("strategy", default_config[:strategy]),
    threshold: config.fetch("threshold", default_config[:threshold]),
    max_tokens: config["max_tokens"],
    retain_steps: config.fetch("retain_steps", default_config[:retain_steps]),
  }
end

.extract_functions(config_hash) ⇒ Hash

Extract function configurations

Parameters:

  • config_hash (Hash)

    The configuration hash

Returns:

  • (Hash)

    The functions configuration or empty hash



128
129
130
# File 'lib/roast/workflow/configuration_loader.rb', line 128

def extract_functions(config_hash)
  config_hash["functions"] || {}
end

.extract_mcp_tools(config_hash) ⇒ Array

Extract MCP tools from the configuration

Parameters:

  • config_hash (Hash)

    The configuration hash

Returns:

  • (Array)

    The MCP tools array or empty array



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/roast/workflow/configuration_loader.rb', line 104

def extract_mcp_tools(config_hash)
  tools = config_hash["tools"]&.select { |tool| tool.is_a?(Hash) } || []
  return [] if tools.none?

  mcp_tools = []
  tools.each do |tool|
    tool.each do |tool_name, config|
      next unless config.is_a?(Hash) && (config["url"] || config["command"])

      mcp_tools << Configuration::MCPTool.new(
        name: tool_name,
        config: config,
        only: config["only"],
        except: config["except"],
      )
    end
  end

  mcp_tools
end

.extract_model(config_hash) ⇒ String?

Extract model from the configuration

Parameters:

  • config_hash (Hash)

    The configuration hash

Returns:

  • (String, nil)

    The model name if specified



135
136
137
# File 'lib/roast/workflow/configuration_loader.rb', line 135

def extract_model(config_hash)
  config_hash["model"]
end

.extract_name(config_hash, workflow_path) ⇒ String

Extract the workflow name from config or path

Parameters:

  • config_hash (Hash)

    The configuration hash

  • workflow_path (String)

    Path to the workflow file

Returns:

  • (String)

    The workflow name



48
49
50
# File 'lib/roast/workflow/configuration_loader.rb', line 48

def extract_name(config_hash, workflow_path)
  config_hash["name"] || File.basename(workflow_path, ".yml")
end

.extract_post_processing(config_hash) ⇒ Array

Extract post-processing steps from the configuration

Parameters:

  • config_hash (Hash)

    The configuration hash

Returns:

  • (Array)

    The post_processing array or empty array



69
70
71
# File 'lib/roast/workflow/configuration_loader.rb', line 69

def extract_post_processing(config_hash)
  config_hash["post_processing"] || []
end

.extract_pre_processing(config_hash) ⇒ Array

Extract pre-processing steps from the configuration

Parameters:

  • config_hash (Hash)

    The configuration hash

Returns:

  • (Array)

    The pre_processing array or empty array



62
63
64
# File 'lib/roast/workflow/configuration_loader.rb', line 62

def extract_pre_processing(config_hash)
  config_hash["pre_processing"] || []
end

.extract_steps(config_hash) ⇒ Array

Extract steps from the configuration

Parameters:

  • config_hash (Hash)

    The configuration hash

Returns:

  • (Array)

    The steps array or empty array



55
56
57
# File 'lib/roast/workflow/configuration_loader.rb', line 55

def extract_steps(config_hash)
  config_hash["steps"] || []
end

.extract_target(config_hash, options = {}) ⇒ String?

Extract target from config or options

Parameters:

  • config_hash (Hash)

    The configuration hash

  • options (Hash) (defaults to: {})

    Runtime options

Returns:

  • (String, nil)

    The target if specified



143
144
145
# File 'lib/roast/workflow/configuration_loader.rb', line 143

def extract_target(config_hash, options = {})
  options[:target] || config_hash["target"]
end

.extract_tools(config_hash) ⇒ Array, Hash

Extract tools and tool configurations from the configuration

Parameters:

  • config_hash (Hash)

    The configuration hash

Returns:

  • (Array, Hash)

    The tools array or empty array



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/roast/workflow/configuration_loader.rb', line 76

def extract_tools(config_hash)
  tools_config = config_hash["tools"] || []
  tools = []
  tool_configs = {}

  tools_config.each do |tool_entry|
    case tool_entry
    when String
      tools << tool_entry
    when Hash
      tool_entry.each do |tool_name, config|
        # Skip MCP tool configurations (those with url or command)
        if config.is_a?(Hash) && (config["url"] || config["command"])
          next
        end

        tools << tool_name
        tool_configs[tool_name] = config || {}
      end
    end
  end

  [tools, tool_configs]
end

.load(workflow_path, options = {}) ⇒ Hash

Load configuration from a YAML file

Parameters:

  • workflow_path (String)

    Path to the workflow YAML file

Returns:

  • (Hash)

    The parsed configuration hash



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/roast/workflow/configuration_loader.rb', line 11

def load(workflow_path, options = {})
  validate_path!(workflow_path)

  # Load shared.yml if it exists one level above
  parent_dir = File.dirname(workflow_path)
  shared_path = File.join(parent_dir, "..", "shared.yml")

  yaml_content = ""

  if File.exist?(shared_path)
    yaml_content += File.read(shared_path)
    yaml_content += "\n"
  end

  yaml_content += File.read(workflow_path)

  # Use comprehensive validation if requested
  if options[:comprehensive_validation]
    validator = Validators::ValidationOrchestrator.new(yaml_content, workflow_path)
    unless validator.valid?
      raise_validation_errors(validator)
    end

    # Show warnings if any
    display_warnings(validator.warnings) if validator.warnings.any?
  end

  config_hash = YAML.load(yaml_content, aliases: true)

  validate_config!(config_hash)
  config_hash
end