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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//! The STDIN/STDOUT control channel between the daemon and its
//! stdio-speaking leashed children — the laboratory host and the
//! viewer. The daemon is the child's sole spawner and owns its pipes;
//! this vocabulary rides them, one JSON object per line.
//!
//! The daemon writes one [`ChildStdioRequest`] per stdin line, and the
//! child answers each PARSED line with one [`ChildStdioAck`] on
//! stdout, echoing the request's daemon-generated `id` — the
//! correlation key. Two commands exist:
//!
//! - [`ChildStdioCommand::SetAddresses`] — the laboratory host's
//! DECLARATIVE dial list: the ENTIRE desired set of daemon
//! connections, which the host CONVERGES to (connections absent from
//! the list torn down, new ones dialed, changed-signature ones
//! re-dialed, identical live ones untouched). The daemon converges
//! the config-derived list right after the
//! [`crate::process::ServerReady`] handshake and again on every
//! `laboratories config` mutation. The ack confirms the list was
//! CONVERGED (tasks spawned / cancelled), NOT connectivity: dialing
//! retries forever. The viewer never receives this command (and
//! would ack-and-ignore it — every parsed line is acked, so the
//! daemon's ack wait can never hang on a live child).
//! - [`ChildStdioCommand::Shutdown`] — the GRACEFUL kill, both
//! children: ack first (shutdown begun), then flush and exit. The
//! host stops its started containers; the viewer closes every
//! browser tab (persisting its profile to disk) before exiting. This
//! is the ONLY kill the daemon sends these children — no signal, no
//! force path; the daemon waits, unbounded, for true process exit.
//!
//! Stdin EOF remains the host's shutdown backstop (entry drop, daemon
//! death). The viewer, by contrast, IGNORES EOF entirely: a viewer
//! launched by hand — no parent, no pipes — is a first-class mode,
//! and its stdin listener simply disarms when the line stream ends.
//!
//! This is a different transport from the `/laboratory` WebSocket
//! vocabulary and deliberately NAIVE to it. Like
//! [`crate::process::ServerReady`], these are internal pipe types:
//! plain serde, no schemas.
/// One control request, daemon → child, one JSON object per stdin
/// line: a daemon-generated `id` (echoed back in the ack) wrapped
/// around the [`ChildStdioCommand`], flattened — on the wire the line
/// is `{"id": …, "type": …, …}`.
/// The command a [`ChildStdioRequest`] carries.
/// One desired dial-list entry: `address` is a daemon `http://` base
/// (the host appends `/laboratory`); `signature` is presented in the
/// auth preamble (`None` ⇒ unauthenticated).
/// The child's answer to one [`ChildStdioRequest`], child → daemon,
/// one JSON object per stdout line: the request's `id`, echoed.
/// Parse one stdin line as a control request. `None` for anything
/// else (the child ignores unparseable lines; with nothing to
/// correlate, the daemon's ack wait would hang — the daemon only ever
/// writes well-formed lines).
/// Parse one stdout line as an ack. `None` for anything else (the
/// ready line, stray output — the daemon's reader skips them).
/// Print one ack line to stdout and flush — the child side of the
/// channel, sharing stdout with the ready line under the same
/// lock-and-flush discipline as [`crate::process::print_ready`].