mirror of
https://github.com/openai/codex.git
synced 2026-11-16 06:54:36 +00:00
Route approvals through the extension decision API (#43432)
## What changed - Let approval extensions choose between cached approval, synchronous review, and a user prompt for tool and permission requests, while core enforces mandatory Guardian and fresh-review requirements. - Carry an optional `review_reason` on Guardian assessment events and use it to trigger strict-review notifications, retaining the fallback for older events. - Require synchronous review when cached evidence has an unusable encrypted parent compaction. ## Testing Add regression coverage for manual prompts and cached approvals with non-UTF-8 working directories. Update approval contributors in existing tests to use the decision API. GitOrigin-RevId: a4e66416070bdaa881daa41429c49021629f44c1
This commit is contained in:
1 parent
0df39752cb
commit
e1eb98461c
24 files changed
+605
-250
No files matched your search
@@ -1,4 +1,4 @@
|
||||
//! Binds the existing synchronous reviewer to one captured approval action.
|
||||
//! Binds the existing synchronous reviewer to one approval action.
|
||||
|
||||
use codex_extension_api::ExtensionFuture;
|
||||
use codex_extension_api::SynchronousApprovalReviewer;
|
||||
@@ -9,15 +9,77 @@ use super::ApprovalRequestReasons;
|
||||
use super::GuardianApprovalRequest;
|
||||
use super::GuardianReviewContext;
|
||||
use super::GuardianReviewOptions;
|
||||
use super::approval_request::guardian_approval_request_to_json;
|
||||
use super::review::run_synchronous_review;
|
||||
use crate::session::session::Session;
|
||||
|
||||
/// Carries the original action even when the legacy synchronous renderer cannot handle its paths.
|
||||
/// This lets the extension return AskUser before invoking that renderer.
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct ReviewAction {
|
||||
pub(super) action: Result<serde_json::Value, String>,
|
||||
pub(super) category: codex_protocol::openai_models::GuardianScope,
|
||||
pub(super) request: Result<GuardianApprovalRequest, String>,
|
||||
}
|
||||
|
||||
impl From<GuardianApprovalRequest> for ReviewAction {
|
||||
fn from(request: GuardianApprovalRequest) -> Self {
|
||||
Self {
|
||||
action: guardian_approval_request_to_json(&request).map_err(|error| error.to_string()),
|
||||
category: request.guardian_scope(),
|
||||
request: Ok(request),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ReviewAction {
|
||||
pub(crate) fn from_approval_action(
|
||||
action: crate::tools::sandboxing::ApprovalAction,
|
||||
exec_command_cwd_convention: Option<codex_utils_path_uri::PathConvention>,
|
||||
) -> Self {
|
||||
let category = action.guardian_scope();
|
||||
let original = serde_json::to_value(&action).map_err(|error| error.to_string());
|
||||
match action.into_guardian_request(exec_command_cwd_convention) {
|
||||
Ok(request) => Self::from(request),
|
||||
Err(error) => Self {
|
||||
action: original,
|
||||
category,
|
||||
request: Err(error.to_string()),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ReviewAction {
|
||||
/// Preserve the checks previously made before entering Guardian from tool approvals.
|
||||
pub(super) fn validate(
|
||||
&self,
|
||||
context: &GuardianReviewContext,
|
||||
) -> Result<&GuardianApprovalRequest, ReviewDecision> {
|
||||
let request = self.request.as_ref().map_err(|error| {
|
||||
tracing::error!(%error, "failed to build automatic approval action");
|
||||
ReviewDecision::denied("automatic approval review could not prepare the action")
|
||||
})?;
|
||||
if let GuardianApprovalRequest::WriteStdin { environment_id, .. } = request
|
||||
&& !context
|
||||
.environments()
|
||||
.turn_environments()
|
||||
.any(|environment| environment.selection.environment_id == *environment_id)
|
||||
{
|
||||
return Err(ReviewDecision::denied(
|
||||
"automatic approval review cannot access the terminal's environment; select it before retrying",
|
||||
));
|
||||
}
|
||||
Ok(request)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(super) struct ReviewRuntime {
|
||||
pub(super) session: Arc<Session>,
|
||||
pub(super) context: GuardianReviewContext,
|
||||
pub(super) review_id: String,
|
||||
pub(super) request: GuardianApprovalRequest,
|
||||
pub(super) request: ReviewAction,
|
||||
pub(super) reasons: ApprovalRequestReasons,
|
||||
pub(super) options: GuardianReviewOptions,
|
||||
}
|
||||
@@ -27,6 +89,6 @@ impl SynchronousApprovalReviewer for ReviewRuntime {
|
||||
&self,
|
||||
reason: codex_protocol::approvals::GuardianReviewReason,
|
||||
) -> ExtensionFuture<'_, ReviewDecision> {
|
||||
Box::pin(run_synchronous_review(self.clone(), reason))
|
||||
Box::pin(run_synchronous_review(self.clone(), Some(reason)))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user