Module: LanguageOperator::CLI::Commands::Agent::Helpers::SynthesisWatcher

Included in:
Base
Defined in:
lib/language_operator/cli/commands/agent/helpers/synthesis_watcher.rb

Overview

Helper methods for watching agent synthesis status

Instance Method Summary collapse

Instance Method Details

#check_synthesis_status(k8s, agent_name, namespace, synthesis_data, start_time) ⇒ Hash?

Check synthesis status for a specific agent

Parameters:

  • k8s (Kubernetes::Client)

    Kubernetes client

  • agent_name (String)

    Agent name

  • namespace (String)

    Namespace

  • synthesis_data (Hash)

    Hash to populate with synthesis metadata

  • start_time (Time)

    Synthesis start time

Returns:

  • (Hash, nil)

    Synthesis status or nil if not complete



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/language_operator/cli/commands/agent/helpers/synthesis_watcher.rb', line 68

def check_synthesis_status(k8s, agent_name, namespace, synthesis_data, start_time)
  agent = k8s.get_resource('LanguageAgent', agent_name, namespace)
  conditions = agent.dig('status', 'conditions') || []
  synthesis_status = agent.dig('status', 'synthesis')

  # Capture synthesis metadata
  if synthesis_status
    synthesis_data[:model] = synthesis_status['model']
    synthesis_data[:token_count] = synthesis_status['tokenCount']
  end

  # Check for synthesis completion
  synthesized = conditions.find { |c| c['type'] == 'Synthesized' }
  return nil unless synthesized

  if synthesized['status'] == 'True'
    duration = Time.now - start_time
    { success: true, duration: duration, **synthesis_data }
  elsif synthesized['status'] == 'False'
    Formatters::ProgressFormatter.error("Synthesis failed: #{synthesized['message']}")
    { success: false }
  end
end

#watch_synthesis_status(k8s, agent_name, namespace) ⇒ Hash

Watch synthesis status with progress spinner

Parameters:

  • k8s (Kubernetes::Client)

    Kubernetes client

  • agent_name (String)

    Agent name

  • namespace (String)

    Namespace

Returns:

  • (Hash)

    Synthesis result with success status and metadata



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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/language_operator/cli/commands/agent/helpers/synthesis_watcher.rb', line 16

def watch_synthesis_status(k8s, agent_name, namespace)
  max_wait = 600 # Wait up to 10 minutes (local models can be slow)
  interval = 2   # Check every 2 seconds
  elapsed = 0
  start_time = Time.now
  synthesis_data = {}

  Formatters::ProgressFormatter.with_spinner('Synthesizing code from instructions') do
    synthesis_result = nil
    loop do
      status = check_synthesis_status(k8s, agent_name, namespace, synthesis_data, start_time)
      if status
        synthesis_result = status
        break
      end

      # Timeout check
      if elapsed >= max_wait
        Formatters::ProgressFormatter.warn('Synthesis taking longer than expected, continuing in background...')
        puts
        puts 'Check synthesis status with:'
        puts "  langop agent inspect #{agent_name}"
        synthesis_result = { success: true, timeout: true }
        break
      end

      sleep interval
      elapsed += interval
    end
    synthesis_result
  rescue K8s::Error::NotFound
    # Agent not found yet, keep waiting
    sleep interval
    elapsed += interval
    retry if elapsed < max_wait

    Formatters::ProgressFormatter.error('Agent resource not found')
    return { success: false }
  rescue StandardError => e
    Formatters::ProgressFormatter.warn("Could not watch synthesis: #{e.message}")
    return { success: true } # Continue anyway
  end
end