tui: plumb permission profile selection (#23708)

## Why

The named-profile `/permissions` picker needs a small TUI action path
that can select permission profiles without folding the menu UI and
profile metadata into the same review.

## What changed

- Carry permission-profile selections through the TUI app event flow.
- Persist selected profiles while preserving the existing approval
settings and guardrail prompts.
- Keep the legacy `/permissions` picker behavior in this layer; the
profile-mode menu stays in the follow-up PR.

## Stack

1. [#22931](https://github.com/openai/codex/pull/22931):
runtime/session/network propagation for active permission profiles.
2. **This PR**: TUI selection plumbing and guardrail flow.
3. [#21559](https://github.com/openai/codex/pull/21559): profile-aware
`/permissions` menu and custom profile display.

<img width="1632" height="1186" alt="image"
src="https://github.com/user-attachments/assets/69ddcd5e-b57c-468d-8c1d-246916323c15"
/>

## Validation

- `git diff --cached --check` before commit.
- Full test run skipped at the user request while pushing the split
stack.
This commit is contained in:
viyatb-oai authored and GitHub committed 2026-05-21 12:26:36 -03:00
1 parent e0e304b123
commit fcff0d6c52
13 files changed
+627 -144

No files matched your search

+115 -18
View File
@@ -800,18 +800,24 @@ impl App {
AppEvent::OpenFullAccessConfirmation {
preset,
return_to_permissions,
profile_selection,
} => {
self.chat_widget
.open_full_access_confirmation(preset, return_to_permissions);
self.chat_widget.open_full_access_confirmation(
preset,
return_to_permissions,
profile_selection,
);
}
AppEvent::OpenWorldWritableWarningConfirmation {
preset,
profile_selection,
sample_paths,
extra_count,
failed_scan,
} => {
self.chat_widget.open_world_writable_warning_confirmation(
preset,
profile_selection,
sample_paths,
extra_count,
failed_scan,
@@ -848,10 +854,17 @@ impl App {
self.launch_external_editor(tui).await;
}
}
AppEvent::OpenWindowsSandboxEnablePrompt { preset } => {
self.chat_widget.open_windows_sandbox_enable_prompt(preset);
AppEvent::OpenWindowsSandboxEnablePrompt {
preset,
profile_selection,
} => {
self.chat_widget
.open_windows_sandbox_enable_prompt(preset, profile_selection);
}
AppEvent::OpenWindowsSandboxFallbackPrompt { preset } => {
AppEvent::OpenWindowsSandboxFallbackPrompt {
preset,
profile_selection,
} => {
self.session_telemetry.counter(
"codex.windows_sandbox.fallback_prompt_shown",
/*inc*/ 1,
@@ -866,12 +879,30 @@ impl App {
);
}
self.chat_widget
.open_windows_sandbox_fallback_prompt(preset);
.open_windows_sandbox_fallback_prompt(preset, profile_selection);
}
AppEvent::BeginWindowsSandboxElevatedSetup { preset } => {
AppEvent::BeginWindowsSandboxElevatedSetup {
preset,
profile_selection,
} => {
#[cfg(target_os = "windows")]
{
let permission_profile = preset.permission_profile.clone();
let permission_profile = match self
.permission_profile_for_windows_setup(&preset, profile_selection.as_ref())
.await
{
Ok(permission_profile) => permission_profile,
Err(err) => {
tracing::warn!(
error = %err,
"failed to resolve permission profile for elevated Windows sandbox setup"
);
self.chat_widget.add_error_message(format!(
"Failed to prepare Windows sandbox for the selected permission profile: {err}"
));
return Ok(AppRunControl::Continue);
}
};
let policy_cwd = self.config.cwd.clone();
let command_cwd = policy_cwd.clone();
let env_map: std::collections::HashMap<String, String> =
@@ -887,6 +918,7 @@ impl App {
tx.send(AppEvent::EnableWindowsSandboxForAgentMode {
preset,
mode: WindowsSandboxEnableMode::Elevated,
profile_selection,
});
return Ok(AppRunControl::Continue);
}
@@ -903,7 +935,10 @@ impl App {
);
})
else {
tx.send(AppEvent::OpenWindowsSandboxFallbackPrompt { preset });
tx.send(AppEvent::OpenWindowsSandboxFallbackPrompt {
preset,
profile_selection,
});
return Ok(AppRunControl::Continue);
};
tokio::task::spawn_blocking(move || {
@@ -924,6 +959,7 @@ impl App {
AppEvent::EnableWindowsSandboxForAgentMode {
preset: preset.clone(),
mode: WindowsSandboxEnableMode::Elevated,
profile_selection: profile_selection.clone(),
}
}
Err(err) => {
@@ -955,7 +991,10 @@ impl App {
error = %err,
"failed to run elevated Windows sandbox setup"
);
AppEvent::OpenWindowsSandboxFallbackPrompt { preset }
AppEvent::OpenWindowsSandboxFallbackPrompt {
preset,
profile_selection,
}
}
};
tx.send(event);
@@ -963,13 +1002,31 @@ impl App {
}
#[cfg(not(target_os = "windows"))]
{
let _ = preset;
let _ = (preset, profile_selection);
}
}
AppEvent::BeginWindowsSandboxLegacySetup { preset } => {
AppEvent::BeginWindowsSandboxLegacySetup {
preset,
profile_selection,
} => {
#[cfg(target_os = "windows")]
{
let permission_profile = preset.permission_profile.clone();
let permission_profile = match self
.permission_profile_for_windows_setup(&preset, profile_selection.as_ref())
.await
{
Ok(permission_profile) => permission_profile,
Err(err) => {
tracing::warn!(
error = %err,
"failed to resolve permission profile for legacy Windows sandbox setup"
);
self.chat_widget.add_error_message(format!(
"Failed to prepare Windows sandbox for the selected permission profile: {err}"
));
return Ok(AppRunControl::Continue);
}
};
let policy_cwd = self.config.cwd.clone();
let command_cwd = policy_cwd.clone();
let env_map: std::collections::HashMap<String, String> =
@@ -988,7 +1045,10 @@ impl App {
);
})
else {
tx.send(AppEvent::OpenWindowsSandboxFallbackPrompt { preset });
tx.send(AppEvent::OpenWindowsSandboxFallbackPrompt {
preset,
profile_selection,
});
return Ok(AppRunControl::Continue);
};
tokio::task::spawn_blocking(move || {
@@ -1014,12 +1074,13 @@ impl App {
tx.send(AppEvent::EnableWindowsSandboxForAgentMode {
preset,
mode: WindowsSandboxEnableMode::Legacy,
profile_selection,
});
});
}
#[cfg(not(target_os = "windows"))]
{
let _ = preset;
let _ = (preset, profile_selection);
}
}
AppEvent::BeginWindowsSandboxGrantReadRoot { path } => {
@@ -1082,7 +1143,11 @@ impl App {
));
}
},
AppEvent::EnableWindowsSandboxForAgentMode { preset, mode } => {
AppEvent::EnableWindowsSandboxForAgentMode {
preset,
mode,
profile_selection,
} => {
#[cfg(target_os = "windows")]
{
self.chat_widget.clear_windows_sandbox_setup_status();
@@ -1142,11 +1207,40 @@ impl App {
self.app_event_tx.send(
AppEvent::OpenWorldWritableWarningConfirmation {
preset: Some(preset.clone()),
profile_selection: profile_selection.clone(),
sample_paths,
extra_count,
failed_scan,
},
);
} else if let Some(selection) = profile_selection {
self.app_event_tx.send(AppEvent::CodexOp(
AppCommand::override_turn_context(
/*cwd*/ None,
/*approval_policy*/ None,
/*approvals_reviewer*/ None,
/*permission_profile*/ None,
/*active_permission_profile*/ None,
#[cfg(target_os = "windows")]
Some(windows_sandbox_level),
/*model*/ None,
/*effort*/ None,
/*summary*/ None,
/*service_tier*/ None,
/*collaboration_mode*/ None,
/*personality*/ None,
),
));
self.apply_permission_profile_selection(selection).await;
let _ = mode;
self.chat_widget.add_plain_history_lines(vec![
Line::from(vec!["• ".dim(), "Sandbox ready".into()]),
Line::from(vec![
" ".into(),
"Codex can now safely edit files and execute commands in your computer"
.dark_gray(),
]),
]);
} else {
self.app_event_tx.send(AppEvent::CodexOp(
AppCommand::override_turn_context(
@@ -1196,7 +1290,7 @@ impl App {
}
#[cfg(not(target_os = "windows"))]
{
let _ = (preset, mode);
let _ = (preset, mode, profile_selection);
}
}
AppEvent::PersistModelSelection { model, effort } => {
@@ -1460,7 +1554,7 @@ impl App {
return Ok(AppRunControl::Continue);
}
self.runtime_permission_profile_override =
Some(self.config.permissions.permission_profile().clone());
Some(RuntimePermissionProfileOverride::from_config(&self.config));
self.sync_active_thread_permission_settings_to_cached_session()
.await;
@@ -1496,6 +1590,9 @@ impl App {
}
}
}
AppEvent::SelectPermissionProfile(selection) => {
self.apply_permission_profile_selection(selection).await;
}
AppEvent::UpdateApprovalsReviewer(policy) => {
self.config.approvals_reviewer = policy;
self.chat_widget.set_approvals_reviewer(policy);