agentmux_srv_core/backend/startup_mode.rs
1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! Whether this srv was started headless, for the core code that decides what the process may do (the build cache
5//! cleaner). `main` sets it once, right after it has read the command line (`headless::requested()`); the
6//! headless module (`headless.rs`, startup glue) stays where it is. Unset means not headless, as in the tests.
7
8use std::sync::atomic::{AtomicBool, Ordering};
9
10static HEADLESS: AtomicBool = AtomicBool::new(false);
11
12/// Record that this process was started headless (`--headless` or `AGENTMUX_HEADLESS=1`).
13pub fn set_headless(headless: bool) {
14 HEADLESS.store(headless, Ordering::SeqCst);
15}
16
17/// Was this process started headless? False until `set_headless` says so.
18pub fn headless() -> bool {
19 HEADLESS.load(Ordering::SeqCst)
20}
21
22#[cfg(test)]
23mod tests {
24 use super::*;
25
26 #[test]
27 fn unset_is_not_headless_and_the_flag_follows_the_last_call() {
28 assert!(!headless());
29 set_headless(true);
30 assert!(headless());
31 set_headless(false);
32 assert!(!headless());
33 }
34}