use super::{RiskTier, tier_may_be_waived};
use crate::agent::OverrideRecord;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct AskOrigin {
pub explicit: bool,
pub default: bool,
pub clamp: bool,
pub intent_raised: bool,
pub hook_raised: bool,
}
pub const STARTUP_WAIVER_REASON_PREFIX: &str = "startup-override:";
#[derive(Clone, Debug)]
pub struct StartupWaiver {
nonce: String,
}
impl StartupWaiver {
pub fn from_record(record: &OverrideRecord) -> Option<Self> {
record.flags.no_hitl.then(|| Self {
nonce: record.nonce.clone(),
})
}
pub fn nonce(&self) -> &str {
&self.nonce
}
pub fn reason(&self) -> String {
format!("{STARTUP_WAIVER_REASON_PREFIX}{}", self.nonce)
}
pub fn may_waive(&self, origin: AskOrigin, tier: Option<RiskTier>) -> bool {
if origin.intent_raised || origin.hook_raised || origin.explicit {
return false;
}
if !(origin.default || origin.clamp) {
return false;
}
tier_may_be_waived(tier)
}
}
#[cfg(test)]
#[path = "startup_waiver_tests.rs"]
mod tests;