mirror of
https://github.com/openai/codex.git
synced 2026-11-26 07:26:11 +00:00
tui: add named permission profile picker (#21559)
## Why Users who opt into named permission profiles through `default_permissions` or `[permissions.*]` should stay in named-profile semantics when they open `/permissions`. The legacy picker rewrites those users into anonymous preset state, which loses the active profile identity and hides custom configured profiles. ## What changed - Switch `/permissions` to a profile-aware picker when profile mode is active. - Show friendly built-in labels instead of raw `:` profile syntax. - Include configured custom profiles and their descriptions in the picker. - Route selections through the split TUI profile-selection flow below this PR. - Add TUI snapshots and regression coverage for built-ins, custom profiles, and conflicting legacy runtime overrides. ## Stack 1. [#22931](https://github.com/openai/codex/pull/22931): runtime/session/network propagation for active permission profiles. 2. [#23708](https://github.com/openai/codex/pull/23708): TUI selection plumbing and guardrail flow. 3. **This PR**: profile-aware `/permissions` menu and custom profile display. ## UX impact In profile mode, `/permissions` shows the same human-facing built-ins users already know: ```text Default Auto-review Full Access Read Only locked-down web-enabled ``` Selecting `locked-down` keeps `active_permission_profile = Some("locked-down")`; selecting a built-in keeps the friendly label while switching to its named built-in profile. ## Screenshots Live `$test-tui` smoke screenshots uploaded through GitHub attachments: **Profile mode with built-ins and custom profiles** <img width="832" alt="Profile mode permissions picker with custom profiles" src="https://github.com/user-attachments/assets/58b72431-418c-4839-9e39-575076db4c8f" /> **Legacy mode remains anonymous preset picker** <img width="1232" alt="Legacy permissions picker" src="https://github.com/user-attachments/assets/95f413ab-4cee-411c-9afb-92580a885c97" /> <img width="1296" height="906" alt="image" src="https://github.com/user-attachments/assets/ea381a78-9904-4aa2-828f-b7f2e43f60f2" /> <img width="705" height="207" alt="Screenshot 2026-05-18 at 2 58 00 PM" src="https://github.com/user-attachments/assets/2fa6dd71-0296-449e-a6de-a72d78a1cb70" /> ## 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:
1 parent
ef6528c6c7
commit
f6fd753039
9 files changed
+424
-10
No files matched your search
@@ -0,0 +1,171 @@
|
||||
use super::*;
|
||||
|
||||
impl ChatWidget {
|
||||
pub(super) fn open_permission_profiles_popup(&mut self) {
|
||||
let active_profile_id = self
|
||||
.config
|
||||
.permissions
|
||||
.active_permission_profile()
|
||||
.map(|profile| profile.id);
|
||||
let presets = builtin_approval_presets();
|
||||
let Some(read_only) = presets.iter().find(|preset| preset.id == "read-only") else {
|
||||
self.add_error_message(
|
||||
"Internal error: missing the 'read-only' approval preset.".to_string(),
|
||||
);
|
||||
return;
|
||||
};
|
||||
let Some(default) = presets.iter().find(|preset| preset.id == "auto") else {
|
||||
self.add_error_message(
|
||||
"Internal error: missing the 'auto' approval preset.".to_string(),
|
||||
);
|
||||
return;
|
||||
};
|
||||
let Some(full_access) = presets.iter().find(|preset| preset.id == "full-access") else {
|
||||
self.add_error_message(
|
||||
"Internal error: missing the 'full-access' approval preset.".to_string(),
|
||||
);
|
||||
return;
|
||||
};
|
||||
let mut items = vec![
|
||||
self.builtin_permission_mode_selection_item(
|
||||
default,
|
||||
":workspace",
|
||||
default
|
||||
.description
|
||||
.replace(" (Identical to Agent mode)", ""),
|
||||
AskForApproval::from(default.approval),
|
||||
ApprovalsReviewer::User,
|
||||
),
|
||||
];
|
||||
if self.config.features.enabled(Feature::GuardianApproval) {
|
||||
items.push(self.builtin_permission_mode_selection_item(
|
||||
default,
|
||||
":workspace",
|
||||
AUTO_REVIEW_DESCRIPTION.to_string(),
|
||||
AskForApproval::OnRequest,
|
||||
ApprovalsReviewer::AutoReview,
|
||||
));
|
||||
}
|
||||
items.push(self.builtin_permission_mode_selection_item(
|
||||
full_access,
|
||||
":danger-no-sandbox",
|
||||
full_access.description.to_string(),
|
||||
AskForApproval::from(full_access.approval),
|
||||
ApprovalsReviewer::User,
|
||||
));
|
||||
items.push(self.builtin_permission_mode_selection_item(
|
||||
read_only,
|
||||
":read-only",
|
||||
read_only.description.to_string(),
|
||||
AskForApproval::from(read_only.approval),
|
||||
ApprovalsReviewer::User,
|
||||
));
|
||||
items.extend(
|
||||
self.config
|
||||
.custom_permission_profiles
|
||||
.iter()
|
||||
.map(|profile| {
|
||||
Self::permission_profile_selection_item(
|
||||
&profile.id,
|
||||
&profile.id,
|
||||
profile
|
||||
.description
|
||||
.as_deref()
|
||||
.unwrap_or("Configured permission profile."),
|
||||
active_profile_id.as_deref(),
|
||||
)
|
||||
}),
|
||||
);
|
||||
|
||||
self.bottom_pane.show_selection_view(SelectionViewParams {
|
||||
title: Some("Update Model Permissions".to_string()),
|
||||
footer_hint: Some(standard_popup_hint_line()),
|
||||
items,
|
||||
header: Box::new(()),
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
|
||||
fn builtin_permission_mode_selection_item(
|
||||
&self,
|
||||
preset: &ApprovalPreset,
|
||||
id: &str,
|
||||
description: String,
|
||||
approval_policy: AskForApproval,
|
||||
approvals_reviewer: ApprovalsReviewer,
|
||||
) -> SelectionItem {
|
||||
let label = if approvals_reviewer == ApprovalsReviewer::AutoReview {
|
||||
"Auto-review"
|
||||
} else {
|
||||
preset.label
|
||||
};
|
||||
let active_profile_id = self
|
||||
.config
|
||||
.permissions
|
||||
.active_permission_profile()
|
||||
.map(|profile| profile.id);
|
||||
let current_approval =
|
||||
AskForApproval::from(self.config.permissions.approval_policy.value());
|
||||
let current_reviewer = self.config.approvals_reviewer;
|
||||
let profile_id = id.to_string();
|
||||
let selection = PermissionProfileSelection {
|
||||
profile_id,
|
||||
approval_policy: Some(approval_policy),
|
||||
approvals_reviewer: Some(approvals_reviewer),
|
||||
display_label: label.to_string(),
|
||||
};
|
||||
SelectionItem {
|
||||
name: label.to_string(),
|
||||
description: Some(description),
|
||||
is_current: active_profile_id.as_deref() == Some(id)
|
||||
&& current_approval == approval_policy
|
||||
&& current_reviewer == approvals_reviewer,
|
||||
actions: self.permission_mode_actions(
|
||||
preset,
|
||||
label.to_string(),
|
||||
approvals_reviewer,
|
||||
Some(selection),
|
||||
/*return_to_permissions*/ true,
|
||||
),
|
||||
dismiss_on_select: true,
|
||||
disabled_reason: self
|
||||
.config
|
||||
.permissions
|
||||
.approval_policy
|
||||
.can_set(&approval_policy.to_core())
|
||||
.err()
|
||||
.map(|err| err.to_string())
|
||||
.or_else(|| {
|
||||
self.config
|
||||
.permissions
|
||||
.can_set_permission_profile(&preset.permission_profile)
|
||||
.err()
|
||||
.map(|err| err.to_string())
|
||||
}),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
fn permission_profile_selection_item(
|
||||
label: &str,
|
||||
id: &str,
|
||||
description: &str,
|
||||
active_profile_id: Option<&str>,
|
||||
) -> SelectionItem {
|
||||
let id_for_action = id.to_string();
|
||||
let selection = PermissionProfileSelection {
|
||||
profile_id: id_for_action.clone(),
|
||||
approval_policy: None,
|
||||
approvals_reviewer: None,
|
||||
display_label: id_for_action,
|
||||
};
|
||||
SelectionItem {
|
||||
name: label.to_string(),
|
||||
description: Some(description.to_string()),
|
||||
is_current: active_profile_id == Some(id),
|
||||
actions: Self::permission_profile_selection_actions(selection),
|
||||
dismiss_on_select: true,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user