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
// Output control: quiet mode and leveled messaging for AI-friendly output.
// When AID_QUIET=1 or --quiet is set, only errors and essential output are shown.
// Exports: is_quiet(), info(), hint(), warn(), error()
use std::sync::atomic::{AtomicBool, Ordering};
static QUIET: AtomicBool = AtomicBool::new(false);
/// Initialize quiet mode from environment.
pub fn init() {
if std::env::var("AID_QUIET").is_ok_and(|v| v == "1" || v == "true") {
QUIET.store(true, Ordering::Relaxed);
}
}
/// Set quiet mode programmatically (e.g. from --quiet flag).
pub fn set_quiet(quiet: bool) {
QUIET.store(quiet, Ordering::Relaxed);
}
#[allow(dead_code)] // Used by aid_info!/aid_hint! macros via $crate::output::is_quiet()
pub fn is_quiet() -> bool {
QUIET.load(Ordering::Relaxed)
}
/// Informational message — suppressed in quiet mode.
/// Use for: project detection, auto-applied settings, internal bookkeeping.
#[macro_export]
macro_rules! aid_info {
($($arg:tt)*) => {
if !$crate::output::is_quiet() {
eprintln!($($arg)*);
}
};
}
/// Hint/tip for the user — suppressed in quiet mode.
/// Use for: "aid watch --quiet ...", "aid merge ...", TUI suggestions.
#[macro_export]
macro_rules! aid_hint {
($($arg:tt)*) => {
if !$crate::output::is_quiet() {
eprintln!($($arg)*);
}
};
}
/// Warning — always shown, even in quiet mode.
/// Use for: rate limits, disk space, scope violations, audit safety.
#[macro_export]
macro_rules! aid_warn {
($($arg:tt)*) => {{
eprintln!($($arg)*);
}};
}
/// Error — always shown, even in quiet mode.
#[macro_export]
macro_rules! aid_error {
($($arg:tt)*) => {{
eprintln!($($arg)*);
}};
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn quiet_mode_defaults_off() {
assert!(!is_quiet());
}
#[test]
fn set_quiet_toggles_mode() {
set_quiet(true);
assert!(is_quiet());
set_quiet(false);
assert!(!is_quiet());
}
}