zeph_core/runtime_context.rs
1// SPDX-FileCopyrightText: 2026 Andrei G <bug-ops>
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4/// Runtime mode flags determined at startup from CLI arguments.
5///
6/// This struct is intentionally `Copy` — it carries only boolean flags
7/// and is passed by value to subsystem initializers. Adding it to function
8/// signatures replaces individual `tui_mode: bool` parameters and provides
9/// a single extension point for future runtime flags.
10///
11/// # Examples
12///
13/// ```
14/// use zeph_core::RuntimeContext;
15///
16/// let ctx = RuntimeContext { tui_mode: true, daemon_mode: false };
17/// assert!(ctx.suppress_stderr());
18///
19/// let default_ctx = RuntimeContext::default();
20/// assert!(!default_ctx.suppress_stderr());
21/// ```
22#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
23pub struct RuntimeContext {
24 /// True when the TUI dashboard is active (ratatui owns stderr).
25 pub tui_mode: bool,
26 /// True when running as a headless daemon (a2a feature).
27 ///
28 /// This field is forward-looking: it is set at daemon entry but has no
29 /// current consumer beyond [`RuntimeContext::suppress_stderr`]. When the
30 /// a2a subsystem grows additional mode-aware initializers, they will read
31 /// this field rather than threading a new `daemon_mode: bool` parameter.
32 pub daemon_mode: bool,
33}
34
35impl RuntimeContext {
36 /// Returns `true` when stderr output should be suppressed.
37 ///
38 /// Stderr is suppressed when the TUI owns the terminal (raw mode) or when
39 /// running as a headless daemon with no controlling terminal.
40 #[must_use]
41 pub fn suppress_stderr(&self) -> bool {
42 self.tui_mode || self.daemon_mode
43 }
44}
45
46#[cfg(test)]
47mod tests {
48 use super::RuntimeContext;
49
50 #[test]
51 fn suppress_stderr_daemon_only() {
52 let ctx = RuntimeContext {
53 tui_mode: false,
54 daemon_mode: true,
55 };
56 assert!(ctx.suppress_stderr());
57 }
58
59 #[test]
60 fn suppress_stderr_both_true() {
61 let ctx = RuntimeContext {
62 tui_mode: true,
63 daemon_mode: true,
64 };
65 assert!(ctx.suppress_stderr());
66 }
67
68 #[test]
69 fn suppress_stderr_default_is_false() {
70 assert!(!RuntimeContext::default().suppress_stderr());
71 }
72}