use uuid::Uuid;
#[derive(Debug, Clone)]
pub enum ClawEvent {
MemoryAdded {
agent_id: Uuid,
memory_id: Uuid,
memory_type: String,
},
MemoryArchived {
agent_id: Uuid,
memory_id: Uuid,
reason: String,
},
SearchExecuted {
agent_id: Uuid,
query_preview: String,
result_count: usize,
latency_ms: u64,
},
BranchCreated {
agent_id: Uuid,
branch_id: Uuid,
name: String,
},
BranchMerged {
agent_id: Uuid,
source: String,
target: String,
applied: u32,
},
SyncCompleted {
agent_id: Uuid,
pushed: u32,
pulled: u32,
},
ReflectionCompleted {
agent_id: Uuid,
job_id: String,
archived: u32,
promoted: u32,
},
SessionCreated {
agent_id: Uuid,
session_id: Uuid,
},
SessionExpired {
agent_id: Uuid,
session_id: Uuid,
},
GuardDenied {
agent_id: Uuid,
action: String,
resource: String,
reason: String,
},
ComponentHealthChanged {
component: String,
healthy: bool,
},
PluginLoaded {
name: String,
version: String,
},
PluginUnloaded {
name: String,
},
ShutdownInitiated {
reason: String,
},
}
impl ClawEvent {
pub fn event_type(&self) -> &'static str {
match self {
Self::MemoryAdded { .. } => "memory.added",
Self::MemoryArchived { .. } => "memory.archived",
Self::SearchExecuted { .. } => "search.executed",
Self::BranchCreated { .. } => "branch.created",
Self::BranchMerged { .. } => "branch.merged",
Self::SyncCompleted { .. } => "sync.completed",
Self::ReflectionCompleted { .. } => "reflect.completed",
Self::SessionCreated { .. } => "session.created",
Self::SessionExpired { .. } => "session.expired",
Self::GuardDenied { .. } => "guard.denied",
Self::ComponentHealthChanged { .. } => "component.health_changed",
Self::PluginLoaded { .. } => "plugin.loaded",
Self::PluginUnloaded { .. } => "plugin.unloaded",
Self::ShutdownInitiated { .. } => "shutdown.initiated",
}
}
pub fn agent_id(&self) -> Option<Uuid> {
match self {
Self::MemoryAdded { agent_id, .. }
| Self::MemoryArchived { agent_id, .. }
| Self::SearchExecuted { agent_id, .. }
| Self::BranchCreated { agent_id, .. }
| Self::BranchMerged { agent_id, .. }
| Self::SyncCompleted { agent_id, .. }
| Self::ReflectionCompleted { agent_id, .. }
| Self::SessionCreated { agent_id, .. }
| Self::SessionExpired { agent_id, .. }
| Self::GuardDenied { agent_id, .. } => Some(*agent_id),
_ => None,
}
}
pub fn is_security_event(&self) -> bool {
matches!(self, Self::GuardDenied { .. } | Self::SessionExpired { .. })
}
}