mirror of
https://github.com/openai/codex.git
synced 2026-05-01 11:52:10 +03:00
first pass at prefix rules
This commit is contained in:
33
codex-rs/execpolicy2/src/decision.rs
Normal file
33
codex-rs/execpolicy2/src/decision.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::error::Error;
|
||||
use crate::error::Result;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum Decision {
|
||||
Allow,
|
||||
Prompt,
|
||||
Forbidden,
|
||||
}
|
||||
|
||||
impl Decision {
|
||||
pub fn parse(raw: &str) -> Result<Self> {
|
||||
match raw {
|
||||
"allow" => Ok(Self::Allow),
|
||||
"prompt" => Ok(Self::Prompt),
|
||||
"forbidden" => Ok(Self::Forbidden),
|
||||
other => Err(Error::InvalidDecision(other.to_string())),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns true if `self` is stricter (less permissive) than `other`.
|
||||
pub fn is_stricter_than(self, other: Self) -> bool {
|
||||
matches!(
|
||||
(self, other),
|
||||
(Decision::Forbidden, Decision::Prompt | Decision::Allow)
|
||||
| (Decision::Prompt, Decision::Allow)
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user