ssh_cli/json_wire/mod.rs
1// SPDX-License-Identifier: MIT OR Apache-2.0
2// G-SECDEV-05: pure module — no `unsafe`.
3#![forbid(unsafe_code)]
4//! Typed JSON wire DTOs for agent-facing stdout/stderr contracts.
5//!
6//! # Policy (Rules Rust — JSON / NDJSON)
7//!
8//! - **Format:** classic single-root JSON (object or array), RFC 8259. Not NDJSON.
9//! - **Encoding:** UTF-8, no BOM on emit; BOM stripped on import parse.
10//! - **Shape:** one complete document per CLI invocation on the data stream
11//! (stdout success or stderr error envelope), terminated by a single LF.
12//! - **Pretty-print:** forbidden on the agent wire — compact `serde_json::to_string`
13//! only (machine interop; matches error envelope historical compact form).
14//! - **Types:** known payloads use `Serialize`/`Deserialize` structs here; `Value`
15//! is reserved for genuinely dynamic trees (`meta command-tree`) and the
16//! flexible success-envelope field map at the emission boundary.
17//! - **Must-Ignore:** import deserializers ignore unknown fields (default serde).
18//! - **I-JSON:** integers are `u16`/`u32`/`u64`/`i32` within safe practical ranges
19//! (ports, exit codes, ms timeouts, byte counts); no `NaN`/`Infinity` floats.
20//! - **Schemas:** hand-versioned under `docs/schemas/*.schema.json` (not generated
21//! at runtime). Agents validate offline; product does not embed a schema engine.
22//! - **Config on disk:** TOML, not JSON5. JSON is only for CLI machine contracts
23//! and optional `vps export --json` / import of that envelope.
24
25mod emit;
26mod execution;
27mod vps_export;
28
29pub use emit::{
30 print_json_line, print_json_line_stderr, strip_utf8_bom, write_json_line, ErrorEnvelope,
31 SuccessEnvelope, UTF8_BOM,
32};
33pub use execution::{
34 ExecBatchJson, ExecHostJson, ExecutionJson, HealthBatchJson, HealthCheckJson, HealthHostJson,
35 ScpBatchJson, ScpHostJson, ScpTransferJson, SftpBatchJson, SftpFsOpJson, SftpListEntryJson,
36 SftpListJson, SftpTransferJson, TunnelListeningJson,
37};
38pub use vps_export::{
39 ExportHostJson, ImportDefaults, ImportEnvelope, ImportHostEntry, MaskedVpsJson, VpsExportJson,
40};