Skip to main content

Module output

Module output 

Source
Expand description

Machine-readable output renderer for SubX-CLI.

This module defines the versioned JSON envelope contract used by --output json mode, the OutputMode enum surfaced as a top-level CLI flag, and the OutputRenderer abstraction routed through the command dispatcher. The text-mode renderer is a thin shim that preserves today’s interactive UX; the JSON renderer owns stdout exclusively and emits exactly one JSON document per invocation.

§Stdout / stderr discipline

  • JSON mode (--output json): stdout SHALL receive exactly one serde_json document terminated by a trailing \n. No other writes to stdout from any command, helper, or library code are permitted — print_success/print_warning/display_match_results/progress bars are silenced for the lifetime of the process. Stderr is also tightened: free-form eprintln! / println! chatter (matcher 🔍 AI Analysis Results: block, Total matches: summaries, - file_<id> candidate lines, Warning: Skipping relocation / Warning: Conflict resolution prompt not implemented, etc.) is suppressed. Structured tracing / log records (gated by RUST_LOG) are still allowed; ANSI styling and status symbols are stripped (see crate::cli::ui). With --quiet, even those structured records are suppressed except for fatal errors emitted by the renderer itself.
  • Text mode (default): behavior is unchanged from prior releases.

§Schema versioning

SCHEMA_VERSION follows semver. Additive payload changes are minor bumps; renames or removals are major bumps and require a new OpenSpec change proposal.

Structs§

Envelope
Top-level JSON envelope written to stdout in JSON mode.
ErrorEnvelope
Stable error payload carried in Envelope::error.
JsonRenderer
JSON renderer — owns stdout exclusively in JSON mode.
TextRenderer
Text renderer — preserves today’s UX as a no-op for the envelope.

Enums§

OutputMode
Output mode selected by the user via --output or SUBX_OUTPUT.

Constants§

SCHEMA_VERSION
Schema version emitted in every JSON envelope.

Traits§

OutputRenderer
Renderer trait routing success/error envelopes to the active output stream.

Functions§

active_mode
Returns the active output mode, defaulting to OutputMode::Text when not yet installed.
emit_argument_parsing_error
Emit a synthetic argument-parsing error envelope (clap failures).
emit_error
Emit an error envelope through the appropriate renderer.
emit_success
Emit a success envelope through the appropriate renderer.
emit_success_with_warnings
Emit a success envelope with optional non-fatal warnings attached.
install_active_mode
Install the resolved output mode and quiet flag globally.
is_quiet
Returns whether --quiet is active.
strip_ansi
Strip ANSI CSI escape sequences from a borrowed string.