mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Extract TUI approval request payloads into structs (#33684)
## What changed Give command, permissions, patch, and MCP elicitation approvals dedicated request structs, and update TUI routing and rendering to use the wrapped payloads. GitOrigin-RevId: ffee4058dd27505be2a11de3758ac12bb707b6b8
This commit is contained in:
1 parent
693b8c2ba4
commit
d3fc1950a9
8 files changed
+231
-267
No files matched your search
@@ -2091,18 +2091,18 @@ impl App {
|
||||
self.chat_widget.handle_manage_skills_closed();
|
||||
}
|
||||
AppEvent::FullScreenApprovalRequest(request) => match request {
|
||||
ApprovalRequest::ApplyPatch { cwd, changes, .. } => {
|
||||
ApprovalRequest::ApplyPatch(request) => {
|
||||
let _ = tui.enter_alt_screen();
|
||||
let diff_summary = DiffSummary::new(changes, cwd);
|
||||
let diff_summary = DiffSummary::new(request.changes, request.cwd);
|
||||
self.overlay = Some(Overlay::new_static_with_renderables(
|
||||
vec![diff_summary.into()],
|
||||
"P A T C H".to_string(),
|
||||
self.keymap.pager.clone(),
|
||||
));
|
||||
}
|
||||
ApprovalRequest::Exec { command, .. } => {
|
||||
ApprovalRequest::Exec(request) => {
|
||||
let _ = tui.enter_alt_screen();
|
||||
let full_cmd = strip_bash_lc_and_escape(&command);
|
||||
let full_cmd = strip_bash_lc_and_escape(&request.command);
|
||||
let full_cmd_lines = highlight_bash_to_lines(&full_cmd);
|
||||
self.overlay = Some(Overlay::new_static_with_lines(
|
||||
full_cmd_lines,
|
||||
@@ -2110,27 +2110,22 @@ impl App {
|
||||
self.keymap.pager.clone(),
|
||||
));
|
||||
}
|
||||
ApprovalRequest::Permissions {
|
||||
environment_id,
|
||||
permissions,
|
||||
reason,
|
||||
..
|
||||
} => {
|
||||
ApprovalRequest::Permissions(request) => {
|
||||
let _ = tui.enter_alt_screen();
|
||||
let mut lines = Vec::new();
|
||||
if let Some(environment_id) = environment_id {
|
||||
if let Some(environment_id) = request.environment_id {
|
||||
lines.push(Line::from(vec![
|
||||
"Environment: ".into(),
|
||||
environment_id.bold(),
|
||||
]));
|
||||
lines.push(Line::from(""));
|
||||
}
|
||||
if let Some(reason) = reason {
|
||||
if let Some(reason) = request.reason {
|
||||
lines.push(Line::from(vec!["Reason: ".into(), reason.italic()]));
|
||||
lines.push(Line::from(""));
|
||||
}
|
||||
if let Some(rule_line) =
|
||||
crate::bottom_pane::format_requested_permissions_rule(&permissions)
|
||||
crate::bottom_pane::format_requested_permissions_rule(&request.permissions)
|
||||
{
|
||||
lines.push(Line::from(vec![
|
||||
"Permission rule: ".into(),
|
||||
@@ -2143,16 +2138,12 @@ impl App {
|
||||
self.keymap.pager.clone(),
|
||||
));
|
||||
}
|
||||
ApprovalRequest::McpElicitation {
|
||||
server_name,
|
||||
message,
|
||||
..
|
||||
} => {
|
||||
ApprovalRequest::McpElicitation(request) => {
|
||||
let _ = tui.enter_alt_screen();
|
||||
let paragraph = Paragraph::new(vec![
|
||||
Line::from(vec!["Server: ".into(), server_name.bold()]),
|
||||
Line::from(vec!["Server: ".into(), request.server_name.bold()]),
|
||||
Line::from(""),
|
||||
Line::from(message),
|
||||
Line::from(request.message),
|
||||
])
|
||||
.wrap(Wrap { trim: false });
|
||||
self.overlay = Some(Overlay::new_static_with_renderables(
|
||||
|
||||
@@ -2543,12 +2543,7 @@ async fn inactive_thread_exec_approval_preserves_context() {
|
||||
action: AppServerNetworkPolicyRuleAction::Allow,
|
||||
}]);
|
||||
|
||||
let Some(ThreadInteractiveRequest::Approval(ApprovalRequest::Exec {
|
||||
available_decisions,
|
||||
network_approval_context,
|
||||
additional_permissions,
|
||||
..
|
||||
})) = app
|
||||
let Some(ThreadInteractiveRequest::Approval(ApprovalRequest::Exec(approval))) = app
|
||||
.interactive_request_for_thread_request(thread_id, &request)
|
||||
.await
|
||||
.expect("valid localized paths")
|
||||
@@ -2557,14 +2552,14 @@ async fn inactive_thread_exec_approval_preserves_context() {
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
network_approval_context,
|
||||
approval.network_approval_context,
|
||||
Some(AppServerNetworkApprovalContext {
|
||||
host: "example.com".to_string(),
|
||||
protocol: AppServerNetworkApprovalProtocol::Socks5Tcp,
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
additional_permissions,
|
||||
approval.additional_permissions,
|
||||
Some(AdditionalPermissionProfile {
|
||||
network: Some(AdditionalNetworkPermissions {
|
||||
enabled: Some(true),
|
||||
@@ -2578,7 +2573,7 @@ async fn inactive_thread_exec_approval_preserves_context() {
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
available_decisions,
|
||||
approval.available_decisions,
|
||||
vec![
|
||||
codex_app_server_protocol::CommandExecutionApprovalDecision::Accept,
|
||||
codex_app_server_protocol::CommandExecutionApprovalDecision::AcceptForSession,
|
||||
@@ -2610,7 +2605,7 @@ async fn inactive_thread_exec_approval_splits_shell_wrapped_command() {
|
||||
params.command =
|
||||
Some(shlex::try_join(["/bin/zsh", "-lc", script]).expect("round-trippable shell wrapper"));
|
||||
|
||||
let Some(ThreadInteractiveRequest::Approval(ApprovalRequest::Exec { command, .. })) = app
|
||||
let Some(ThreadInteractiveRequest::Approval(ApprovalRequest::Exec(approval))) = app
|
||||
.interactive_request_for_thread_request(thread_id, &request)
|
||||
.await
|
||||
.expect("valid localized paths")
|
||||
@@ -2619,7 +2614,7 @@ async fn inactive_thread_exec_approval_splits_shell_wrapped_command() {
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
command,
|
||||
approval.command,
|
||||
vec![
|
||||
"/bin/zsh".to_string(),
|
||||
"-lc".to_string(),
|
||||
@@ -2670,14 +2665,11 @@ async fn inactive_thread_file_change_approval_recovers_buffered_changes() {
|
||||
.expect("valid localized paths")
|
||||
.expect("expected file change approval request");
|
||||
|
||||
let ThreadInteractiveRequest::Approval(ApprovalRequest::ApplyPatch {
|
||||
changes, reason, ..
|
||||
}) = &request
|
||||
else {
|
||||
let ThreadInteractiveRequest::Approval(ApprovalRequest::ApplyPatch(approval)) = &request else {
|
||||
panic!("expected apply-patch approval request");
|
||||
};
|
||||
assert_eq!(
|
||||
changes,
|
||||
&approval.changes,
|
||||
&HashMap::from([(
|
||||
PathBuf::from("README.md"),
|
||||
FileChange::Add {
|
||||
@@ -2686,7 +2678,7 @@ async fn inactive_thread_file_change_approval_recovers_buffered_changes() {
|
||||
)])
|
||||
);
|
||||
assert_eq!(
|
||||
reason,
|
||||
&approval.reason,
|
||||
&Some("command failed; retry without sandbox?".to_string())
|
||||
);
|
||||
|
||||
@@ -2728,11 +2720,7 @@ async fn inactive_thread_permissions_approval_preserves_file_system_permissions(
|
||||
},
|
||||
};
|
||||
|
||||
let Some(ThreadInteractiveRequest::Approval(ApprovalRequest::Permissions {
|
||||
environment_id,
|
||||
permissions,
|
||||
..
|
||||
})) = app
|
||||
let Some(ThreadInteractiveRequest::Approval(ApprovalRequest::Permissions(approval))) = app
|
||||
.interactive_request_for_thread_request(thread_id, &request)
|
||||
.await
|
||||
.expect("valid localized paths")
|
||||
@@ -2740,9 +2728,9 @@ async fn inactive_thread_permissions_approval_preserves_file_system_permissions(
|
||||
panic!("expected permissions approval request");
|
||||
};
|
||||
|
||||
assert_eq!(environment_id.as_deref(), Some("remote"));
|
||||
assert_eq!(approval.environment_id.as_deref(), Some("remote"));
|
||||
assert_eq!(
|
||||
permissions,
|
||||
approval.permissions,
|
||||
RequestPermissionProfile {
|
||||
network: Some(NetworkPermissions {
|
||||
enabled: Some(true),
|
||||
|
||||
@@ -219,7 +219,7 @@ impl App {
|
||||
let proposed_execpolicy_amendment = params.proposed_execpolicy_amendment.clone();
|
||||
let proposed_network_policy_amendments =
|
||||
params.proposed_network_policy_amendments.clone();
|
||||
Some(ThreadInteractiveRequest::Approval(ApprovalRequest::Exec {
|
||||
let approval = ExecApprovalRequest {
|
||||
thread_id,
|
||||
thread_label,
|
||||
id: params
|
||||
@@ -243,10 +243,14 @@ impl App {
|
||||
}),
|
||||
network_approval_context,
|
||||
additional_permissions,
|
||||
}))
|
||||
};
|
||||
Some(ThreadInteractiveRequest::Approval(ApprovalRequest::Exec(
|
||||
approval,
|
||||
)))
|
||||
}
|
||||
ServerRequest::FileChangeRequestApproval { params, .. } => Some(
|
||||
ThreadInteractiveRequest::Approval(ApprovalRequest::ApplyPatch {
|
||||
ThreadInteractiveRequest::Approval(ApprovalRequest::ApplyPatch(
|
||||
ApplyPatchApprovalRequest {
|
||||
thread_id,
|
||||
thread_label,
|
||||
id: params.item_id.clone(),
|
||||
@@ -260,7 +264,8 @@ impl App {
|
||||
.await
|
||||
.map(crate::app_server_approval_conversions::file_update_changes_to_display)
|
||||
.unwrap_or_default(),
|
||||
}),
|
||||
},
|
||||
)),
|
||||
),
|
||||
ServerRequest::McpServerElicitationRequest { request_id, params } => {
|
||||
if let Some(params) = AppLinkViewParams::from_url_app_server_request(
|
||||
@@ -284,13 +289,13 @@ impl App {
|
||||
message,
|
||||
..
|
||||
} => Some(ThreadInteractiveRequest::Approval(
|
||||
ApprovalRequest::McpElicitation {
|
||||
ApprovalRequest::McpElicitation(McpElicitationApprovalRequest {
|
||||
thread_id,
|
||||
thread_label,
|
||||
server_name: params.server_name.clone(),
|
||||
request_id: request_id.clone(),
|
||||
message: message.clone(),
|
||||
},
|
||||
}),
|
||||
)),
|
||||
codex_app_server_protocol::McpServerElicitationRequest::OpenAiForm {
|
||||
..
|
||||
@@ -319,14 +324,14 @@ impl App {
|
||||
)
|
||||
})?;
|
||||
Some(ThreadInteractiveRequest::Approval(
|
||||
ApprovalRequest::Permissions {
|
||||
ApprovalRequest::Permissions(PermissionsApprovalRequest {
|
||||
thread_id,
|
||||
thread_label,
|
||||
call_id: params.item_id.clone(),
|
||||
environment_id: params.environment_id.clone(),
|
||||
reason: params.reason.clone(),
|
||||
permissions,
|
||||
},
|
||||
}),
|
||||
))
|
||||
}
|
||||
_ => None,
|
||||
@@ -350,20 +355,17 @@ impl App {
|
||||
}
|
||||
|
||||
fn render_inactive_patch_preview(&mut self, request: &ApprovalRequest) {
|
||||
let ApprovalRequest::ApplyPatch {
|
||||
thread_label,
|
||||
cwd,
|
||||
changes,
|
||||
..
|
||||
} = request
|
||||
else {
|
||||
let ApprovalRequest::ApplyPatch(request) = request else {
|
||||
return;
|
||||
};
|
||||
if thread_label.is_none() || changes.is_empty() {
|
||||
if request.thread_label.is_none() || request.changes.is_empty() {
|
||||
return;
|
||||
}
|
||||
self.chat_widget
|
||||
.add_to_history(history_cell::new_patch_event(changes.clone(), cwd));
|
||||
.add_to_history(history_cell::new_patch_event(
|
||||
request.changes.clone(),
|
||||
&request.cwd,
|
||||
));
|
||||
}
|
||||
|
||||
pub(super) async fn pending_inactive_thread_requests(&self) -> Vec<(ThreadId, ServerRequest)> {
|
||||
|
||||
Reference in new issue
Block a user