Skip to main content

agent_types/
notify.rs

1//! Notify pure types: NoticeKind, Notice.
2
3use serde::{Deserialize, Serialize};
4
5/// Notice category โ€” decides how consumers render the notification.
6#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
7#[serde(rename_all = "snake_case")]
8pub enum NoticeKind {
9    /// Persistent warning line (red), does not interrupt the turn.
10    Warning,
11    /// Transient progress (status bar), next one replaces the previous.
12    Progress,
13    /// Plain information line.
14    Info,
15    /// Persistent attention line (amber), does not interrupt the turn.
16    ///
17    /// "Look at this" without "this failed": a task blocked on an
18    /// interactive prompt, a state change the human owns. Red stays the
19    /// face of things that broke ([`NoticeKind::Warning`]).
20    Attention,
21}
22
23/// Display-only notice from an engine mechanism.
24///
25/// `text` is a mechanism-level English fact; product layers (e.g. a TUI)
26/// may rewrite it per `source`.
27#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
28pub struct Notice {
29    pub kind: NoticeKind,
30    /// Emitting mechanism: "guard" / "judge" / "tool:<name>" / "reaper" ...
31    pub source: String,
32    pub text: String,
33}
34
35#[cfg(test)]
36mod tests {
37    use super::*;
38    use serde_json::json;
39
40    // Design doc ยง9: Notice/NoticeKind serde round-trip + serialization tag
41    #[test]
42    fn notice_kind_serde_snake_case_round_trip() {
43        for (kind, tag) in [
44            (NoticeKind::Warning, "warning"),
45            (NoticeKind::Progress, "progress"),
46            (NoticeKind::Info, "info"),
47            (NoticeKind::Attention, "attention"),
48        ] {
49            let v = serde_json::to_value(&kind).unwrap();
50            assert_eq!(v, json!(tag));
51            let back: NoticeKind = serde_json::from_value(v).unwrap();
52            assert_eq!(&back, &kind);
53        }
54    }
55
56    #[test]
57    fn notice_serde_round_trip() {
58        let notice = Notice {
59            kind: NoticeKind::Warning,
60            source: "guard".to_string(),
61            text: "judge unparsed โ€” treating as complete".to_string(),
62        };
63        let v = serde_json::to_value(&notice).unwrap();
64        assert_eq!(v["kind"], json!("warning"));
65        assert_eq!(v["source"], json!("guard"));
66        assert_eq!(v["text"], json!("judge unparsed โ€” treating as complete"));
67
68        let back: Notice = serde_json::from_value(v).unwrap();
69        assert_eq!(back, notice);
70    }
71}