mirror of
https://github.com/openai/codex.git
synced 2026-11-19 22:30:42 +00:00
feat(tui): preselect suggested permission scope
Thread `suggestedScope` through the app-server permission approval request and use it when constructing TUI approval requests. This keeps the protocol backward compatible by defaulting the field to `turn` when older clients omit it. Add focused app-server and TUI coverage, plus a snapshot for the session-suggested approval overlay so reviewers can see the preselected session row.
This commit is contained in:
@@ -1079,7 +1079,7 @@ the client can offer session-scoped and/or persistent approval choices.
|
||||
|
||||
Clients must opt into conversational permission confirmation request methods by listing them in `initialize.params.capabilities.supportedServerRequests`. The opt-in is per connection and per method, which lets older clients continue to initialize without promising UI they do not implement.
|
||||
|
||||
The built-in `request_permissions` tool sends an `item/permissions/requestApproval` JSON-RPC request to the client with the requested permission profile. This v2 payload mirrors the command-execution `additionalPermissions` shape: it can request network access and additional filesystem access.
|
||||
The built-in `request_permissions` tool sends an `item/permissions/requestApproval` JSON-RPC request to the client with the requested permission profile. This v2 payload mirrors the command-execution `additionalPermissions` shape: it can request network access and additional filesystem access, and it includes `suggestedScope` so clients can preselect the model's requested lifetime while still requiring explicit confirmation.
|
||||
|
||||
```json
|
||||
{
|
||||
@@ -1090,6 +1090,7 @@ The built-in `request_permissions` tool sends an `item/permissions/requestApprov
|
||||
"turnId": "turn_123",
|
||||
"itemId": "call_123",
|
||||
"reason": "Select a workspace root",
|
||||
"suggestedScope": "session",
|
||||
"permissions": {
|
||||
"fileSystem": {
|
||||
"write": ["/Users/me/project", "/Users/me/shared"]
|
||||
|
||||
@@ -866,6 +866,7 @@ pub(crate) async fn apply_bespoke_event_handling(
|
||||
item_id: request.call_id.clone(),
|
||||
reason: request.reason,
|
||||
permissions: request.permissions.into(),
|
||||
suggested_scope: request.suggested_scope.into(),
|
||||
};
|
||||
let (pending_request_id, rx) = request_permissions_outgoing
|
||||
.send_request(ServerRequestPayload::PermissionsRequestApproval(params))
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use codex_protocol::request_permissions::PermissionGrantScope;
|
||||
use core_test_support::responses;
|
||||
use serde_json::json;
|
||||
use std::path::Path;
|
||||
@@ -84,7 +85,10 @@ pub fn create_request_user_input_sse_response(call_id: &str) -> anyhow::Result<S
|
||||
]))
|
||||
}
|
||||
|
||||
pub fn create_request_permissions_sse_response(call_id: &str) -> anyhow::Result<String> {
|
||||
pub fn create_request_permissions_sse_response(
|
||||
call_id: &str,
|
||||
scope: PermissionGrantScope,
|
||||
) -> anyhow::Result<String> {
|
||||
let tool_call_arguments = serde_json::to_string(&json!({
|
||||
"reason": "Select a workspace root",
|
||||
"permissions": {
|
||||
@@ -94,7 +98,8 @@ pub fn create_request_permissions_sse_response(call_id: &str) -> anyhow::Result<
|
||||
"../shared"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"scope": scope,
|
||||
}))?;
|
||||
|
||||
Ok(responses::sse(vec![
|
||||
|
||||
@@ -18,6 +18,7 @@ use codex_app_server_protocol::ThreadStartResponse;
|
||||
use codex_app_server_protocol::TurnStartParams;
|
||||
use codex_app_server_protocol::TurnStartResponse;
|
||||
use codex_app_server_protocol::UserInput as V2UserInput;
|
||||
use codex_protocol::request_permissions::PermissionGrantScope;
|
||||
use serde_json::Value;
|
||||
use serde_json::json;
|
||||
use tokio::time::timeout;
|
||||
@@ -75,7 +76,7 @@ async fn permission_tools_expose_only_the_narrow_flow_for_now() -> Result<()> {
|
||||
async fn request_permissions_round_trips_when_client_supports_app_request() -> Result<()> {
|
||||
let codex_home = tempfile::TempDir::new()?;
|
||||
let responses = vec![
|
||||
create_request_permissions_sse_response("call1")?,
|
||||
create_request_permissions_sse_response("call1", PermissionGrantScope::Session)?,
|
||||
create_final_assistant_message_sse_response("done")?,
|
||||
];
|
||||
let server = create_mock_responses_server_sequence(responses).await;
|
||||
@@ -101,6 +102,10 @@ async fn request_permissions_round_trips_when_client_supports_app_request() -> R
|
||||
assert_eq!(params.thread_id, thread_id);
|
||||
assert_eq!(params.item_id, "call1");
|
||||
assert_eq!(params.reason.as_deref(), Some("Select a workspace root"));
|
||||
assert_eq!(
|
||||
params.suggested_scope,
|
||||
codex_app_server_protocol::PermissionGrantScope::Session
|
||||
);
|
||||
let resolved_request_id = request_id.clone();
|
||||
|
||||
mcp.send_response(
|
||||
@@ -121,7 +126,7 @@ async fn request_permissions_round_trips_when_client_supports_app_request() -> R
|
||||
async fn request_permissions_auto_declines_without_app_request() -> Result<()> {
|
||||
let codex_home = tempfile::TempDir::new()?;
|
||||
let responses = vec![
|
||||
create_request_permissions_sse_response("call1")?,
|
||||
create_request_permissions_sse_response("call1", PermissionGrantScope::Turn)?,
|
||||
create_final_assistant_message_sse_response("done")?,
|
||||
];
|
||||
let server = create_mock_responses_server_sequence(responses).await;
|
||||
|
||||
Reference in New Issue
Block a user