Skip to main content

emit_json_line

Function emit_json_line 

Source
pub fn emit_json_line<T: Serialize>(value: &T)
Expand description

Writes compact JSON to stdout, silently ignoring serialization and I/O errors. Designed for NDJSON streaming where partial output is acceptable.

GAP-SG-142: NDJSON deliberately bypasses crate::agent_surface. The stream contract is one record per line and the shaping surface is defined over a complete envelope; filtering or capping a stream line by line would change what “one record” means for every consumer already parsing it.

The exclusion is a decision, not an oversight — do not “fix” it wholesale. The flags split into two groups:

  • Set-wide, never applicable here: --max-items, --sort and --dedupe-by need the complete result set before they can decide what to emit. A stream has no complete set by construction.
  • Per-line, safe to add later: --select and --truncate-content are stateless per record.

GAP-SG-215 took the contract decision that second bullet asked for, and emit_stream_record / emit_stream_trailer below are it. --select and --truncate-content act per record; everything else is refused before the first byte; the summary line carries the one agent_surface record for the whole stream. --max-output-bytes as a RUNNING budget across the stream is still open, and still needs its own decision about what a consumer sees when the budget is exhausted mid-stream — truncated line, terminator record, or silent stop. Today it is refused rather than half-applied.

This function keeps its unshaped, infallible shape for the emitters that genuinely want neither: enrich progress events and --print-schema listings, which are diagnostics rather than a record stream with a trailer.