aboutsummaryrefslogtreecommitdiffstats
path: root/crates/turtle/src/atuin_daemon/events.rs
blob: 9a398925e26c93643a553822b897816497995824 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//! Daemon events.
//!
//! Events are the primary communication mechanism within the daemon.
//! Components emit events to notify others of state changes, and handle
//! events to react to changes elsewhere in the system.
//!
//! External processes (like CLI commands) can also inject events via the
//! Control gRPC service.

use crate::atuin_client::history::{History, HistoryId};
use crate::atuin_common::record::RecordId;

/// Events that flow through the daemon's event bus.
///
/// Events are broadcast to all components. Each component decides which
/// events it cares about in its `handle_event` implementation.
#[derive(Debug, Clone)]
pub enum DaemonEvent {
    // ---- History lifecycle ----
    /// A command has started running.
    HistoryStarted(History),

    /// A command has finished running.
    HistoryEnded(History),

    // ---- Sync ----
    /// Records were synced from the server.
    ///
    /// The search component uses this to update its index with new history.
    RecordsAdded(Vec<RecordId>),

    /// Sync completed successfully.
    SyncCompleted {
        /// Number of records uploaded.
        uploaded: usize,
        /// Number of records downloaded.
        downloaded: usize,
    },

    /// Sync failed.
    SyncFailed {
        /// Error message describing what went wrong.
        error: String,
    },

    /// Request an immediate sync (external trigger).
    ForceSync,

    // ---- External commands ----
    /// History was pruned - search index needs a full rebuild.
    ///
    /// Emitted when the user runs `atuin history prune` or similar.
    HistoryPruned,

    /// History was rebuilt - search index needs a full rebuild.
    ///
    /// Emitted when the user runs `atuin store rebuild history` or similar.
    HistoryRebuilt,

    /// Specific history items were deleted.
    ///
    /// The search component should remove these from its index.
    HistoryDeleted {
        /// IDs of the deleted history entries.
        ids: Vec<HistoryId>,
    },

    /// Settings have changed, components should reload if needed.
    SettingsReloaded,

    // ---- Lifecycle ----
    /// Request graceful shutdown of the daemon.
    ShutdownRequested,
}