Consolidate apply_patch runtime execution (#36745)

## What changed

- Route verified patches from both direct tool calls and intercepted shell commands through a shared execution helper.
- Simplify patch safety preparation to return either a runtime invocation or a rejection directly.
- Keep permission resolution, approval handling, event emission, runtime execution, and diff tracking in the common path.

GitOrigin-RevId: e16aae8e91d96b8108aefac7f3fbf2da2cbac016
This commit is contained in:
jif authored and copyberry committed 2026-08-03 12:03:33 +00:00
1 parent 62839fec5d
commit 7750465934
4 files changed
+107 -197

No files matched your search

+4 -16
View File
@@ -8,7 +8,6 @@ use codex_protocol::config_types::WindowsSandboxLevel;
use codex_protocol::models::PermissionProfile;
use codex_protocol::permissions::FileSystemSandboxPolicy;
use codex_protocol::protocol::AskForApproval;
use codex_sandboxing::SandboxType;
use codex_sandboxing::get_platform_sandbox;
use codex_utils_path_uri::PathUri;
@@ -19,14 +18,9 @@ const PATCH_REJECTED_READ_ONLY_REASON: &str =
#[derive(Debug, PartialEq)]
pub enum SafetyCheck {
AutoApprove {
sandbox_type: SandboxType,
user_explicitly_approved: bool,
},
AutoApprove,
AskUser,
Reject {
reason: String,
},
Reject { reason: String },
}
pub fn assess_patch_safety(
@@ -70,19 +64,13 @@ pub fn assess_patch_safety(
) {
// Disabled and External profiles intentionally do not apply an
// outer Codex filesystem sandbox.
SafetyCheck::AutoApprove {
sandbox_type: SandboxType::None,
user_explicitly_approved: false,
}
SafetyCheck::AutoApprove
} else {
// Only auto‑approve when we can actually enforce a sandbox. Otherwise
// fall back to asking the user because the patch may touch arbitrary
// paths outside the project.
match get_platform_sandbox(windows_sandbox_level != WindowsSandboxLevel::Disabled) {
Some(sandbox_type) => SafetyCheck::AutoApprove {
sandbox_type,
user_explicitly_approved: false,
},
Some(_) => SafetyCheck::AutoApprove,
None => {
if rejects_sandbox_approval {
SafetyCheck::Reject {