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
// SPDX-FileCopyrightText: 2026 Andrei G <bug-ops>
// SPDX-License-Identifier: MIT OR Apache-2.0
/// Runtime mode flags determined at startup from CLI arguments.
///
/// This struct is intentionally `Copy` — it carries only boolean flags
/// and is passed by value to subsystem initializers. Adding it to function
/// signatures replaces individual `tui_mode: bool` parameters and provides
/// a single extension point for future runtime flags.
///
/// # Examples
///
/// ```
/// use zeph_core::RuntimeContext;
///
/// let ctx = RuntimeContext { tui_mode: true, daemon_mode: false };
/// assert!(ctx.suppress_stderr());
///
/// let default_ctx = RuntimeContext::default();
/// assert!(!default_ctx.suppress_stderr());
/// ```
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub struct RuntimeContext {
/// True when the TUI dashboard is active (ratatui owns stderr).
pub tui_mode: bool,
/// True when running as a headless daemon (a2a feature).
///
/// This field is forward-looking: it is set at daemon entry but has no
/// current consumer beyond [`RuntimeContext::suppress_stderr`]. When the
/// a2a subsystem grows additional mode-aware initializers, they will read
/// this field rather than threading a new `daemon_mode: bool` parameter.
pub daemon_mode: bool,
}
impl RuntimeContext {
/// Returns `true` when stderr output should be suppressed.
///
/// Stderr is suppressed when the TUI owns the terminal (raw mode) or when
/// running as a headless daemon with no controlling terminal.
#[must_use]
pub fn suppress_stderr(&self) -> bool {
self.tui_mode || self.daemon_mode
}
}
#[cfg(test)]
mod tests {
use super::RuntimeContext;
#[test]
fn suppress_stderr_daemon_only() {
let ctx = RuntimeContext {
tui_mode: false,
daemon_mode: true,
};
assert!(ctx.suppress_stderr());
}
#[test]
fn suppress_stderr_both_true() {
let ctx = RuntimeContext {
tui_mode: true,
daemon_mode: true,
};
assert!(ctx.suppress_stderr());
}
#[test]
fn suppress_stderr_default_is_false() {
assert!(!RuntimeContext::default().suppress_stderr());
}
}