Skip to main content

Module brain_control

Module brain_control 

Source
Expand description

oxibrain daemon lifecycle control — bring a brain·down daemon back.

The TUI’s health chip only observes (brain.rs probes); this module acts. When the daemon is installed but stopped, /brain revives it:

  1. launchd (macOS, plist present): launchctl bootstrap a service that is not loaded, launchctl kickstart one that is. launchd keeps supervising it afterwards (KeepAlive), which is the correct home for a daemon — oxibrain serve --daemon deliberately does not fork.
  2. Detached spawn (no plist / non-macOS): start oxibrain serve --daemon --socket <canonical> in its own process group with null stdio. The orphan survives oxicode’s exit.

When the binary is missing entirely, revival is impossible — the caller surfaces install guidance instead of pretending.

Structs§

BrainControlReport
Environment facts the plan is derived from (injectable for tests).

Enums§

ReviveAction
What the revive step decided to do.

Constants§

BRAIN_SERVICE_LABEL
launchd service label used by the oxibrain plist.

Functions§

brain_plist_path
Canonical plist location (~/Library/LaunchAgents/com.oxi.oxibrain.plist).
find_oxibrain_binary
Locate the oxibrain binary: ~/.cargo/bin first (cargo-installed), then PATH.
probe_control
Probe the environment for a control report.
revive
Run the plan and wait for the daemon to answer a ping. Returns human-readable outcome lines on success.
revive_plan
Decide how to revive from a control report. Pure.
service_loaded
Whether the launchd service is loaded (macOS). Non-macOS: false.
should_auto_revive
Whether the background prober should attempt an automatic revive. One attempt per session (success or failure — a broken daemon must not spawn a retry loop), only for users who enabled memory, and never when the binary is missing (that is an install decision, not a restart). Pure.