use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum PropertyClass {
ComplianceCoverage,
EffectRowSoundness,
CapabilityIsolation,
ResourceBounds,
ShieldHaltGuarantee,
CapabilityContainment,
ToolCallSoundness,
EffectBudgeted,
JsonShapeSoundness,
ChannelDeliverySoundness,
}
pub const VALID_BUDGET_PERIODS: &[&str] = &["second", "minute", "hour", "day"];
pub const VALID_ON_EXHAUSTED: &[&str] = &["block", "defer", "shed"];
pub const VALID_BREACH_POLICIES: &[&str] =
&["deflect", "escalate", "halt", "quarantine", "sanitize_and_retry"];
pub const MAX_RETRIES: i64 = 100;
impl PropertyClass {
pub fn slug(&self) -> &'static str {
match self {
PropertyClass::ComplianceCoverage => "compliance_coverage",
PropertyClass::EffectRowSoundness => "effect_row_soundness",
PropertyClass::CapabilityIsolation => "capability_isolation",
PropertyClass::ResourceBounds => "resource_bounds",
PropertyClass::ShieldHaltGuarantee => "shield_halt_guarantee",
PropertyClass::CapabilityContainment => "capability_containment",
PropertyClass::ToolCallSoundness => "tool_call_soundness",
PropertyClass::EffectBudgeted => "effect_budgeted",
PropertyClass::JsonShapeSoundness => "json_shape_soundness",
PropertyClass::ChannelDeliverySoundness => "channel_delivery_soundness",
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ComplianceCoverageWitness {
pub endpoint_name: String,
pub required_classes: Vec<String>,
pub shield_ref: String,
pub shield_present: bool,
pub provided_classes: Vec<String>,
pub unknown_classes: Vec<String>,
pub uncovered_classes: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct EffectRowSoundnessWitness {
pub tool_name: String,
pub declared_effects: Vec<String>,
pub unknown_bases: Vec<String>,
pub missing_qualifier: Vec<String>,
pub invalid_stream_qualifier: Vec<String>,
pub purity_violation: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct CapabilityIsolationWitness {
pub store_name: String,
pub capability: String,
pub malformed: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "subject")]
pub enum ResourceBoundsWitness {
EndpointRetry {
endpoint_name: String,
retries: i64,
in_bounds: bool,
},
SocketCredit {
socket_name: String,
credit: i64,
positive: bool,
},
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ShieldHaltGuaranteeWitness {
pub shield_name: String,
pub on_breach: String,
pub known_policy: bool,
pub scan_count: usize,
pub vacuous_halt: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct CapabilityContainmentWitness {
pub endpoint_name: String,
pub execute_flow: String,
pub flow_resolved: bool,
pub declared_requires: Vec<String>,
pub reached_gates: Vec<String>,
pub uncovered_gates: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ToolCallSoundnessWitness {
pub flow_name: String,
pub call_index: usize,
pub tool_name: String,
pub arg_names: Vec<String>,
pub declared_params: Vec<String>,
pub schema_present: bool,
pub unknown_args: Vec<String>,
pub duplicate_args: Vec<String>,
pub missing_required: Vec<String>,
pub type_mismatches: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct EffectBudgetedWitness {
pub daemon_name: String,
pub quota_count: usize,
pub declared_tools: Vec<String>,
pub unresolved_effects: Vec<String>,
pub nonpositive_limits: Vec<String>,
pub invalid_periods: Vec<String>,
pub on_exhausted: String,
pub on_exhausted_valid: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct JsonShapeSoundnessWitness {
pub store_name: String,
pub declared_types: Vec<String>,
pub lens_columns: Vec<String>,
pub unresolved_shapes: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ChannelDeliverySoundnessWitness {
pub channel_name: String,
pub persistence: String,
pub qos: String,
pub has_producer: bool,
pub has_consumer: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "kind")]
pub enum Witness {
ComplianceCoverage(ComplianceCoverageWitness),
EffectRowSoundness(EffectRowSoundnessWitness),
EffectBudgeted(EffectBudgetedWitness),
CapabilityIsolation(CapabilityIsolationWitness),
ResourceBounds(ResourceBoundsWitness),
ShieldHaltGuarantee(ShieldHaltGuaranteeWitness),
CapabilityContainment(CapabilityContainmentWitness),
ToolCallSoundness(ToolCallSoundnessWitness),
JsonShapeSoundness(JsonShapeSoundnessWitness),
ChannelDeliverySoundness(ChannelDeliverySoundnessWitness),
}
impl Witness {
pub fn subject_name(&self) -> &str {
match self {
Witness::ComplianceCoverage(w) => &w.endpoint_name,
Witness::EffectRowSoundness(w) => &w.tool_name,
Witness::EffectBudgeted(w) => &w.daemon_name,
Witness::CapabilityIsolation(w) => &w.store_name,
Witness::ResourceBounds(ResourceBoundsWitness::EndpointRetry {
endpoint_name,
..
}) => endpoint_name,
Witness::ResourceBounds(ResourceBoundsWitness::SocketCredit {
socket_name,
..
}) => socket_name,
Witness::ShieldHaltGuarantee(w) => &w.shield_name,
Witness::CapabilityContainment(w) => &w.endpoint_name,
Witness::ToolCallSoundness(w) => &w.tool_name,
Witness::JsonShapeSoundness(w) => &w.store_name,
Witness::ChannelDeliverySoundness(w) => &w.channel_name,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ProofTerm {
pub property: PropertyClass,
pub artifact_digest: String,
pub witness: Witness,
pub axon_version: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ProofBundle {
pub axon_version: String,
pub artifact_digest: String,
pub proofs: Vec<ProofTerm>,
}