use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum PropertyClass {
ComplianceCoverage,
EffectRowSoundness,
CapabilityIsolation,
ResourceBounds,
ShieldHaltGuarantee,
CapabilityContainment,
ToolCallSoundness,
}
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",
}
}
}
#[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)]
#[serde(tag = "kind")]
pub enum Witness {
ComplianceCoverage(ComplianceCoverageWitness),
EffectRowSoundness(EffectRowSoundnessWitness),
CapabilityIsolation(CapabilityIsolationWitness),
ResourceBounds(ResourceBoundsWitness),
ShieldHaltGuarantee(ShieldHaltGuaranteeWitness),
CapabilityContainment(CapabilityContainmentWitness),
ToolCallSoundness(ToolCallSoundnessWitness),
}
impl Witness {
pub fn subject_name(&self) -> &str {
match self {
Witness::ComplianceCoverage(w) => &w.endpoint_name,
Witness::EffectRowSoundness(w) => &w.tool_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,
}
}
}
#[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>,
}