Skip to main content

atuin_daemon/
events.rs

1//! Daemon events.
2//!
3//! Events are the primary communication mechanism within the daemon.
4//! Components emit events to notify others of state changes, and handle
5//! events to react to changes elsewhere in the system.
6//!
7//! External processes (like CLI commands) can also inject events via the
8//! Control gRPC service.
9
10use atuin_client::history::{History, HistoryId};
11use atuin_common::record::RecordId;
12
13/// Events that flow through the daemon's event bus.
14///
15/// Events are broadcast to all components. Each component decides which
16/// events it cares about in its `handle_event` implementation.
17#[derive(Debug, Clone)]
18pub enum DaemonEvent {
19    // ---- History lifecycle ----
20    /// A command has started running.
21    HistoryStarted(History),
22
23    /// A command has finished running.
24    HistoryEnded(History),
25
26    // ---- Sync ----
27    /// Records were synced from the server.
28    ///
29    /// The search component uses this to update its index with new history.
30    RecordsAdded(Vec<RecordId>),
31
32    /// Sync completed successfully.
33    SyncCompleted {
34        /// Number of records uploaded.
35        uploaded: usize,
36        /// Number of records downloaded.
37        downloaded: usize,
38    },
39
40    /// Sync failed.
41    SyncFailed {
42        /// Error message describing what went wrong.
43        error: String,
44    },
45
46    /// Request an immediate sync (external trigger).
47    ForceSync,
48
49    // ---- External commands ----
50    /// History was pruned - search index needs a full rebuild.
51    ///
52    /// Emitted when the user runs `atuin history prune` or similar.
53    HistoryPruned,
54
55    /// History was rebuilt - search index needs a full rebuild.
56    ///
57    /// Emitted when the user runs `atuin store rebuild history` or similar.
58    HistoryRebuilt,
59
60    /// Specific history items were deleted.
61    ///
62    /// The search component should remove these from its index.
63    HistoryDeleted {
64        /// IDs of the deleted history entries.
65        ids: Vec<HistoryId>,
66    },
67
68    /// Settings have changed, components should reload if needed.
69    SettingsReloaded,
70
71    // ---- Lifecycle ----
72    /// Request graceful shutdown of the daemon.
73    ShutdownRequested,
74}