Skip to main content

Module daemon

Module daemon 

Source
Expand description

Background daemon for DiffLore.

Consumes the SQLite outbox in a loop so AI-agent hooks stay on the fast path (hook = enqueue, daemon = drain). Does NOT listen on any HTTP port — the local stack is Rust-on-SQLite so in-process access is strictly cheaper than IPC. Lifecycle management uses a PID file at ~/.difflore/daemon.pid; liveness is checked with kill(pid, 0).

run is the only long-running entry point; it installs a SIGTERM / SIGINT handler that breaks out of the drain loop cleanly and deletes the PID file before returning.

Enums§

DaemonStatus
Report the daemon liveness state.
StopOutcome
What stop actually did — useful for UX messages.

Functions§

pid_path
Path of the PID file used by the internal daemon helpers.
run
Long-running drain loop. Claims outbox rows and dispatches them to the cloud on a fixed cadence. Only exits on SIGTERM / SIGINT or on a genuinely fatal error (DB open failure, etc.).
status
Probe the PID file + live process without mutating anything.
stop
Gracefully stop the daemon. Sends SIGTERM, waits up to grace_secs for the process to exit, then escalates to SIGKILL. Removes a stale PID file regardless of which path exits. Returns what actually happened so the CLI can phrase the UX correctly.