Skip to main content

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 error;
51pub mod ipc;
52pub mod notify;
53pub mod pid;
54pub mod query;
55pub mod salsa;
56pub mod start;
57pub mod stats;
58pub mod status;
59pub mod stop;
60pub mod types;
61pub mod warm;
62#[path = "daemon.rs"]
63pub mod daemon_impl;
64pub use daemon_impl as daemon;
65
66// Re-export core types for convenience
67pub use error::{DaemonError, DaemonResult};
68pub use ipc::{
69    check_socket_alive, cleanup_socket, read_command, send_command, send_raw_command,
70    send_response, validate_socket_path, IpcListener, IpcStream, CONNECTION_TIMEOUT_SECS,
71    MAX_MESSAGE_SIZE, READ_TIMEOUT_SECS,
72};
73pub use pid::{
74    check_stale_pid, cleanup_stale_pid, compute_hash, compute_pid_path, compute_socket_path,
75    is_process_running, try_acquire_lock, PidGuard,
76};
77pub use salsa::{hash_args, hash_path, CacheEntry, QueryCache, QueryKey, DEFAULT_MAX_ENTRIES};
78pub use types::{
79    // Statistics
80    AllSessionsSummary,
81    CacheFileInfo,
82    // IPC Messages
83    DaemonCommand,
84    // Configuration
85    DaemonConfig,
86    DaemonResponse,
87    // Status
88    DaemonStatus,
89    DedupStats,
90    GlobalStats,
91    HookStats,
92    SalsaCacheStats,
93    SessionStats,
94    // Constants
95    DEFAULT_REINDEX_THRESHOLD,
96    HOOK_FLUSH_THRESHOLD,
97    IDLE_TIMEOUT,
98    IDLE_TIMEOUT_SECS,
99};
100
101// Re-export daemon components
102pub use daemon_impl::TLDRDaemon;
103
104// Re-export CLI argument types for main.rs integration
105pub use cache_clear::CacheClearArgs;
106pub use cache_stats::CacheStatsArgs;
107pub use notify::DaemonNotifyArgs;
108pub use query::DaemonQueryArgs;
109pub use start::DaemonStartArgs;
110pub use stats::StatsArgs;
111pub use status::DaemonStatusArgs;
112pub use stop::DaemonStopArgs;
113pub use warm::WarmArgs;