Skip to main content

vibe/conditioning/
project.rs

1//! Profile DTO → Conditioning semantic statements.
2
3use super::profile::{ConditioningProfileDto, RequirementClassDto, COND_NS};
4
5#[derive(Debug, Clone, PartialEq, Eq)]
6pub struct CondStatement {
7    pub subject: String,
8    pub predicate: String,
9    pub object: String,
10}
11
12fn term(local: &str) -> String {
13    format!("{COND_NS}{local}")
14}
15
16/// Projects a conditioning profile.
17pub fn project_profile(profile: &ConditioningProfileDto) -> Result<Vec<CondStatement>, String> {
18    profile.validate()?;
19    let subj = profile.profile_id.clone();
20    let mut out = Vec::new();
21    out.push(CondStatement {
22        subject: subj.clone(),
23        predicate: term("type"),
24        object: term("ConditioningProfile"),
25    });
26    out.push(CondStatement {
27        subject: subj.clone(),
28        predicate: term("schemaVersion"),
29        object: profile.schema_version.to_string(),
30    });
31    out.push(CondStatement {
32        subject: subj.clone(),
33        predicate: term("profileId"),
34        object: profile.profile_id.clone(),
35    });
36    out.push(CondStatement {
37        subject: subj.clone(),
38        predicate: term("contentDigest"),
39        object: format!("{:016x}", profile.content_digest()),
40    });
41    out.push(CondStatement {
42        subject: subj.clone(),
43        predicate: term("hasObjective"),
44        object: profile.objective.clone(),
45    });
46    for d in &profile.domains {
47        out.push(CondStatement {
48            subject: subj.clone(),
49            predicate: term("hasDomainScope"),
50            object: d.clone(),
51        });
52    }
53    for r in &profile.requirements {
54        let rid = format!("{}#req-{}", subj, r.id);
55        out.push(CondStatement {
56            subject: subj.clone(),
57            predicate: term("hasRequirement"),
58            object: rid.clone(),
59        });
60        let class = match r.class {
61            RequirementClassDto::Enforced => "EnforcedRequirement",
62            RequirementClassDto::EvidenceObligation => "EvidenceObligation",
63            RequirementClassDto::Guidance => "Guidance",
64        };
65        out.push(CondStatement {
66            subject: rid.clone(),
67            predicate: term("type"),
68            object: term(class),
69        });
70        out.push(CondStatement {
71            subject: rid.clone(),
72            predicate: term("priority"),
73            object: r.priority.to_string(),
74        });
75        out.push(CondStatement {
76            subject: rid.clone(),
77            predicate: term("isRequired"),
78            object: if r.required { "true" } else { "false" }.into(),
79        });
80        if let Some(v) = &r.validator {
81            out.push(CondStatement {
82                subject: rid,
83                predicate: term("validatorRef"),
84                object: v.clone(),
85            });
86        }
87    }
88    out.push(CondStatement {
89        subject: subj,
90        predicate: term("hasBudget"),
91        object: format!(
92            "in:{} out:{} tools:{}",
93            profile.budget.input_tokens, profile.budget.output_tokens, profile.budget.tool_rounds
94        ),
95    });
96    Ok(out)
97}