Skip to main content

innate_core/daemon/
mod.rs

1//! Daemon: background log-watcher that bridges closed systems to the knowledge layer.
2//!
3//! Design: §九 — daemon does NOT open the knowledge database directly.
4//! All knowledge-layer actions go through the CLI binary (subprocess).
5//! Daemon state (offsets, inode, processed events) lives in daemon_state.sqlite only.
6//!
7//! Platform: Linux (fork + /proc). Non-Linux: return an informative error.
8
9use std::path::Path;
10
11use crate::errors::Result;
12
13// ── Schema for daemon_state.sqlite ──────────────────────────────────────────
14
15const DAEMON_SCHEMA: &str = r#"
16CREATE TABLE IF NOT EXISTS watch_state (
17    watch_path            TEXT PRIMARY KEY,
18    last_processed_offset INTEGER NOT NULL DEFAULT 0,
19    last_processed_inode  TEXT,
20    updated_at            TEXT NOT NULL
21);
22
23CREATE TABLE IF NOT EXISTS processed_events (
24    event_id   TEXT PRIMARY KEY,
25    watch_path TEXT,
26    trace_id   TEXT,
27    event_type TEXT,
28    ts         TEXT NOT NULL
29);
30
31CREATE TABLE IF NOT EXISTS daemon_errors (
32    id         INTEGER PRIMARY KEY AUTOINCREMENT,
33    watch_path TEXT,
34    operation  TEXT NOT NULL,
35    message    TEXT NOT NULL,
36    ts         TEXT NOT NULL
37);
38"#;
39
40mod command;
41mod events;
42mod process;
43mod state;
44mod watch;
45
46#[cfg(test)]
47mod tests;
48
49pub(crate) use command::run_command;
50pub use command::DaemonCommands;
51pub use process::{start, status, stop};
52pub use state::{health, is_running};
53pub use watch::run_watch_loop;