Skip to main content

Module output

Module output 

Source
Expand description

Centralized stdout/stderr emitters for CLI output formatting. Single point of terminal I/O for the CLI (stdout JSON, stderr human).

All user-visible output must go through this module; direct println! in other modules is forbidden.

Split by responsibility (GAP-SG-146), roughly in order of how structured the output is:

  • envelope — complete JSON payloads, and the single point where the agent-native reshaping surface is applied
  • error_envelope — failure payloads, with a serializer-free fallback
  • stream — NDJSON, one record per line, under the GAP-SG-215 stream contract: per-record knobs only, and the agent_surface record on the trailer rather than on every line
  • passthrough — plain text and verbatim bytes, no JSON at all
  • human — stderr diagnostics via tracing
  • sink — the one place bytes actually reach stdout
  • format--format value enums
  • responses — the serializable payload types themselves

Every public item is re-exported here, so crate::output::emit_json and friends keep working unchanged; callers never name a submodule.

Structs§

RecallItem
Individual item returned by the recall query.
RecallResponse
Full response envelope returned by the recall subcommand.
RememberResponse
JSON payload emitted by the remember subcommand.

Enums§

JsonOutputFormat
Restricted JSON-only format for commands that always emit JSON.
OutputFormat
Output format variants accepted by --format CLI flags.

Functions§

emit_error
Emits a localised error message to stderr via the tracing subscriber.
emit_error_i18n
Emits a bilingual error to stderr honouring --lang or XDG i18n.lang. Usage: output::emit_error_i18n("invariant violated", "invariante violado").
emit_error_json
Emits a configuration failure, which is permanent by construction.
emit_error_json_with_suggestion
GAP-SG-39: emits the actionable failure envelope for a classified error.
emit_json
Serializes value as JSON and writes it to stdout with a trailing newline.
emit_json_compact
Serializes value as compact (single-line) JSON and writes it to stdout with a trailing newline.
emit_json_line
Writes compact JSON to stdout, silently ignoring serialization and I/O errors. Designed for NDJSON streaming where partial output is acceptable.
emit_progress
Logs msg as a structured tracing::info! event (does not write to stdout). v1.0.89: suppressed when stderr is not a terminal (pipe) to avoid polluting JSON pipelines when the user redirects stderr with 2>&1.
emit_progress_i18n
Emits a bilingual progress message honouring --lang or XDG i18n.lang. v1.0.89: suppressed when stderr is not a terminal (pipe).
emit_raw
GAP-SG-50: writes bytes to stdout verbatim, with no trailing newline and no JSON envelope. Used by read --format raw so the pure memory body can be piped without a jaq -r '.body' round-trip. A BrokenPipe error is silenced gracefully.
emit_stream_record
Writes one record of a stream, with the per-record knobs applied.
emit_stream_trailer
Writes the line that ends a stream, carrying its one agent_surface record.
emit_text
Writes msg followed by a newline to stdout and flushes.