tldr_cli/commands/daemon/mod.rs
1//! Daemon subsystem for TLDR CLI
2//!
3//! Provides a persistent background process that holds indexes in memory for fast
4//! queries, implements Salsa-style query memoization, and tracks usage statistics.
5//!
6//! # Architecture
7//!
8//! ```text
9//! +-----------------------------------------------------------------+
10//! | CLI Layer |
11//! | daemon start | stop | status | query | notify | stats | warm |
12//! +-----------------------------------------------------------------+
13//! |
14//! +-----------v-----------+
15//! | IPC Transport |
16//! | Unix Socket (Unix) |
17//! | TCP Socket (Windows) |
18//! +-----------+-----------+
19//! |
20//! +-----------------------------------------------------------------+
21//! | TLDRDaemon |
22//! | +-------------+ +-------------+ +-------------+ |
23//! | | SalsaDB | | Dedup Index | | Stats Store | |
24//! | | (memoize) | | (content- | | (per-session| |
25//! | | | | hash) | | tracking) | |
26//! | +-------------+ +-------------+ +-------------+ |
27//! +-----------------------------------------------------------------+
28//! ```
29//!
30//! # Modules
31//!
32//! - `types`: Core data types for configuration, status, and statistics
33//! - `error`: Error types for daemon operations
34//! - `pid`: PID file locking for daemon singleton enforcement
35//! - `ipc`: IPC client/server for socket communication
36//! - `salsa`: Salsa-style incremental computation cache
37//! - `daemon`: Main daemon process and command handlers
38//! - `start`: Daemon start command
39//! - `stop`: Daemon stop command
40//! - `status`: Daemon status command
41//! - `query`: Low-level query passthrough command
42//! - `notify`: File change notification command
43//! - `warm`: Cache warming command
44//! - `stats`: Usage statistics command
45//! - `cache_stats`: Cache statistics command
46//! - `cache_clear`: Cache clearing command
47
48pub mod cache_clear;
49pub mod cache_stats;
50pub mod daemon_active;
51#[path = "daemon.rs"]
52pub mod daemon_impl;
53pub mod error;
54pub mod ipc;
55pub mod notify;
56pub mod pid;
57pub mod query;
58pub mod salsa;
59pub mod start;
60pub mod stats;
61pub mod status;
62pub mod stop;
63pub mod types;
64pub mod warm;
65pub use daemon_impl as daemon;
66
67// Re-export core types for convenience
68pub use error::{DaemonError, DaemonResult};
69pub use ipc::{
70 check_socket_alive, cleanup_socket, read_command, send_command, send_raw_command,
71 send_response, validate_socket_path, IpcListener, IpcStream, CONNECTION_TIMEOUT_SECS,
72 MAX_MESSAGE_SIZE, READ_TIMEOUT_SECS,
73};
74pub use pid::{
75 check_stale_pid, cleanup_stale_pid, compute_hash, compute_pid_path, compute_socket_path,
76 is_process_running, try_acquire_lock, PidGuard,
77};
78pub use salsa::{hash_args, hash_path, CacheEntry, QueryCache, QueryKey, DEFAULT_MAX_ENTRIES};
79pub use types::{
80 // Statistics
81 AllSessionsSummary,
82 CacheFileInfo,
83 // IPC Messages
84 DaemonCommand,
85 // Configuration
86 DaemonConfig,
87 DaemonResponse,
88 // Status
89 DaemonStatus,
90 DedupStats,
91 GlobalStats,
92 HookStats,
93 SalsaCacheStats,
94 SessionStats,
95 // Constants
96 DEFAULT_REINDEX_THRESHOLD,
97 HOOK_FLUSH_THRESHOLD,
98 IDLE_TIMEOUT,
99 IDLE_TIMEOUT_SECS,
100};
101
102// Re-export daemon components
103pub use daemon_impl::TLDRDaemon;
104
105// Re-export CLI argument types for main.rs integration
106pub use cache_clear::CacheClearArgs;
107pub use cache_stats::CacheStatsArgs;
108pub use notify::DaemonNotifyArgs;
109pub use query::DaemonQueryArgs;
110pub use start::DaemonStartArgs;
111pub use stats::StatsArgs;
112pub use status::DaemonStatusArgs;
113pub use stop::DaemonStopArgs;
114pub use warm::WarmArgs;