mirror of
https://github.com/openai/codex.git
synced 2026-11-16 06:54:36 +00:00
Represent terminal input in approval reviews (#40528)
## What changed - Add a `writeStdin` Guardian action carrying the approval, process, input, and working-directory details. - Distinguish `command` and `writeStdin` execution approval requests while defaulting missing kinds to `command` for compatibility with older events. - Render terminal-input review progress, denials, timeouts, and retry actions in the TUI, and record the action separately in analytics. - Keep terminal-input reviews as child approvals so they do not change the parent command item's lifecycle or reconstructed history. ## Testing - Cover Guardian serialization, app-server protocol conversion, command history reconstruction, analytics classification, and TUI review flows for terminal input. GitOrigin-RevId: b083d5e2963bdd23b928644ec03c7eb68ebf2950
This commit is contained in:
1 parent
a7b86b6201
commit
9c9675d3d0
51 files changed
+833
-26
No files matched your search
@@ -7,6 +7,7 @@ use codex_protocol::approvals::NetworkApprovalProtocol;
|
||||
use codex_protocol::models::AdditionalPermissionProfile;
|
||||
use codex_protocol::request_permissions::RequestPermissionProfile;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use codex_utils_path_uri::LegacyAppPathString;
|
||||
use codex_utils_path_uri::PathUri;
|
||||
use serde::Serialize;
|
||||
use serde_json::Value;
|
||||
@@ -25,6 +26,21 @@ pub(crate) enum GuardianApprovalRequest {
|
||||
justification: Option<String>,
|
||||
tty: bool,
|
||||
},
|
||||
#[cfg_attr(
|
||||
not(test),
|
||||
expect(
|
||||
dead_code,
|
||||
reason = "Constructed by the follow-up stdin approval routing change"
|
||||
)
|
||||
)]
|
||||
WriteStdin {
|
||||
id: String,
|
||||
approval_id: String,
|
||||
process_id: i32,
|
||||
input: String,
|
||||
cwd: PathUri,
|
||||
tty: bool,
|
||||
},
|
||||
#[cfg(unix)]
|
||||
Execve {
|
||||
id: String,
|
||||
@@ -110,6 +126,16 @@ struct CommandApprovalAction<'a> {
|
||||
tty: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct WriteStdinApprovalAction<'a> {
|
||||
tool: &'static str,
|
||||
session_id: i32,
|
||||
chars: &'a str,
|
||||
cwd: LegacyAppPathString,
|
||||
sandbox_permissions: crate::sandboxing::SandboxPermissions,
|
||||
tty: bool,
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[derive(Serialize)]
|
||||
struct ExecveApprovalAction<'a> {
|
||||
@@ -273,6 +299,20 @@ pub(crate) fn guardian_approval_request_to_json(
|
||||
justification.as_ref(),
|
||||
Some(*tty),
|
||||
),
|
||||
GuardianApprovalRequest::WriteStdin {
|
||||
process_id,
|
||||
input,
|
||||
cwd,
|
||||
tty,
|
||||
..
|
||||
} => serialize_guardian_action(WriteStdinApprovalAction {
|
||||
tool: "write_stdin",
|
||||
session_id: *process_id,
|
||||
chars: input,
|
||||
cwd: cwd.clone().into(),
|
||||
sandbox_permissions: crate::sandboxing::SandboxPermissions::RequireEscalated,
|
||||
tty: *tty,
|
||||
}),
|
||||
#[cfg(unix)]
|
||||
GuardianApprovalRequest::Execve {
|
||||
id: _,
|
||||
@@ -367,6 +407,18 @@ pub(crate) fn guardian_assessment_action(
|
||||
GuardianApprovalRequest::ExecCommand { command, cwd, .. } => {
|
||||
command_assessment_action(GuardianCommandSource::UnifiedExec, command, cwd)
|
||||
}
|
||||
GuardianApprovalRequest::WriteStdin {
|
||||
approval_id,
|
||||
process_id,
|
||||
input,
|
||||
cwd,
|
||||
..
|
||||
} => GuardianAssessmentAction::WriteStdin {
|
||||
approval_id: approval_id.clone(),
|
||||
process_id: process_id.to_string(),
|
||||
stdin: input.clone(),
|
||||
cwd: cwd.clone(),
|
||||
},
|
||||
#[cfg(unix)]
|
||||
GuardianApprovalRequest::Execve {
|
||||
source,
|
||||
@@ -439,6 +491,9 @@ pub(crate) fn guardian_reviewed_action(
|
||||
additional_permissions: additional_permissions.clone(),
|
||||
tty: *tty,
|
||||
},
|
||||
GuardianApprovalRequest::WriteStdin { tty, .. } => {
|
||||
GuardianReviewedAction::WriteStdin { tty: *tty }
|
||||
}
|
||||
#[cfg(unix)]
|
||||
GuardianApprovalRequest::Execve {
|
||||
source,
|
||||
@@ -480,6 +535,7 @@ pub(crate) fn guardian_reviewed_action(
|
||||
pub(crate) fn guardian_request_target_item_id(request: &GuardianApprovalRequest) -> Option<&str> {
|
||||
match request {
|
||||
GuardianApprovalRequest::ExecCommand { id, .. }
|
||||
| GuardianApprovalRequest::WriteStdin { id, .. }
|
||||
| GuardianApprovalRequest::ApplyPatch { id, .. }
|
||||
| GuardianApprovalRequest::McpToolCall { id, .. }
|
||||
| GuardianApprovalRequest::RequestPermissions { id, .. } => Some(id),
|
||||
@@ -497,6 +553,7 @@ pub(crate) fn guardian_request_turn_id<'a>(
|
||||
GuardianApprovalRequest::NetworkAccess { turn_id, .. }
|
||||
| GuardianApprovalRequest::RequestPermissions { turn_id, .. } => turn_id,
|
||||
GuardianApprovalRequest::ExecCommand { .. }
|
||||
| GuardianApprovalRequest::WriteStdin { .. }
|
||||
| GuardianApprovalRequest::ApplyPatch { .. }
|
||||
| GuardianApprovalRequest::McpToolCall { .. } => default_turn_id,
|
||||
#[cfg(unix)]
|
||||
|
||||
@@ -178,6 +178,7 @@ fn reviewed_action_tag(action: &GuardianReviewedAction) -> &'static str {
|
||||
match action {
|
||||
GuardianReviewedAction::Shell { .. } => "shell",
|
||||
GuardianReviewedAction::UnifiedExec { .. } => "unified_exec",
|
||||
GuardianReviewedAction::WriteStdin { .. } => "write_stdin",
|
||||
GuardianReviewedAction::Execve { .. } => "execve",
|
||||
GuardianReviewedAction::ApplyPatch {} => "apply_patch",
|
||||
GuardianReviewedAction::NetworkAccess { .. } => "network_access",
|
||||
|
||||
@@ -37,6 +37,7 @@ use codex_model_provider_info::OPENAI_PROVIDER_ID;
|
||||
use codex_models_manager::manager::StaticModelsManager;
|
||||
use codex_network_proxy::NetworkProxyConfig;
|
||||
use codex_protocol::ThreadId;
|
||||
use codex_protocol::approvals::GuardianAssessmentAction;
|
||||
use codex_protocol::approvals::NetworkApprovalProtocol;
|
||||
use codex_protocol::config_types::ApprovalsReviewer;
|
||||
use codex_protocol::models::ContentItem;
|
||||
@@ -1364,6 +1365,49 @@ async fn build_guardian_prompt_items_explains_network_access_review_scope() -> a
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn guardian_write_stdin_preserves_input_and_foreign_cwd() -> serde_json::Result<()> {
|
||||
let cwd = PathUri::parse("file:///C:/workspace").expect("valid executor cwd");
|
||||
let input = "confirm\n";
|
||||
let action = GuardianApprovalRequest::WriteStdin {
|
||||
id: "terminal-open".to_string(),
|
||||
approval_id: "terminal-write".to_string(),
|
||||
process_id: 1000,
|
||||
input: input.to_string(),
|
||||
cwd: cwd.clone(),
|
||||
tty: true,
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
guardian_approval_request_to_json(&action)?,
|
||||
serde_json::json!({
|
||||
"tool": "write_stdin",
|
||||
"session_id": 1000,
|
||||
"chars": input,
|
||||
"cwd": r"C:\workspace",
|
||||
"sandbox_permissions": "require_escalated",
|
||||
"tty": true,
|
||||
}),
|
||||
);
|
||||
assert_eq!(
|
||||
guardian_assessment_action(&action),
|
||||
GuardianAssessmentAction::WriteStdin {
|
||||
approval_id: "terminal-write".to_string(),
|
||||
process_id: "1000".to_string(),
|
||||
stdin: input.to_string(),
|
||||
cwd,
|
||||
},
|
||||
);
|
||||
assert_eq!(
|
||||
(
|
||||
guardian_request_target_item_id(&action),
|
||||
guardian_request_turn_id(&action, "current-turn"),
|
||||
),
|
||||
(Some("terminal-open"), "current-turn"),
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn guardian_assessment_action_redacts_apply_patch_patch_text() {
|
||||
let cwd = test_path_buf("/tmp").abs();
|
||||
|
||||
Reference in new issue
Block a user