Class: EnhanceSwarm::OutputStreamer

Inherits:
Object
  • Object
show all
Defined in:
lib/enhance_swarm/output_streamer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(max_lines: 10) ⇒ OutputStreamer

Returns a new instance of OutputStreamer.



10
11
12
13
14
15
16
17
# File 'lib/enhance_swarm/output_streamer.rb', line 10

def initialize(max_lines: 10)
  @max_lines = max_lines
  @agent_outputs = {}
  @active_agents = {}
  @output_mutex = Mutex.new
  @display_thread = nil
  @running = false
end

Instance Attribute Details

#active_agentsObject (readonly)

Returns the value of attribute active_agents.



8
9
10
# File 'lib/enhance_swarm/output_streamer.rb', line 8

def active_agents
  @active_agents
end

#agent_outputsObject (readonly)

Returns the value of attribute agent_outputs.



8
9
10
# File 'lib/enhance_swarm/output_streamer.rb', line 8

def agent_outputs
  @agent_outputs
end

Instance Method Details

#add_agent(agent_id, process_pid, role: 'agent') ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/enhance_swarm/output_streamer.rb', line 30

def add_agent(agent_id, process_pid, role: 'agent')
  @output_mutex.synchronize do
    @active_agents[agent_id] = {
      pid: process_pid,
      role: role,
      start_time: Time.now,
      status: 'running'
    }
    @agent_outputs[agent_id] = {
      lines: [],
      last_update: Time.now
    }
  end
  
  # Start monitoring this agent's output (in real implementation)
  # start_agent_monitor(agent_id, process_pid)
end

#add_output_line(agent_id, line) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/enhance_swarm/output_streamer.rb', line 57

def add_output_line(agent_id, line)
  @output_mutex.synchronize do
    return unless @agent_outputs[agent_id]
    
    # Clean and format the line
    clean_line = clean_output_line(line)
    return if clean_line.empty?
    
    @agent_outputs[agent_id][:lines] << {
      text: clean_line,
      timestamp: Time.now
    }
    
    # Keep only recent lines
    if @agent_outputs[agent_id][:lines].length > @max_lines
      @agent_outputs[agent_id][:lines].shift
    end
    
    @agent_outputs[agent_id][:last_update] = Time.now
  end
end

#remove_agent(agent_id, status: 'completed') ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/enhance_swarm/output_streamer.rb', line 48

def remove_agent(agent_id, status: 'completed')
  @output_mutex.synchronize do
    if @active_agents[agent_id]
      @active_agents[agent_id][:status] = status
      @active_agents[agent_id][:end_time] = Time.now
    end
  end
end

#start_streamingObject



19
20
21
22
# File 'lib/enhance_swarm/output_streamer.rb', line 19

def start_streaming
  @running = true
  @display_thread = Thread.new { display_loop }
end

#stop_streamingObject



24
25
26
27
28
# File 'lib/enhance_swarm/output_streamer.rb', line 24

def stop_streaming
  @running = false
  @display_thread&.join
  clear_display
end