Module: LanguageOperator::CLI::Commands::System::Helpers::TemplateLoader

Defined in:
lib/language_operator/cli/commands/system/helpers/template_loader.rb

Overview

Template loading utilities

Instance Method Summary collapse

Instance Method Details

#fetch_from_operator(type) ⇒ Object

Fetch template from operator ConfigMap via kubectl



21
22
23
24
25
26
27
# File 'lib/language_operator/cli/commands/system/helpers/template_loader.rb', line 21

def fetch_from_operator(type)
  configmap_name = type == 'agent' ? 'agent-synthesis-template' : 'persona-distillation-template'
  result = `kubectl get configmap #{configmap_name} -n language-operator-system -o jsonpath='{.data.template}' 2>/dev/null`
  result.empty? ? nil : result
rescue StandardError
  nil
end

#load_bundled_template(type) ⇒ Object

Load bundled template from gem



30
31
32
33
34
# File 'lib/language_operator/cli/commands/system/helpers/template_loader.rb', line 30

def load_bundled_template(type)
  filename = type == 'agent' ? 'agent_synthesis.tmpl' : 'persona_distillation.tmpl'
  template_path = File.join(__dir__, '..', '..', '..', 'templates', filename)
  File.read(template_path)
end

#load_template(type) ⇒ Object

Load template from bundled gem or operator ConfigMap



11
12
13
14
15
16
17
18
# File 'lib/language_operator/cli/commands/system/helpers/template_loader.rb', line 11

def load_template(type)
  # Try to fetch from operator ConfigMap first (if kubectl available)
  template = fetch_from_operator(type)
  return template if template

  # Fall back to bundled template
  load_bundled_template(type)
end

#render_go_template(template, data) ⇒ Object

Render Go-style template (LanguageOperator::CLI::Commands::System::Helpers::TemplateLoader.{{.Variable}) Simplified implementation for basic variable substitution



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/language_operator/cli/commands/system/helpers/template_loader.rb', line 38

def render_go_template(template, data)
  result = template.dup

  # Handle {{if .ErrorContext}} - remove this section for test-synthesis
  result.gsub!(/{{if \.ErrorContext}}.*?{{else}}/m, '')
  result.gsub!(/{{end}}/, '')

  # Replace simple variables {{.Variable}}
  data.each do |key, value|
    result.gsub!("{{.#{key}}}", value.to_s)
  end

  result
end