Class: Brute::Events::PrefixedTerminalOutput

Inherits:
Handler
  • Object
show all
Defined in:
lib/brute/events/prefixed_terminal_output.rb

Overview

TerminalOutput variant that prefixes all output with a label. Useful for sub-agents running concurrently — the prefix makes it clear which agent produced each line.

Usage in a middleware stack:

use Brute::Middleware::EventHandler,
    handler_class: Brute::Events::PrefixedTerminalOutput,
    prefix: "explore"

Instance Method Summary collapse

Constructor Details

#initialize(inner, prefix: "sub-agent") ⇒ PrefixedTerminalOutput

Returns a new instance of PrefixedTerminalOutput.



19
20
21
22
23
# File 'lib/brute/events/prefixed_terminal_output.rb', line 19

def initialize(inner, prefix: "sub-agent")
  super(inner)
  @prefix = prefix
  @tag = "[#{@prefix}]".light_black
end

Instance Method Details

#<<(event) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/brute/events/prefixed_terminal_output.rb', line 25

def <<(event)
  $stdout.sync = true

  type = event.to_h[:type]
  data = event.to_h[:data]

  method = "on_#{type}"
  send(method, data) if respond_to?(method, true)

  super
end