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}
16
17/// Display-only notice from an engine mechanism.
18///
19/// `text` is a mechanism-level English fact; product layers (e.g. a TUI)
20/// may rewrite it per `source`.
21#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
22pub struct Notice {
23    pub kind: NoticeKind,
24    /// Emitting mechanism: "guard" / "judge" / "tool:<name>" / "reaper" ...
25    pub source: String,
26    pub text: String,
27}
28
29#[cfg(test)]
30mod tests {
31    use super::*;
32    use serde_json::json;
33
34    // Design doc ยง9: Notice/NoticeKind serde round-trip + serialization tag
35    #[test]
36    fn notice_kind_serde_snake_case_round_trip() {
37        for (kind, tag) in [
38            (NoticeKind::Warning, "warning"),
39            (NoticeKind::Progress, "progress"),
40            (NoticeKind::Info, "info"),
41        ] {
42            let v = serde_json::to_value(&kind).unwrap();
43            assert_eq!(v, json!(tag));
44            let back: NoticeKind = serde_json::from_value(v).unwrap();
45            assert_eq!(&back, &kind);
46        }
47    }
48
49    #[test]
50    fn notice_serde_round_trip() {
51        let notice = Notice {
52            kind: NoticeKind::Warning,
53            source: "guard".to_string(),
54            text: "judge unparsed โ€” treating as complete".to_string(),
55        };
56        let v = serde_json::to_value(&notice).unwrap();
57        assert_eq!(v["kind"], json!("warning"));
58        assert_eq!(v["source"], json!("guard"));
59        assert_eq!(v["text"], json!("judge unparsed โ€” treating as complete"));
60
61        let back: Notice = serde_json::from_value(v).unwrap();
62        assert_eq!(back, notice);
63    }
64}