Skip to main content

NotificationService

Struct NotificationService 

Source
pub struct NotificationService { /* private fields */ }
Expand description

Notification policy service: classification + dedup + preference persistence.

Construct with NotificationService::new and share via Arc.

Implementations§

Source§

impl NotificationService

Source

pub const DEDUP_WINDOW: Duration

Window within which a repeated dedup_key is coalesced (suppressed).

Source

pub fn new(prefs_path: PathBuf) -> Self

Creates a service, loading preferences from prefs_path.

A missing or unparsable file falls back to NotificationPreferences::default (see NotificationPreferences::load). The dedup map and relay set start empty.

Source

pub fn notify(&self, session_id: &str, event: &AgentEvent) -> Option<AgentEvent>

Classifies event and, if notification-worthy and not a recent duplicate, materialises an AgentEvent::Notification.

Returns None when the policy declines the event (disabled, gated, or not notification-worthy) or when an identical dedup_key fired within Self::DEDUP_WINDOW. On a successful (non-deduped) emission the dedup map is opportunistically pruned of entries older than the window.

Source

pub fn mint_custom( &self, session_id: &str, title: impl Into<String>, body: impl Into<String>, priority: NotificationPriority, ) -> Option<AgentEvent>

Mints a custom notification for the notify tool.

This is a passthrough classification (see policy::classify_custom): it does not consult a per-category preference — there isn’t one for arbitrary agent-chosen content — only the master enabled switch and the shared dedup window apply. Callers choose priority; title/body are used verbatim (no truncation).

Source

pub fn notify_schedule_run( &self, session_id: &str, success: bool, title: impl Into<String>, body: impl Into<String>, ) -> Option<AgentEvent>

Mints a schedule-run completion/failure notification (see policy::classify_schedule_run for the full no-double-fire rationale): it shares the SAME category/priority/dedup key that Self::notify would derive from the raw AgentEvent::Complete/ Error a scheduled run’s agent loop also emits, so this is safe to call unconditionally alongside the always-on relay — at most one of the two ever survives this service’s dedup window.

Source

pub fn preferences(&self) -> NotificationPreferences

Returns a snapshot clone of the current preferences.

Source

pub fn set_preferences(&self, prefs: NotificationPreferences) -> Result<()>

Replaces the current preferences and persists them to disk.

The in-memory value is updated first, then written to the configured path; a write error is returned but the in-memory update still stands.

Source

pub fn try_begin_relay(&self, session_id: &str) -> bool

Marks session_id as having a running relay.

Returns true when the session was newly inserted — i.e. the caller is the one that should spawn the relay. Returns false if a relay is already active for this session.

Source

pub fn end_relay(&self, session_id: &str)

Clears the running-relay marker for session_id.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more