Skip to main content

BrainDriver

Trait BrainDriver 

Source
pub trait BrainDriver: Send {
    // Required methods
    fn tick(
        &mut self,
        sessions: &[SessionSnapshot],
        deny_rules: &[AutoRule],
    ) -> Vec<(u32, String)>;
    fn cleanup(&mut self, sessions: &[SessionSnapshot]);
    fn accept(&mut self, pid: u32) -> Option<String>;
    fn reject(&mut self, pid: u32) -> Option<PendingSuggestion>;
    fn pending_for(&self, pid: u32) -> Option<PendingSuggestion>;
    fn pending_count(&self) -> usize;
    fn clear_pending(&mut self);
    fn set_pending(&mut self, suggestion: PendingSuggestion);
}
Expand description

Stateful brain orchestration. Unlike the read-only views, this needs &mut per tick — the engine accumulates pending suggestions, cleans up after exited sessions, and applies user accept/reject decisions.

Boxed as Box<dyn BrainDriver> rather than Arc<dyn BrainDriver> because there is exactly one owner (the TUI’s App) and every method needs &mut self. Sharing across threads is not a goal here.

Implementations may be None — the brain is opt-in (--brain flag). When the field is None the TUI renders without brain interaction.

Required Methods§

Source

fn tick( &mut self, sessions: &[SessionSnapshot], deny_rules: &[AutoRule], ) -> Vec<(u32, String)>

Run one tick of the brain loop against the current session set and the operator’s deny rules. Returns (pid, status_message) pairs for any actions the brain decided on this tick — the TUI surfaces the messages in the status bar.

Source

fn cleanup(&mut self, sessions: &[SessionSnapshot])

Drop pending suggestions for sessions that have exited. Called every refresh so the pending map stays bounded by the live session count.

Source

fn accept(&mut self, pid: u32) -> Option<String>

User accepted the pending suggestion for pid. Implementations return the log message the TUI should surface (None when there’s no suggestion to accept).

Source

fn reject(&mut self, pid: u32) -> Option<PendingSuggestion>

User rejected the pending suggestion for pid. Returns the suggestion that was rejected — the TUI logs it for replay / counterfactual analysis.

Source

fn pending_for(&self, pid: u32) -> Option<PendingSuggestion>

Lookup the pending suggestion for pid, if any. Used by detail panels and the status bar.

Source

fn pending_count(&self) -> usize

Total pending suggestion count. Used by the status bar.

Source

fn clear_pending(&mut self)

Drop every pending suggestion. Called when the brain mode flips off or the operator resets state.

Source

fn set_pending(&mut self, suggestion: PendingSuggestion)

Inject a pending suggestion for pid. Used by demo mode to fake brain activity for screenshots / recordings. Implementations may drop suggestions whose action string doesn’t map to a known engine action (rather than erroring out) — demo is best-effort.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§