Class: SwarmCLI::Formatters::JsonFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/swarm_cli/formatters/json_formatter.rb

Overview

JsonFormatter streams JSON log entries in real-time for consumption by scripts. Each log entry is output as a single line of JSON (newline-delimited JSON).

No colors, no spinners, no animations - just pure structured data.

Instance Method Summary collapse

Constructor Details

#initialize(output: $stdout) ⇒ JsonFormatter

Returns a new instance of JsonFormatter.



10
11
12
# File 'lib/swarm_cli/formatters/json_formatter.rb', line 10

def initialize(output: $stdout)
  @output = output
end

Instance Method Details

#on_error(error:, duration: nil) ⇒ Object

Called when swarm execution fails

No action needed - SwarmSDK's swarm_stop event already contains error information



39
40
41
# File 'lib/swarm_cli/formatters/json_formatter.rb', line 39

def on_error(error:, duration: nil)
  # SwarmSDK emits swarm_stop automatically with error information
end

#on_log(entry) ⇒ Object

Called for each log entry from SwarmSDK



24
25
26
# File 'lib/swarm_cli/formatters/json_formatter.rb', line 24

def on_log(entry)
  emit(entry)
end

#on_start(config_path:, swarm_name:, lead_agent:, prompt:) ⇒ Object

Called when swarm execution starts

Note: SwarmSDK now automatically emits swarm_start as a log event, so we don't emit it here to avoid duplicates. The swarm_start event will flow through on_log() from the SwarmSDK event stream.



19
20
21
# File 'lib/swarm_cli/formatters/json_formatter.rb', line 19

def on_start(config_path:, swarm_name:, lead_agent:, prompt:)
  # SwarmSDK emits swarm_start automatically - no need to emit here
end

#on_success(result:) ⇒ Object

Called when swarm execution completes successfully

No action needed - SwarmSDK's swarm_stop event already contains all necessary information (content, last_agent, duration, metrics, etc.)



32
33
34
# File 'lib/swarm_cli/formatters/json_formatter.rb', line 32

def on_success(result:)
  # SwarmSDK emits swarm_stop automatically with complete information
end