Skip to main content

rustyclaw_core/threads/
events.rs

1//! Thread events — emitted when thread state changes.
2
3use super::{ThreadId, ThreadInfo, ThreadStatus};
4use serde::{Deserialize, Serialize};
5
6/// Events emitted by the ThreadManager.
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub enum ThreadEvent {
9    /// A new thread was created
10    Created {
11        thread: ThreadInfo,
12        parent_id: Option<ThreadId>,
13    },
14    
15    /// Thread status changed
16    StatusChanged {
17        thread_id: ThreadId,
18        old_status: ThreadStatus,
19        new_status: ThreadStatus,
20    },
21    
22    /// Thread description updated
23    DescriptionChanged {
24        thread_id: ThreadId,
25        description: String,
26    },
27    
28    /// Thread became foreground
29    Foregrounded {
30        thread_id: ThreadId,
31        previous_foreground: Option<ThreadId>,
32    },
33    
34    /// Thread completed (with optional result)
35    Completed {
36        thread_id: ThreadId,
37        summary: Option<String>,
38        result: Option<String>,
39    },
40    
41    /// Thread failed
42    Failed {
43        thread_id: ThreadId,
44        error: String,
45    },
46    
47    /// Thread was removed/cleaned up
48    Removed {
49        thread_id: ThreadId,
50    },
51    
52    /// Message added to thread
53    MessageAdded {
54        thread_id: ThreadId,
55        message_count: usize,
56    },
57}
58
59impl ThreadEvent {
60    /// Get the thread ID this event relates to.
61    pub fn thread_id(&self) -> ThreadId {
62        match self {
63            Self::Created { thread, .. } => thread.id,
64            Self::StatusChanged { thread_id, .. } => *thread_id,
65            Self::DescriptionChanged { thread_id, .. } => *thread_id,
66            Self::Foregrounded { thread_id, .. } => *thread_id,
67            Self::Completed { thread_id, .. } => *thread_id,
68            Self::Failed { thread_id, .. } => *thread_id,
69            Self::Removed { thread_id } => *thread_id,
70            Self::MessageAdded { thread_id, .. } => *thread_id,
71        }
72    }
73    
74    /// Is this an event that should trigger a sidebar update?
75    pub fn triggers_sidebar_update(&self) -> bool {
76        // All events except MessageAdded trigger sidebar updates
77        !matches!(self, Self::MessageAdded { .. })
78    }
79}