streamJsonEventLine function

String? streamJsonEventLine(
  1. AgentEvent event
)

Maps one AgentEvent to its stream-json line, or null when the event is filtered out of the stream (fa-native events).

Like the HEP writer, the dispatch is split into small defaulted switches (lifecycle vs tool-execution families) to stay under the repo's CRAP gate; the sealed-set triage AC (issue #695 AC2) is enforced by the encoder test, which enumerates every AgentEvent subtype (count tripwire included) and asserts each is mapped or explicitly filtered.

Implementation

String? streamJsonEventLine(AgentEvent event) {
  final Map<String, dynamic>? json;
  if (event is ToolExecutionStartEvent ||
      event is ToolExecutionUpdateEvent ||
      event is ToolExecutionEndEvent) {
    json = _toolExecutionEventJson(event);
  } else {
    json = _lifecycleEventJson(event);
  }
  if (json == null) return null;
  return jsonEncode(json);
}