mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Centralize Guardian policy resolution in config and protocol (#45957)
## What changed - Extend `GuardianModelPolicy` with controls for uncategorized tools, unscored actions, the initial computer-use call allowance, and sandboxed command coverage. - Add `GuardianPolicyLoader` in `codex-config` to translate legacy settings, preserve catalog policy precedence, and enforce reviewer requirements. Apply live model review requirements through `ConfigRequirements::constrain_guardian_policy`. - Use the shared model policy for Guardian scoring and approval, replacing the extension-local policy wrapper while retaining legacy defaults. ## Testing Add configuration tests for catalog precedence, legacy scope fallback, required-model constraints, and legacy computer-use opt-in and feature gating. Adapt existing extension tests to consume the shared policy. GitOrigin-RevId: 6fed1c3a831964ad28ea7de5cb19e74e323c1204
This commit is contained in:
1 parent
6500c1f844
commit
7275afc5c7
14 files changed
+388
-241
No files matched your search
@@ -39,6 +39,7 @@ mod guardian;
|
||||
pub use guardian::GuardianModelPolicy;
|
||||
pub use guardian::GuardianReviewMode;
|
||||
pub use guardian::GuardianScope;
|
||||
pub use guardian::GuardianUnscoredAction;
|
||||
|
||||
#[path = "openai_models/guardian_v2.rs"]
|
||||
mod guardian_v2;
|
||||
|
||||
@@ -12,9 +12,10 @@ use crate::mcp::is_node_repl_backed_server;
|
||||
use crate::mcp::is_node_repl_backed_tool;
|
||||
|
||||
/// How Guardian handles an action when the user selects automatic approval.
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, TS, JsonSchema)]
|
||||
#[derive(Debug, Default, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, TS, JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum GuardianReviewMode {
|
||||
#[default]
|
||||
Disabled,
|
||||
Synchronous,
|
||||
/// Use a current low-risk score; otherwise run synchronous review.
|
||||
@@ -23,6 +24,17 @@ pub enum GuardianReviewMode {
|
||||
Unknown,
|
||||
}
|
||||
|
||||
/// How actions outside adaptive coverage affect cached classification evidence.
|
||||
#[derive(Debug, Default, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, TS, JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum GuardianUnscoredAction {
|
||||
Ignore,
|
||||
AgeScore,
|
||||
#[default]
|
||||
#[serde(other)]
|
||||
InvalidateScore,
|
||||
}
|
||||
|
||||
/// A complete model policy. Omitted scopes are disabled; unknown fields are ignored.
|
||||
/// Code Mode wrappers have no approval scope; their nested tools follow this policy.
|
||||
#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq, Eq, TS, JsonSchema)]
|
||||
@@ -39,6 +51,17 @@ pub struct GuardianModelPolicy {
|
||||
pub network: Option<GuardianReviewMode>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub permissions: Option<GuardianReviewMode>,
|
||||
/// Coverage for tools without an approval category.
|
||||
#[serde(default)]
|
||||
pub other_tools: GuardianReviewMode,
|
||||
#[serde(default)]
|
||||
pub unscored_action: GuardianUnscoredAction,
|
||||
/// Omission retains the existing allowance for adaptive computer use.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub initial_cua_call: Option<bool>,
|
||||
/// Whether adaptive shell coverage includes ordinary sandboxed commands.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub sandboxed_exec_commands: Option<bool>,
|
||||
}
|
||||
|
||||
impl GuardianModelPolicy {
|
||||
@@ -53,6 +76,39 @@ impl GuardianModelPolicy {
|
||||
}
|
||||
.unwrap_or(GuardianReviewMode::Disabled)
|
||||
}
|
||||
|
||||
pub fn scoring_enabled(&self) -> bool {
|
||||
[
|
||||
self.computer_use,
|
||||
self.shell,
|
||||
self.file_changes,
|
||||
self.mcp,
|
||||
self.network,
|
||||
self.permissions,
|
||||
]
|
||||
.contains(&Some(GuardianReviewMode::Adaptive))
|
||||
}
|
||||
|
||||
pub fn disable_scoring(&mut self) {
|
||||
for mode in [
|
||||
&mut self.computer_use,
|
||||
&mut self.shell,
|
||||
&mut self.file_changes,
|
||||
&mut self.mcp,
|
||||
&mut self.network,
|
||||
&mut self.permissions,
|
||||
] {
|
||||
if *mode == Some(GuardianReviewMode::Adaptive) {
|
||||
*mode = Some(GuardianReviewMode::Synchronous);
|
||||
}
|
||||
}
|
||||
self.other_tools = GuardianReviewMode::Synchronous;
|
||||
}
|
||||
|
||||
pub fn allows_initial_cua_call(&self) -> bool {
|
||||
self.initial_cua_call
|
||||
.unwrap_or(self.computer_use == Some(GuardianReviewMode::Adaptive))
|
||||
}
|
||||
}
|
||||
|
||||
/// Approval categories understood by this client. Future catalog keys are ignored.
|
||||
|
||||
Reference in new issue
Block a user