Skip to main content

vtcode_config/root/
notifications.rs

1//! Notification preferences for terminal and desktop alerts
2//! (`[notifications]` under `ui.notifications`). Split from `mod.rs` to
3//! respect the 1000-line ceiling; the surface and defaults are unchanged.
4
5use serde::{Deserialize, Serialize};
6
7use super::env_bool_var;
8use super::modes::{NotificationBackend, NotificationDeliveryMode};
9
10/// Notification preferences for terminal and desktop alerts.
11#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
12#[derive(Debug, Clone, Deserialize, Serialize)]
13pub struct UiNotificationsConfig {
14    /// Master toggle for all runtime notifications.
15    #[serde(default = "default_notifications_enabled")]
16    pub enabled: bool,
17
18    /// Notification transport strategy.
19    #[serde(default)]
20    pub delivery_mode: NotificationDeliveryMode,
21
22    /// Preferred backend for desktop notification delivery.
23    #[serde(default)]
24    pub backend: NotificationBackend,
25
26    /// Suppress notifications while terminal focus is active.
27    #[serde(default = "default_notifications_suppress_when_focused")]
28    pub suppress_when_focused: bool,
29
30    /// Notify when a shell/command execution fails.
31    /// If omitted, falls back to `tool_failure` for backward compatibility.
32    #[serde(default)]
33    pub command_failure: Option<bool>,
34
35    /// Notify when a tool call fails.
36    #[serde(default = "default_notifications_tool_failure")]
37    pub tool_failure: bool,
38
39    /// Notify on runtime/system errors.
40    #[serde(default = "default_notifications_error")]
41    pub error: bool,
42
43    /// Legacy master toggle for completion notifications.
44    /// New installs should prefer `completion_success` and `completion_failure`.
45    #[serde(default = "default_notifications_completion")]
46    pub completion: bool,
47
48    /// Notify when a turn/session completes successfully.
49    /// If omitted, falls back to `completion`.
50    #[serde(default)]
51    pub completion_success: Option<bool>,
52
53    /// Notify when a turn/session is partial, failed, or cancelled.
54    /// If omitted, falls back to `completion`.
55    #[serde(default)]
56    pub completion_failure: Option<bool>,
57
58    /// Notify when human input/approval is required.
59    #[serde(default = "default_notifications_hitl")]
60    pub hitl: bool,
61
62    /// Notify when policy approval is required.
63    /// If omitted, falls back to `hitl` for backward compatibility.
64    #[serde(default)]
65    pub policy_approval: Option<bool>,
66
67    /// Notify on generic request events.
68    /// If omitted, falls back to `hitl` for backward compatibility.
69    #[serde(default)]
70    pub request: Option<bool>,
71
72    /// Notify on successful tool calls.
73    #[serde(default = "default_notifications_tool_success")]
74    pub tool_success: bool,
75
76    /// Suppression window for repeated identical notifications.
77    #[serde(default = "default_notifications_repeat_window_seconds")]
78    pub repeat_window_seconds: u64,
79
80    /// Maximum identical notifications allowed within the suppression window.
81    #[serde(default = "default_notifications_max_identical_in_window")]
82    pub max_identical_in_window: u32,
83}
84
85impl Default for UiNotificationsConfig {
86    fn default() -> Self {
87        Self {
88            enabled: default_notifications_enabled(),
89            delivery_mode: NotificationDeliveryMode::default(),
90            backend: NotificationBackend::default(),
91            suppress_when_focused: default_notifications_suppress_when_focused(),
92            command_failure: Some(default_notifications_command_failure()),
93            tool_failure: default_notifications_tool_failure(),
94            error: default_notifications_error(),
95            completion: default_notifications_completion(),
96            completion_success: Some(default_notifications_completion_success()),
97            completion_failure: Some(default_notifications_completion_failure()),
98            hitl: default_notifications_hitl(),
99            policy_approval: Some(default_notifications_policy_approval()),
100            request: Some(default_notifications_request()),
101            tool_success: default_notifications_tool_success(),
102            repeat_window_seconds: default_notifications_repeat_window_seconds(),
103            max_identical_in_window: default_notifications_max_identical_in_window(),
104        }
105    }
106}
107
108fn default_notifications_enabled() -> bool {
109    true
110}
111
112fn default_notifications_suppress_when_focused() -> bool {
113    true
114}
115
116fn default_notifications_command_failure() -> bool {
117    false
118}
119
120fn default_notifications_tool_failure() -> bool {
121    false
122}
123
124fn default_notifications_error() -> bool {
125    true
126}
127
128fn default_notifications_completion() -> bool {
129    true
130}
131
132fn default_notifications_completion_success() -> bool {
133    false
134}
135
136fn default_notifications_completion_failure() -> bool {
137    true
138}
139
140fn default_notifications_hitl() -> bool {
141    true
142}
143
144fn default_notifications_policy_approval() -> bool {
145    true
146}
147
148fn default_notifications_request() -> bool {
149    false
150}
151
152fn default_notifications_tool_success() -> bool {
153    false
154}
155
156fn default_notifications_repeat_window_seconds() -> u64 {
157    30
158}
159
160fn default_notifications_max_identical_in_window() -> u32 {
161    1
162}