use super::ErrorCategory;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum SafeguardKind {
PlanningWorkflow,
CommandSecurity,
ToolPolicy,
PermissionReview,
SafetyValidation,
}
impl SafeguardKind {
#[must_use]
pub const fn category(self) -> ErrorCategory {
match self {
Self::PlanningWorkflow => ErrorCategory::PlanningPolicyViolation,
Self::CommandSecurity | Self::ToolPolicy | Self::PermissionReview | Self::SafetyValidation => {
ErrorCategory::PolicyViolation
}
}
}
}
#[derive(Debug, Clone, thiserror::Error)]
#[error("{message}")]
pub struct SafeguardDenial {
kind: SafeguardKind,
message: String,
}
impl SafeguardDenial {
#[must_use]
pub fn new(kind: SafeguardKind, message: impl Into<String>) -> Self {
Self { kind, message: message.into() }
}
#[must_use]
pub const fn kind(&self) -> SafeguardKind {
self.kind
}
}
impl SafeguardDenial {
#[must_use]
pub fn planning_workflow(message: impl Into<String>) -> anyhow::Error {
anyhow::Error::new(Self::new(SafeguardKind::PlanningWorkflow, message))
}
#[must_use]
pub fn safety_validation(message: impl Into<String>) -> anyhow::Error {
anyhow::Error::new(Self::new(SafeguardKind::SafetyValidation, message))
}
}