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 trace_context (
32    watch_path TEXT PRIMARY KEY,
33    trace_id   TEXT NOT NULL,
34    updated_at TEXT NOT NULL
35);
36
37CREATE TABLE IF NOT EXISTS daemon_errors (
38    id         INTEGER PRIMARY KEY AUTOINCREMENT,
39    watch_path TEXT,
40    operation  TEXT NOT NULL,
41    message    TEXT NOT NULL,
42    ts         TEXT NOT NULL
43);
44"#;
45
46mod command;
47mod events;
48mod process;
49mod state;
50mod watch;
51
52#[cfg(test)]
53mod tests;
54
55pub(crate) use command::run_command;
56pub use command::DaemonCommands;
57pub use process::{start, status, stop};
58pub use state::is_running;
59pub use watch::run_watch_loop;