1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//! Complete JSON envelopes — and the single point where the agent-native
//! surface is applied.
//!
//! GAP-SG-142 put the reshaping here rather than in each subcommand precisely
//! because there is exactly one function pair every payload passes through.
//! One implementation covers the whole CLI and no command has to know the
//! surface exists.
//!
//! The `active()` check keeps the fast path intact: with no shaping flag set,
//! the value is serialized straight from its own `Serialize` impl and the
//! envelope is byte-for-byte what it was before the surface existed.
use sink;
use crateAppError;
use Serialize;
/// Serializes `value` and returns its JSON text, applying the agent-native
/// surface when one is installed.
///
/// `pretty` selects indented output; compact is a single line.
/// Whether the envelope should be indented.
///
/// Indentation is for a human reading a terminal. Off a terminal it is bytes a
/// consumer pays for and never reads, so the envelope goes out compact.
///
/// GAP-SG-170: this also keeps `--max-output-bytes` honest. `budget::enforce`
/// measures with `serde_json::to_string`, the compact form, while emission used
/// `to_string_pretty` unconditionally. The ceiling was therefore enforced on one
/// serialization and violated on another — measured at 8 659 bytes emitted for a
/// declared cap of 8 000, with the overshoot growing alongside the cap because
/// indentation scales with content. With the surface active the answer is never
/// indented, so the byte the budget counts is the byte the caller receives.
/// Serializes `value` as JSON and writes it to stdout with a trailing newline.
///
/// Indented on a terminal, compact everywhere else; see [`should_indent`].
///
/// Flushes stdout after writing. A `BrokenPipe` error is silenced so that
/// piping to consumers that close early (e.g. `head`) does not surface an error.
///
/// # Errors
/// Returns `Err` when serialization fails or when a non-`BrokenPipe` I/O error occurs.
/// Serializes `value` as compact (single-line) JSON and writes it to stdout with a trailing newline.
///
/// Flushes stdout after writing. A `BrokenPipe` error is silenced.
///
/// # Errors
/// Returns `Err` when serialization fails or when a non-`BrokenPipe` I/O error occurs.