vibe/conditioning/
profile.rs1pub const SCHEMA_VERSION: u16 = 1;
4pub const COND_NS: &str = "https://qualiadb.org/schema/conditioning#";
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub enum RequirementClassDto {
8 Enforced,
9 EvidenceObligation,
10 Guidance,
11}
12
13#[derive(Debug, Clone, PartialEq, Eq)]
14pub struct RequirementDto {
15 pub id: String,
16 pub class: RequirementClassDto,
17 pub rule: String,
18 pub validator: Option<String>,
19 pub required: bool,
20 pub priority: u8,
21}
22
23#[derive(Debug, Clone, PartialEq, Eq)]
24pub struct ConditioningBudgetDto {
25 pub input_tokens: u32,
26 pub output_tokens: u32,
27 pub tool_rounds: u16,
28}
29
30#[derive(Debug, Clone, PartialEq, Eq)]
31pub struct ConditioningProfileDto {
32 pub schema_version: u16,
33 pub profile_id: String,
34 pub objective: String,
35 pub domains: Vec<String>,
36 pub requirements: Vec<RequirementDto>,
37 pub budget: ConditioningBudgetDto,
38}
39
40impl ConditioningProfileDto {
41 pub fn validate(&self) -> Result<(), String> {
43 if self.schema_version != SCHEMA_VERSION {
44 return Err(format!(
45 "unsupported schema_version {}",
46 self.schema_version
47 ));
48 }
49 if self.profile_id.trim().is_empty() {
50 return Err("profile_id must be non-empty".into());
51 }
52 if self.objective.trim().is_empty() {
53 return Err("objective must be non-empty".into());
54 }
55 if self.requirements.len() > 64 {
56 return Err("requirements exceed bound 64".into());
57 }
58 if self.domains.len() > 32 {
59 return Err("domains exceed bound 32".into());
60 }
61 let mut seen = Vec::new();
62 for r in &self.requirements {
63 if r.id.trim().is_empty() {
64 return Err("requirement id empty".into());
65 }
66 if seen.contains(&r.id) {
67 return Err(format!("duplicate requirement id {}", r.id));
68 }
69 seen.push(r.id.clone());
70 if matches!(r.class, RequirementClassDto::Enforced) && r.validator.is_none() {
71 return Err(format!("enforced requirement {} needs validator", r.id));
72 }
73 }
74 Ok(())
75 }
76
77 pub fn content_digest(&self) -> u64 {
79 let mut h: u64 = 0xcbf29ce484222325;
80 for b in self.profile_id.as_bytes() {
81 h ^= *b as u64;
82 h = h.wrapping_mul(0x100000001b3);
83 }
84 for b in self.objective.as_bytes() {
85 h ^= *b as u64;
86 h = h.wrapping_mul(0x100000001b3);
87 }
88 for r in &self.requirements {
89 for b in r.id.as_bytes() {
90 h ^= *b as u64;
91 h = h.wrapping_mul(0x100000001b3);
92 }
93 h ^= r.priority as u64;
94 h = h.wrapping_mul(0x100000001b3);
95 }
96 h
97 }
98}