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
//! Operator-local supervisor daemon (ADR-006, M2 §6).
//!
//! `zero-headless` ships two artifacts:
//!
//! 1. **`zero-headlessd` binary** — the supervisor daemon. Runs
//! under launchd (macOS) or systemd (Linux); listens on a
//! Unix socket at
//! `<zero_dir>/operators/<operator-slug>/sock` for typed line-delimited JSON
//! requests from the `zero` CLI (and, in M3, the Telegram
//! bot). Persists its "operator intended me to be running"
//! state under
//! `<zero_dir>/operators/<operator-slug>/state/headless.json` so a
//! crash-and-restart recovers the operator's posture rather
//! than silently defaulting to "off".
//!
//! 2. **Library surface** — the [`protocol`] envelopes, the
//! [`client::Client`] dialer, and the [`state::State`]
//! persistence type. The `zero-commands` crate's real
//! `SupervisorSource` adapter (shipped in §6, not in this
//! module) is built on top of [`client::Client`] so the
//! shipped binary and the CLI-side dialer speak the same
//! wire format by construction.
//!
//! # Invariants
//!
//! - **Line-delimited JSON framing.** One request per line,
//! one response per line. Chosen over length-prefixed framing
//! so an operator debugging a stuck daemon can
//! `nc -U <zero_dir>/operators/<operator-slug>/sock` and read
//! what the daemon is saying without tooling. Every envelope has
//! a `kind` tag so the
//! protocol is forward-extensible.
//!
//! - **Kill-switch paths are never gated.** A `/kill` from the
//! CLI, a `SIGTERM`, or a Telegram-originated kill all reach
//! the same `graceful_drain` path. Silence on a kill request
//! is the 2 AM failure mode the architecture exists to
//! prevent — the daemon logs a single-line breadcrumb for
//! every kill attempt and honours it within a hard deadline.
//!
//! - **Three honest questions in one `status`.** The protocol's
//! [`protocol::StatusReply`] answers (a) is the daemon
//! running, (b) is the engine reachable from the daemon, (c)
//! what was the daemon's most recent action. Silence on any
//! of the three is a lie; the protocol type forces all three
//! to be populated on every reply.
//!
//! The daemon itself does *not* make trading decisions — those
//! live in the engine. `zero-headlessd` is a watchdog + kill-
//! switch surface + structured keepalive; it exists so an
//! operator who closes their laptop still has a path to halt
//! the engine from a phone (via the M3 Telegram bot) or a
//! second terminal (via `zero kill`, §8).
pub use ;
pub use ;
pub use ;
pub use ;