mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50:46 +00:00
Add request_permissions_tool always allow
Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
@@ -39,6 +39,17 @@
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"PermissionProfilePersistence": {
|
||||
"properties": {
|
||||
"profileName": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"profileName"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"RequestPermissionProfile": {
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
@@ -73,6 +84,17 @@
|
||||
"permissions": {
|
||||
"$ref": "#/definitions/RequestPermissionProfile"
|
||||
},
|
||||
"permissionsProfilePersistence": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/PermissionProfilePersistence"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
],
|
||||
"default": null
|
||||
},
|
||||
"reason": {
|
||||
"type": [
|
||||
"string",
|
||||
|
||||
@@ -39,6 +39,31 @@
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"AdditionalPermissionProfile": {
|
||||
"properties": {
|
||||
"fileSystem": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/AdditionalFileSystemPermissions"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
},
|
||||
"network": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/AdditionalNetworkPermissions"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"GrantedPermissionProfile": {
|
||||
"properties": {
|
||||
"fileSystem": {
|
||||
@@ -65,11 +90,75 @@
|
||||
"type": "object"
|
||||
},
|
||||
"PermissionGrantScope": {
|
||||
"enum": [
|
||||
"turn",
|
||||
"session"
|
||||
"oneOf": [
|
||||
{
|
||||
"properties": {
|
||||
"type": {
|
||||
"enum": [
|
||||
"turn"
|
||||
],
|
||||
"title": "TurnPermissionGrantScopeType",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"type"
|
||||
],
|
||||
"title": "TurnPermissionGrantScope",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"type": {
|
||||
"enum": [
|
||||
"session"
|
||||
],
|
||||
"title": "SessionPermissionGrantScopeType",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"type"
|
||||
],
|
||||
"title": "SessionPermissionGrantScope",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"permissionProfileAmendment": {
|
||||
"$ref": "#/definitions/PermissionProfileAmendment"
|
||||
},
|
||||
"type": {
|
||||
"enum": [
|
||||
"persist"
|
||||
],
|
||||
"title": "PersistPermissionGrantScopeType",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"permissionProfileAmendment",
|
||||
"type"
|
||||
],
|
||||
"title": "PersistPermissionGrantScope",
|
||||
"type": "object"
|
||||
}
|
||||
]
|
||||
},
|
||||
"PermissionProfileAmendment": {
|
||||
"properties": {
|
||||
"permissions": {
|
||||
"$ref": "#/definitions/AdditionalPermissionProfile"
|
||||
},
|
||||
"profileName": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"permissions",
|
||||
"profileName"
|
||||
],
|
||||
"type": "string"
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
@@ -82,7 +171,9 @@
|
||||
"$ref": "#/definitions/PermissionGrantScope"
|
||||
}
|
||||
],
|
||||
"default": "turn"
|
||||
"default": {
|
||||
"type": "turn"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
||||
@@ -1344,6 +1344,17 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"PermissionProfilePersistence": {
|
||||
"properties": {
|
||||
"profileName": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"profileName"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"PermissionsRequestApprovalParams": {
|
||||
"properties": {
|
||||
"itemId": {
|
||||
@@ -1352,6 +1363,17 @@
|
||||
"permissions": {
|
||||
"$ref": "#/definitions/RequestPermissionProfile"
|
||||
},
|
||||
"permissionsProfilePersistence": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/PermissionProfilePersistence"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
],
|
||||
"default": null
|
||||
},
|
||||
"reason": {
|
||||
"type": [
|
||||
"string",
|
||||
|
||||
@@ -3230,11 +3230,86 @@
|
||||
]
|
||||
},
|
||||
"PermissionGrantScope": {
|
||||
"enum": [
|
||||
"turn",
|
||||
"session"
|
||||
"oneOf": [
|
||||
{
|
||||
"properties": {
|
||||
"type": {
|
||||
"enum": [
|
||||
"turn"
|
||||
],
|
||||
"title": "TurnPermissionGrantScopeType",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"type"
|
||||
],
|
||||
"title": "TurnPermissionGrantScope",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"type": {
|
||||
"enum": [
|
||||
"session"
|
||||
],
|
||||
"title": "SessionPermissionGrantScopeType",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"type"
|
||||
],
|
||||
"title": "SessionPermissionGrantScope",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"permissionProfileAmendment": {
|
||||
"$ref": "#/definitions/PermissionProfileAmendment"
|
||||
},
|
||||
"type": {
|
||||
"enum": [
|
||||
"persist"
|
||||
],
|
||||
"title": "PersistPermissionGrantScopeType",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"permissionProfileAmendment",
|
||||
"type"
|
||||
],
|
||||
"title": "PersistPermissionGrantScope",
|
||||
"type": "object"
|
||||
}
|
||||
]
|
||||
},
|
||||
"PermissionProfileAmendment": {
|
||||
"properties": {
|
||||
"permissions": {
|
||||
"$ref": "#/definitions/AdditionalPermissionProfile"
|
||||
},
|
||||
"profileName": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"permissions",
|
||||
"profileName"
|
||||
],
|
||||
"type": "string"
|
||||
"type": "object"
|
||||
},
|
||||
"PermissionProfilePersistence": {
|
||||
"properties": {
|
||||
"profileName": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"profileName"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"PermissionsRequestApprovalParams": {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
@@ -3245,6 +3320,17 @@
|
||||
"permissions": {
|
||||
"$ref": "#/definitions/RequestPermissionProfile"
|
||||
},
|
||||
"permissionsProfilePersistence": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/PermissionProfilePersistence"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
],
|
||||
"default": null
|
||||
},
|
||||
"reason": {
|
||||
"type": [
|
||||
"string",
|
||||
@@ -3279,7 +3365,9 @@
|
||||
"$ref": "#/definitions/PermissionGrantScope"
|
||||
}
|
||||
],
|
||||
"default": "turn"
|
||||
"default": {
|
||||
"type": "turn"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// GENERATED CODE! DO NOT MODIFY BY HAND!
|
||||
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { PermissionProfileAmendment } from "./PermissionProfileAmendment";
|
||||
|
||||
export type PermissionGrantScope = "turn" | "session";
|
||||
export type PermissionGrantScope = { "type": "turn" } | { "type": "session" } | { "type": "persist", permissionProfileAmendment: PermissionProfileAmendment, };
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// GENERATED CODE! DO NOT MODIFY BY HAND!
|
||||
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { AdditionalPermissionProfile } from "./AdditionalPermissionProfile";
|
||||
|
||||
export type PermissionProfileAmendment = { profileName: string, permissions: AdditionalPermissionProfile, };
|
||||
@@ -0,0 +1,5 @@
|
||||
// GENERATED CODE! DO NOT MODIFY BY HAND!
|
||||
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
|
||||
export type PermissionProfilePersistence = { profileName: string, };
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
// GENERATED CODE! DO NOT MODIFY BY HAND!
|
||||
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { PermissionProfilePersistence } from "./PermissionProfilePersistence";
|
||||
import type { RequestPermissionProfile } from "./RequestPermissionProfile";
|
||||
|
||||
export type PermissionsRequestApprovalParams = { threadId: string, turnId: string, itemId: string, reason: string | null, permissions: RequestPermissionProfile, };
|
||||
export type PermissionsRequestApprovalParams = { threadId: string, turnId: string, itemId: string, reason?: string | null, permissions: RequestPermissionProfile, permissionsProfilePersistence?: PermissionProfilePersistence | null, };
|
||||
|
||||
@@ -214,6 +214,8 @@ export type { OverriddenMetadata } from "./OverriddenMetadata";
|
||||
export type { PatchApplyStatus } from "./PatchApplyStatus";
|
||||
export type { PatchChangeKind } from "./PatchChangeKind";
|
||||
export type { PermissionGrantScope } from "./PermissionGrantScope";
|
||||
export type { PermissionProfileAmendment } from "./PermissionProfileAmendment";
|
||||
export type { PermissionProfilePersistence } from "./PermissionProfilePersistence";
|
||||
export type { PermissionsRequestApprovalParams } from "./PermissionsRequestApprovalParams";
|
||||
export type { PermissionsRequestApprovalResponse } from "./PermissionsRequestApprovalResponse";
|
||||
export type { PlanDeltaNotification } from "./PlanDeltaNotification";
|
||||
|
||||
@@ -68,6 +68,7 @@ use codex_protocol::protocol::ModelRerouteReason as CoreModelRerouteReason;
|
||||
use codex_protocol::protocol::NetworkAccess as CoreNetworkAccess;
|
||||
use codex_protocol::protocol::NonSteerableTurnKind as CoreNonSteerableTurnKind;
|
||||
use codex_protocol::protocol::PatchApplyStatus as CorePatchApplyStatus;
|
||||
use codex_protocol::protocol::PersistPermissionProfileAction as CorePersistPermissionProfileAction;
|
||||
use codex_protocol::protocol::RateLimitSnapshot as CoreRateLimitSnapshot;
|
||||
use codex_protocol::protocol::RateLimitWindow as CoreRateLimitWindow;
|
||||
use codex_protocol::protocol::ReadOnlyAccess as CoreReadOnlyAccess;
|
||||
@@ -87,6 +88,7 @@ use codex_protocol::protocol::SubAgentSource as CoreSubAgentSource;
|
||||
use codex_protocol::protocol::TokenUsage as CoreTokenUsage;
|
||||
use codex_protocol::protocol::TokenUsageInfo as CoreTokenUsageInfo;
|
||||
use codex_protocol::request_permissions::PermissionGrantScope as CorePermissionGrantScope;
|
||||
use codex_protocol::request_permissions::PermissionProfilePersistence as CorePermissionProfilePersistence;
|
||||
use codex_protocol::request_permissions::RequestPermissionProfile as CoreRequestPermissionProfile;
|
||||
use codex_protocol::user_input::ByteRange as CoreByteRange;
|
||||
use codex_protocol::user_input::TextElement as CoreTextElement;
|
||||
@@ -1157,6 +1159,21 @@ pub struct RequestPermissionProfile {
|
||||
pub file_system: Option<AdditionalFileSystemPermissions>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export_to = "v2/")]
|
||||
pub struct PermissionProfilePersistence {
|
||||
pub profile_name: String,
|
||||
}
|
||||
|
||||
impl From<CorePermissionProfilePersistence> for PermissionProfilePersistence {
|
||||
fn from(value: CorePermissionProfilePersistence) -> Self {
|
||||
Self {
|
||||
profile_name: value.profile_name,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CoreRequestPermissionProfile> for RequestPermissionProfile {
|
||||
fn from(value: CoreRequestPermissionProfile) -> Self {
|
||||
Self {
|
||||
@@ -1222,6 +1239,24 @@ impl From<GrantedPermissionProfile> for CorePermissionProfile {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CorePermissionProfile> for GrantedPermissionProfile {
|
||||
fn from(value: CorePermissionProfile) -> Self {
|
||||
Self {
|
||||
network: value.network.map(AdditionalNetworkPermissions::from),
|
||||
file_system: value.file_system.map(AdditionalFileSystemPermissions::from),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CoreRequestPermissionProfile> for GrantedPermissionProfile {
|
||||
fn from(value: CoreRequestPermissionProfile) -> Self {
|
||||
Self {
|
||||
network: value.network.map(AdditionalNetworkPermissions::from),
|
||||
file_system: value.file_system.map(AdditionalFileSystemPermissions::from),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export_to = "v2/")]
|
||||
@@ -6161,18 +6196,91 @@ pub struct PermissionsRequestApprovalParams {
|
||||
pub thread_id: String,
|
||||
pub turn_id: String,
|
||||
pub item_id: String,
|
||||
#[ts(optional = nullable)]
|
||||
pub reason: Option<String>,
|
||||
pub permissions: RequestPermissionProfile,
|
||||
#[serde(default)]
|
||||
#[ts(optional = nullable)]
|
||||
pub permissions_profile_persistence: Option<PermissionProfilePersistence>,
|
||||
}
|
||||
|
||||
v2_enum_from_core!(
|
||||
#[derive(Default)]
|
||||
pub enum PermissionGrantScope from CorePermissionGrantScope {
|
||||
#[default]
|
||||
Turn,
|
||||
Session
|
||||
impl From<PermissionProfilePersistence> for CorePermissionProfilePersistence {
|
||||
fn from(value: PermissionProfilePersistence) -> Self {
|
||||
Self {
|
||||
profile_name: value.profile_name,
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export_to = "v2/")]
|
||||
pub struct PermissionProfileAmendment {
|
||||
pub profile_name: String,
|
||||
pub permissions: AdditionalPermissionProfile,
|
||||
}
|
||||
|
||||
impl From<CorePersistPermissionProfileAction> for PermissionProfileAmendment {
|
||||
fn from(value: CorePersistPermissionProfileAction) -> Self {
|
||||
Self {
|
||||
profile_name: value.profile_name,
|
||||
permissions: value.permissions.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PermissionProfileAmendment> for CorePersistPermissionProfileAction {
|
||||
fn from(value: PermissionProfileAmendment) -> Self {
|
||||
Self {
|
||||
profile_name: value.profile_name,
|
||||
permissions: value.permissions.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
|
||||
#[serde(tag = "type", rename_all = "camelCase")]
|
||||
#[ts(tag = "type")]
|
||||
#[ts(export_to = "v2/")]
|
||||
#[derive(Default)]
|
||||
pub enum PermissionGrantScope {
|
||||
#[default]
|
||||
Turn,
|
||||
Session,
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(rename_all = "camelCase")]
|
||||
Persist {
|
||||
permission_profile_amendment: PermissionProfileAmendment,
|
||||
},
|
||||
}
|
||||
|
||||
impl PermissionGrantScope {
|
||||
pub fn to_core(self) -> CorePermissionGrantScope {
|
||||
match self {
|
||||
Self::Turn => CorePermissionGrantScope::Turn,
|
||||
Self::Session => CorePermissionGrantScope::Session,
|
||||
Self::Persist {
|
||||
permission_profile_amendment,
|
||||
} => CorePermissionGrantScope::Persist {
|
||||
permission_profile_amendment: permission_profile_amendment.into(),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CorePermissionGrantScope> for PermissionGrantScope {
|
||||
fn from(value: CorePermissionGrantScope) -> Self {
|
||||
match value {
|
||||
CorePermissionGrantScope::Turn => Self::Turn,
|
||||
CorePermissionGrantScope::Session => Self::Session,
|
||||
CorePermissionGrantScope::Persist {
|
||||
permission_profile_amendment,
|
||||
} => Self::Persist {
|
||||
permission_profile_amendment: permission_profile_amendment.into(),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
@@ -6548,6 +6656,7 @@ mod tests {
|
||||
}),
|
||||
}
|
||||
);
|
||||
assert_eq!(params.permissions_profile_persistence, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -116,6 +116,7 @@ use codex_protocol::ThreadId;
|
||||
use codex_protocol::dynamic_tools::DynamicToolCallOutputContentItem as CoreDynamicToolCallOutputContentItem;
|
||||
use codex_protocol::dynamic_tools::DynamicToolResponse as CoreDynamicToolResponse;
|
||||
use codex_protocol::items::parse_hook_prompt_message;
|
||||
use codex_protocol::models::PermissionProfile as CorePermissionProfile;
|
||||
use codex_protocol::plan_tool::UpdatePlanArgs;
|
||||
use codex_protocol::protocol::CodexErrorInfo as CoreCodexErrorInfo;
|
||||
use codex_protocol::protocol::Event;
|
||||
@@ -124,6 +125,7 @@ use codex_protocol::protocol::ExecApprovalRequestEvent;
|
||||
use codex_protocol::protocol::McpToolCallBeginEvent;
|
||||
use codex_protocol::protocol::McpToolCallEndEvent;
|
||||
use codex_protocol::protocol::Op;
|
||||
use codex_protocol::protocol::PersistPermissionProfileAction as CorePersistPermissionProfileAction;
|
||||
use codex_protocol::protocol::RealtimeEvent;
|
||||
use codex_protocol::protocol::ReviewDecision;
|
||||
use codex_protocol::protocol::ReviewOutputEvent;
|
||||
@@ -857,6 +859,10 @@ pub(crate) async fn apply_bespoke_event_handling(
|
||||
item_id: request.call_id.clone(),
|
||||
reason: request.reason,
|
||||
permissions: request.permissions.into(),
|
||||
permissions_profile_persistence: request
|
||||
.permissions_profile_persistence
|
||||
.clone()
|
||||
.map(Into::into),
|
||||
};
|
||||
let (pending_request_id, rx) = outgoing
|
||||
.send_request(ServerRequestPayload::PermissionsRequestApproval(params))
|
||||
@@ -2536,13 +2542,27 @@ fn request_permissions_response_from_client_result(
|
||||
scope: codex_app_server_protocol::PermissionGrantScope::Turn,
|
||||
}
|
||||
});
|
||||
let granted_permissions: CorePermissionProfile =
|
||||
intersect_permission_profiles(requested_permissions.into(), response.permissions.into());
|
||||
Some(CoreRequestPermissionsResponse {
|
||||
permissions: intersect_permission_profiles(
|
||||
requested_permissions.into(),
|
||||
response.permissions.into(),
|
||||
)
|
||||
.into(),
|
||||
scope: response.scope.to_core(),
|
||||
permissions: granted_permissions.clone().into(),
|
||||
scope: match response.scope {
|
||||
codex_app_server_protocol::PermissionGrantScope::Turn => CorePermissionGrantScope::Turn,
|
||||
codex_app_server_protocol::PermissionGrantScope::Session => {
|
||||
CorePermissionGrantScope::Session
|
||||
}
|
||||
codex_app_server_protocol::PermissionGrantScope::Persist {
|
||||
permission_profile_amendment,
|
||||
} => CorePermissionGrantScope::Persist {
|
||||
permission_profile_amendment: CorePersistPermissionProfileAction {
|
||||
profile_name: permission_profile_amendment.profile_name,
|
||||
permissions: intersect_permission_profiles(
|
||||
granted_permissions,
|
||||
permission_profile_amendment.permissions.into(),
|
||||
),
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -3691,7 +3711,9 @@ mod tests {
|
||||
let response = request_permissions_response_from_client_result(
|
||||
CoreRequestPermissionProfile::default(),
|
||||
Ok(Ok(serde_json::json!({
|
||||
"scope": "session",
|
||||
"scope": {
|
||||
"type": "session",
|
||||
},
|
||||
"permissions": {},
|
||||
}))),
|
||||
)
|
||||
|
||||
@@ -22,6 +22,7 @@ use crate::compact::run_inline_auto_compact_task;
|
||||
use crate::compact::should_use_remote_compact_task;
|
||||
use crate::compact_remote::run_inline_remote_auto_compact_task;
|
||||
use crate::config::ManagedFeatures;
|
||||
use crate::config::persistence_target_for_permissions;
|
||||
use crate::connectors;
|
||||
use crate::exec_policy::ExecPolicyManager;
|
||||
use crate::installation_id::resolve_installation_id;
|
||||
@@ -3294,7 +3295,11 @@ impl Session {
|
||||
call_id,
|
||||
turn_id: turn_context.sub_id.clone(),
|
||||
reason: args.reason,
|
||||
permissions: args.permissions,
|
||||
permissions: args.permissions.clone(),
|
||||
permissions_profile_persistence: persistence_target_for_permissions(
|
||||
turn_context.config.as_ref(),
|
||||
&args.permissions.into(),
|
||||
),
|
||||
});
|
||||
self.send_event(turn_context, event).await;
|
||||
rx_response.await.ok()
|
||||
@@ -3449,8 +3454,8 @@ impl Session {
|
||||
let mut ts = at.turn_state.lock().await;
|
||||
let entry = ts.remove_pending_request_permissions(call_id);
|
||||
if entry.is_some() && !response.permissions.is_empty() {
|
||||
match response.scope {
|
||||
PermissionGrantScope::Turn => {
|
||||
match &response.scope {
|
||||
PermissionGrantScope::Turn | PermissionGrantScope::Persist { .. } => {
|
||||
ts.record_granted_permissions(response.permissions.clone().into());
|
||||
}
|
||||
PermissionGrantScope::Session => {
|
||||
@@ -4877,6 +4882,7 @@ mod handlers {
|
||||
use crate::SkillError;
|
||||
use crate::codex::spawn_review_thread;
|
||||
use crate::config::Config;
|
||||
use crate::config::edit::ConfigEditsBuilder;
|
||||
use crate::config_loader::CloudRequirementsLoader;
|
||||
use crate::config_loader::LoaderOverrides;
|
||||
use crate::config_loader::load_config_layers_state;
|
||||
@@ -4910,6 +4916,7 @@ mod handlers {
|
||||
use codex_protocol::protocol::ThreadRolledBackEvent;
|
||||
use codex_protocol::protocol::TurnAbortReason;
|
||||
use codex_protocol::protocol::WarningEvent;
|
||||
use codex_protocol::request_permissions::PermissionGrantScope;
|
||||
use codex_protocol::request_permissions::RequestPermissionsResponse;
|
||||
use codex_protocol::request_user_input::RequestUserInputResponse;
|
||||
|
||||
@@ -5214,6 +5221,42 @@ mod handlers {
|
||||
id: String,
|
||||
response: RequestPermissionsResponse,
|
||||
) {
|
||||
let persist_permissions = match &response.scope {
|
||||
PermissionGrantScope::Persist {
|
||||
permission_profile_amendment,
|
||||
} => Some(permission_profile_amendment.clone()),
|
||||
PermissionGrantScope::Turn | PermissionGrantScope::Session => None,
|
||||
};
|
||||
if let Some(action) = persist_permissions {
|
||||
let codex_home = sess.codex_home().await;
|
||||
let persist_result = match crate::config::validate_persist_permission_profile_action(
|
||||
sess.get_config().await.as_ref(),
|
||||
&action,
|
||||
) {
|
||||
Ok(()) => {
|
||||
ConfigEditsBuilder::new(&codex_home)
|
||||
.merge_permission_profile(action)
|
||||
.apply()
|
||||
.await
|
||||
}
|
||||
Err(err) => Err(err.into()),
|
||||
};
|
||||
if let Err(err) = persist_result {
|
||||
let message = format!("Failed to update permissions profile: {err}");
|
||||
tracing::warn!("{message}");
|
||||
sess.send_event_raw(Event {
|
||||
id: id.clone(),
|
||||
msg: EventMsg::Warning(WarningEvent { message }),
|
||||
})
|
||||
.await;
|
||||
} else {
|
||||
sess.reload_user_config_layer().await;
|
||||
if !response.permissions.is_empty() {
|
||||
let mut state = sess.state.lock().await;
|
||||
state.record_granted_permissions(response.permissions.clone().into());
|
||||
}
|
||||
}
|
||||
}
|
||||
sess.notify_request_permissions_response(&id, response)
|
||||
.await;
|
||||
}
|
||||
|
||||
@@ -202,6 +202,7 @@ async fn handle_request_permissions_uses_tool_call_id_for_round_trip() {
|
||||
}),
|
||||
..RequestPermissionProfile::default()
|
||||
},
|
||||
permissions_profile_persistence: None,
|
||||
},
|
||||
&cancel_token,
|
||||
)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use super::*;
|
||||
use crate::config::CONFIG_TOML_FILE;
|
||||
use crate::config::ConfigBuilder;
|
||||
use crate::config::test_config;
|
||||
use crate::config_loader::ConfigLayerStack;
|
||||
@@ -93,6 +94,7 @@ use codex_protocol::protocol::TurnCompleteEvent;
|
||||
use codex_protocol::protocol::TurnStartedEvent;
|
||||
use codex_protocol::protocol::UserMessageEvent;
|
||||
use codex_protocol::protocol::W3cTraceContext;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use core_test_support::PathBufExt;
|
||||
use core_test_support::context_snapshot;
|
||||
use core_test_support::context_snapshot::ContextSnapshotOptions;
|
||||
@@ -2976,6 +2978,133 @@ async fn notify_request_permissions_response_ignores_unmatched_call_id() {
|
||||
assert_eq!(session.granted_turn_permissions().await, None);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn request_permissions_response_persist_grants_session_permissions_after_successful_persist()
|
||||
{
|
||||
let (session, _turn_context) = make_session_and_context().await;
|
||||
let codex_home = session.codex_home().await;
|
||||
std::fs::create_dir_all(&codex_home).expect("create codex home");
|
||||
std::fs::write(
|
||||
codex_home.join(CONFIG_TOML_FILE),
|
||||
r#"
|
||||
default_permissions = "workspace"
|
||||
|
||||
[permissions.workspace.filesystem]
|
||||
":project_roots" = "write"
|
||||
"#,
|
||||
)
|
||||
.expect("write user config");
|
||||
session.reload_user_config_layer().await;
|
||||
|
||||
*session.active_turn.lock().await = Some(ActiveTurn::default());
|
||||
let (tx_response, rx_response) = tokio::sync::oneshot::channel();
|
||||
{
|
||||
let mut active_turn = session.active_turn.lock().await;
|
||||
let active_turn = active_turn.as_mut().expect("active turn");
|
||||
let mut turn_state = active_turn.turn_state.lock().await;
|
||||
turn_state.insert_pending_request_permissions("call-1".to_string(), tx_response);
|
||||
}
|
||||
|
||||
let session = Arc::new(session);
|
||||
let codex_home = AbsolutePathBuf::try_from(codex_home.as_path()).expect("absolute codex home");
|
||||
let permissions = RequestPermissionProfile {
|
||||
file_system: Some(codex_protocol::models::FileSystemPermissions {
|
||||
read: Some(vec![codex_home.clone()]),
|
||||
write: Some(vec![codex_home]),
|
||||
}),
|
||||
..RequestPermissionProfile::default()
|
||||
};
|
||||
let response = codex_protocol::request_permissions::RequestPermissionsResponse {
|
||||
permissions: permissions.clone(),
|
||||
scope: PermissionGrantScope::Persist {
|
||||
permission_profile_amendment:
|
||||
codex_protocol::protocol::PersistPermissionProfileAction {
|
||||
profile_name: "workspace".to_string(),
|
||||
permissions: permissions.clone().into(),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
handlers::request_permissions_response(&session, "call-1".to_string(), response.clone()).await;
|
||||
|
||||
let received_response = tokio::time::timeout(StdDuration::from_secs(1), rx_response)
|
||||
.await
|
||||
.expect("request_permissions response timed out")
|
||||
.expect("request_permissions response missing");
|
||||
assert_eq!(received_response, response);
|
||||
assert_eq!(
|
||||
session.granted_turn_permissions().await,
|
||||
Some(permissions.clone().into())
|
||||
);
|
||||
assert_eq!(
|
||||
session.granted_session_permissions().await,
|
||||
Some(permissions.into())
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn request_permissions_response_persist_rejects_unreloadable_profile_update() {
|
||||
let (session, _turn_context) = make_session_and_context().await;
|
||||
let codex_home = session.codex_home().await;
|
||||
std::fs::create_dir_all(&codex_home).expect("create codex home");
|
||||
let original_config = r#"
|
||||
default_permissions = "workspace"
|
||||
|
||||
[permissions.workspace.filesystem]
|
||||
":minimal" = "read"
|
||||
"#;
|
||||
let config_path = codex_home.join(CONFIG_TOML_FILE);
|
||||
std::fs::write(&config_path, original_config).expect("write user config");
|
||||
session.reload_user_config_layer().await;
|
||||
|
||||
*session.active_turn.lock().await = Some(ActiveTurn::default());
|
||||
let (tx_response, rx_response) = tokio::sync::oneshot::channel();
|
||||
{
|
||||
let mut active_turn = session.active_turn.lock().await;
|
||||
let active_turn = active_turn.as_mut().expect("active turn");
|
||||
let mut turn_state = active_turn.turn_state.lock().await;
|
||||
turn_state.insert_pending_request_permissions("call-1".to_string(), tx_response);
|
||||
}
|
||||
|
||||
let session = Arc::new(session);
|
||||
let codex_home_path =
|
||||
AbsolutePathBuf::try_from(codex_home.as_path()).expect("absolute codex home");
|
||||
let permissions = RequestPermissionProfile {
|
||||
file_system: Some(codex_protocol::models::FileSystemPermissions {
|
||||
read: None,
|
||||
write: Some(vec![codex_home_path]),
|
||||
}),
|
||||
..RequestPermissionProfile::default()
|
||||
};
|
||||
let response = codex_protocol::request_permissions::RequestPermissionsResponse {
|
||||
permissions: permissions.clone(),
|
||||
scope: PermissionGrantScope::Persist {
|
||||
permission_profile_amendment:
|
||||
codex_protocol::protocol::PersistPermissionProfileAction {
|
||||
profile_name: "workspace".to_string(),
|
||||
permissions: permissions.clone().into(),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
handlers::request_permissions_response(&session, "call-1".to_string(), response.clone()).await;
|
||||
|
||||
let received_response = tokio::time::timeout(StdDuration::from_secs(1), rx_response)
|
||||
.await
|
||||
.expect("request_permissions response timed out")
|
||||
.expect("request_permissions response missing");
|
||||
assert_eq!(received_response, response);
|
||||
assert_eq!(
|
||||
std::fs::read_to_string(config_path).expect("read user config"),
|
||||
original_config
|
||||
);
|
||||
assert_eq!(
|
||||
session.granted_turn_permissions().await,
|
||||
Some(permissions.into())
|
||||
);
|
||||
assert_eq!(session.granted_session_permissions().await, None);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn request_permissions_emits_event_when_granular_policy_allows_requests() {
|
||||
let (session, mut turn_context, rx) = make_session_and_context_with_rx().await;
|
||||
|
||||
@@ -997,6 +997,29 @@ pub fn apply_blocking(
|
||||
None => String::new(),
|
||||
};
|
||||
|
||||
let Some(updated) = apply_edits_to_string(&serialized, profile, edits)? else {
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
write_atomically(&write_paths.write_path, &updated).with_context(|| {
|
||||
format!(
|
||||
"failed to persist config.toml at {}",
|
||||
write_paths.write_path.display()
|
||||
)
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn apply_edits_to_string(
|
||||
serialized: &str,
|
||||
profile: Option<&str>,
|
||||
edits: &[ConfigEdit],
|
||||
) -> anyhow::Result<Option<String>> {
|
||||
if edits.is_empty() {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
let doc = if serialized.is_empty() {
|
||||
DocumentMut::new()
|
||||
} else {
|
||||
@@ -1016,18 +1039,7 @@ pub fn apply_blocking(
|
||||
mutated |= document.apply(edit)?;
|
||||
}
|
||||
|
||||
if !mutated {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
write_atomically(&write_paths.write_path, &document.doc.to_string()).with_context(|| {
|
||||
format!(
|
||||
"failed to persist config.toml at {}",
|
||||
write_paths.write_path.display()
|
||||
)
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
Ok(mutated.then(|| document.doc.to_string()))
|
||||
}
|
||||
|
||||
/// Persist edits asynchronously by offloading the blocking writer.
|
||||
|
||||
@@ -111,7 +111,9 @@ pub use codex_sandboxing::system_bwrap_warning;
|
||||
pub use managed_features::ManagedFeatures;
|
||||
pub use network_proxy_spec::NetworkProxySpec;
|
||||
pub use network_proxy_spec::StartedNetworkProxy;
|
||||
pub(crate) use permissions::persistence_target_for_permissions;
|
||||
pub(crate) use permissions::resolve_permission_profile;
|
||||
pub(crate) use permissions::validate_persist_permission_profile_action;
|
||||
pub use service::ConfigService;
|
||||
pub use service::ConfigServiceError;
|
||||
|
||||
|
||||
@@ -11,13 +11,21 @@ use codex_config::permissions_toml::PermissionsToml;
|
||||
use codex_network_proxy::NetworkProxyConfig;
|
||||
#[cfg(test)]
|
||||
use codex_network_proxy::NetworkUnixSocketPermission as ProxyNetworkUnixSocketPermission;
|
||||
use codex_protocol::models::PermissionProfile;
|
||||
use codex_protocol::permissions::FileSystemPath;
|
||||
use codex_protocol::permissions::FileSystemSandboxEntry;
|
||||
use codex_protocol::permissions::FileSystemSandboxPolicy;
|
||||
use codex_protocol::permissions::FileSystemSpecialPath;
|
||||
use codex_protocol::permissions::NetworkSandboxPolicy;
|
||||
use codex_protocol::protocol::PersistPermissionProfileAction;
|
||||
use codex_protocol::request_permissions::PermissionProfilePersistence;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
|
||||
use crate::config::Config;
|
||||
use crate::config::deserialize_config_toml_with_base;
|
||||
use crate::config::edit::ConfigEdit;
|
||||
use crate::config::edit::apply_edits_to_string;
|
||||
|
||||
pub(crate) fn network_proxy_config_from_profile_network(
|
||||
network: Option<&NetworkToml>,
|
||||
) -> NetworkProxyConfig {
|
||||
@@ -27,6 +35,98 @@ pub(crate) fn network_proxy_config_from_profile_network(
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn persistence_target_for_permissions(
|
||||
config: &Config,
|
||||
requested_permissions: &PermissionProfile,
|
||||
) -> Option<PermissionProfilePersistence> {
|
||||
if !is_supported_filesystem_only_request(requested_permissions) {
|
||||
return None;
|
||||
}
|
||||
|
||||
// TODO: honor inherited default permission profiles instead of only the raw user layer.
|
||||
let user_layer = config.config_layer_stack.get_user_layer()?;
|
||||
let user_config =
|
||||
deserialize_config_toml_with_base(user_layer.config.clone(), &config.codex_home).ok()?;
|
||||
let profile_name = user_config.default_permissions?;
|
||||
let permissions = user_config.permissions?;
|
||||
if !permissions.entries.contains_key(profile_name.as_str()) {
|
||||
return None;
|
||||
}
|
||||
|
||||
let action = PersistPermissionProfileAction {
|
||||
profile_name,
|
||||
permissions: requested_permissions.clone(),
|
||||
};
|
||||
validate_persist_permission_profile_action(config, &action)
|
||||
.ok()
|
||||
.map(|()| PermissionProfilePersistence {
|
||||
profile_name: action.profile_name,
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn validate_persist_permission_profile_action(
|
||||
config: &Config,
|
||||
action: &PersistPermissionProfileAction,
|
||||
) -> io::Result<()> {
|
||||
let user_layer = config.config_layer_stack.get_user_layer().ok_or_else(|| {
|
||||
io::Error::new(
|
||||
io::ErrorKind::InvalidInput,
|
||||
"permissions profiles can only be persisted to user config",
|
||||
)
|
||||
})?;
|
||||
let serialized_user_config = toml::to_string(&user_layer.config).map_err(invalid_data)?;
|
||||
let user_config =
|
||||
deserialize_config_toml_with_base(user_layer.config.clone(), &config.codex_home)?;
|
||||
|
||||
if user_config.default_permissions.as_deref() != Some(action.profile_name.as_str()) {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::InvalidInput,
|
||||
format!(
|
||||
"permissions profile `{}` is not the active default profile",
|
||||
action.profile_name
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
let Some(permissions) = user_config.permissions.as_ref() else {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::InvalidInput,
|
||||
"default_permissions requires a `[permissions]` table",
|
||||
));
|
||||
};
|
||||
if !permissions
|
||||
.entries
|
||||
.contains_key(action.profile_name.as_str())
|
||||
{
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::InvalidInput,
|
||||
format!(
|
||||
"default_permissions refers to undefined profile `{}`",
|
||||
action.profile_name
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
let edits = [ConfigEdit::MergePermissionProfile(action.clone())];
|
||||
let merged_config =
|
||||
apply_edits_to_string(&serialized_user_config, /*profile*/ None, &edits)
|
||||
.map_err(invalid_data)?
|
||||
.unwrap_or(serialized_user_config);
|
||||
let merged_value = toml::from_str(&merged_config).map_err(invalid_data)?;
|
||||
let merged_user_config = deserialize_config_toml_with_base(merged_value, &config.codex_home)?;
|
||||
let permissions = merged_user_config.permissions.ok_or_else(|| {
|
||||
io::Error::new(
|
||||
io::ErrorKind::InvalidInput,
|
||||
"default_permissions requires a `[permissions]` table",
|
||||
)
|
||||
})?;
|
||||
let (file_system_sandbox_policy, network_sandbox_policy) =
|
||||
compile_permission_profile(&permissions, action.profile_name.as_str(), &mut Vec::new())?;
|
||||
file_system_sandbox_policy
|
||||
.to_legacy_sandbox_policy(network_sandbox_policy, config.cwd.as_path())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn resolve_permission_profile<'a>(
|
||||
permissions: &'a PermissionsToml,
|
||||
profile_name: &str,
|
||||
@@ -115,6 +215,31 @@ fn compile_network_sandbox_policy(network: Option<&NetworkToml>) -> NetworkSandb
|
||||
}
|
||||
}
|
||||
|
||||
fn is_supported_filesystem_only_request(permissions: &PermissionProfile) -> bool {
|
||||
let Some(file_system) = permissions.file_system.as_ref() else {
|
||||
return false;
|
||||
};
|
||||
|
||||
if file_system.is_empty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
if permissions
|
||||
.network
|
||||
.as_ref()
|
||||
.and_then(|network| network.enabled)
|
||||
.unwrap_or(false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
fn invalid_data(err: impl std::fmt::Display) -> io::Error {
|
||||
io::Error::new(io::ErrorKind::InvalidData, err.to_string())
|
||||
}
|
||||
|
||||
fn compile_filesystem_permission(
|
||||
path: &str,
|
||||
permission: &FilesystemPermissionToml,
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
use super::*;
|
||||
use crate::config::CONFIG_TOML_FILE;
|
||||
use crate::config::Config;
|
||||
use crate::config::ConfigBuilder;
|
||||
use crate::config::ConfigOverrides;
|
||||
use codex_config::config_toml::ConfigToml;
|
||||
use codex_config::permissions_toml::FilesystemPermissionsToml;
|
||||
@@ -10,6 +12,9 @@ use codex_config::permissions_toml::NetworkUnixSocketPermissionToml;
|
||||
use codex_config::permissions_toml::NetworkUnixSocketPermissionsToml;
|
||||
use codex_config::permissions_toml::PermissionProfileToml;
|
||||
use codex_config::permissions_toml::PermissionsToml;
|
||||
use codex_protocol::models::FileSystemPermissions;
|
||||
use codex_protocol::models::PermissionProfile;
|
||||
use codex_protocol::request_permissions::PermissionProfilePersistence;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use pretty_assertions::assert_eq;
|
||||
use std::collections::BTreeMap;
|
||||
@@ -157,6 +162,84 @@ fn network_permission_containers_project_allowed_and_denied_entries() {
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn persistence_target_rejects_write_grant_that_cannot_reload() -> std::io::Result<()> {
|
||||
let (_temp_dir, config) = load_config_with_user_permissions(
|
||||
r#"
|
||||
default_permissions = "workspace"
|
||||
|
||||
[permissions.workspace.filesystem]
|
||||
":minimal" = "read"
|
||||
"#,
|
||||
)
|
||||
.await?;
|
||||
let path = config.cwd.join("out");
|
||||
let permissions = PermissionProfile {
|
||||
file_system: Some(FileSystemPermissions {
|
||||
read: None,
|
||||
write: Some(vec![path]),
|
||||
}),
|
||||
network: None,
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
persistence_target_for_permissions(&config, &permissions),
|
||||
None
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn persistence_target_allows_read_grant_that_can_reload() -> std::io::Result<()> {
|
||||
let (_temp_dir, config) = load_config_with_user_permissions(
|
||||
r#"
|
||||
default_permissions = "workspace"
|
||||
|
||||
[permissions.workspace.filesystem]
|
||||
":minimal" = "read"
|
||||
"#,
|
||||
)
|
||||
.await?;
|
||||
let path = config.cwd.join("out");
|
||||
let permissions = PermissionProfile {
|
||||
file_system: Some(FileSystemPermissions {
|
||||
read: Some(vec![path]),
|
||||
write: None,
|
||||
}),
|
||||
network: None,
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
persistence_target_for_permissions(&config, &permissions),
|
||||
Some(PermissionProfilePersistence {
|
||||
profile_name: "workspace".to_string()
|
||||
})
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn load_config_with_user_permissions(
|
||||
user_config: &str,
|
||||
) -> std::io::Result<(TempDir, Config)> {
|
||||
let temp_dir = TempDir::new()?;
|
||||
let codex_home = temp_dir.path().join(".codex");
|
||||
let cwd = temp_dir.path().join("workspace");
|
||||
std::fs::create_dir_all(&codex_home)?;
|
||||
std::fs::create_dir_all(&cwd)?;
|
||||
std::fs::write(codex_home.join(CONFIG_TOML_FILE), user_config)?;
|
||||
|
||||
let config = ConfigBuilder::without_managed_config_for_tests()
|
||||
.codex_home(codex_home)
|
||||
.harness_overrides(ConfigOverrides {
|
||||
cwd: Some(cwd),
|
||||
..Default::default()
|
||||
})
|
||||
.build()
|
||||
.await?;
|
||||
|
||||
Ok((temp_dir, config))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn network_toml_overlays_unix_socket_permissions_by_path() {
|
||||
let mut config = NetworkProxyConfig::default();
|
||||
|
||||
@@ -619,6 +619,9 @@ impl TestCodexBuilder {
|
||||
config.codex_self_exe = Some(codex_exec);
|
||||
}
|
||||
}
|
||||
if let Some(path) = find_codex_cli_exe() {
|
||||
config.codex_linux_sandbox_exe = Some(path);
|
||||
}
|
||||
|
||||
let mut mutators = vec![];
|
||||
swap(&mut self.config_mutators, &mut mutators);
|
||||
@@ -637,6 +640,20 @@ impl TestCodexBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
fn find_codex_cli_exe() -> Option<PathBuf> {
|
||||
codex_utils_cargo_bin::cargo_bin("codex")
|
||||
.ok()
|
||||
.filter(|path| path.file_stem().is_some_and(|stem| stem == "codex"))
|
||||
.or_else(|| {
|
||||
std::env::current_exe().ok().and_then(|exe| {
|
||||
exe.parent()
|
||||
.and_then(|parent| parent.parent())
|
||||
.map(|parent| parent.join(format!("codex{}", std::env::consts::EXE_SUFFIX)))
|
||||
.filter(|path| path.is_file())
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn ensure_test_model_catalog(config: &mut Config) -> Result<()> {
|
||||
if config.model.as_deref() != Some(TEST_MODEL_WITH_EXPERIMENTAL_TOOLS)
|
||||
|| config.model_catalog.is_some()
|
||||
|
||||
@@ -1,17 +1,28 @@
|
||||
use crate::models::FileSystemPermissions;
|
||||
use crate::models::NetworkPermissions;
|
||||
use crate::models::PermissionProfile;
|
||||
use crate::protocol::PersistPermissionProfileAction;
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use ts_rs::TS;
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default, Deserialize, Serialize, PartialEq, Eq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, JsonSchema, TS)]
|
||||
#[serde(tag = "type", rename_all = "snake_case")]
|
||||
#[ts(tag = "type")]
|
||||
#[derive(Default)]
|
||||
pub enum PermissionGrantScope {
|
||||
#[default]
|
||||
Turn,
|
||||
Session,
|
||||
Persist {
|
||||
permission_profile_amendment: PersistPermissionProfileAction,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, JsonSchema, TS)]
|
||||
pub struct PermissionProfilePersistence {
|
||||
pub profile_name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Deserialize, Serialize, PartialEq, Eq, JsonSchema, TS)]
|
||||
@@ -70,4 +81,7 @@ pub struct RequestPermissionsEvent {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub reason: Option<String>,
|
||||
pub permissions: RequestPermissionProfile,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub permissions_profile_persistence: Option<PermissionProfilePersistence>,
|
||||
}
|
||||
|
||||
@@ -1839,6 +1839,10 @@ impl App {
|
||||
call_id: params.item_id.clone(),
|
||||
reason: params.reason.clone(),
|
||||
permissions: params.permissions.clone().into(),
|
||||
permissions_profile_persistence: params
|
||||
.permissions_profile_persistence
|
||||
.clone()
|
||||
.map(Into::into),
|
||||
}),
|
||||
),
|
||||
_ => None,
|
||||
@@ -8664,6 +8668,7 @@ guardian_approval = true
|
||||
write: Some(vec![test_absolute_path("/tmp/write")]),
|
||||
}),
|
||||
},
|
||||
permissions_profile_persistence: None,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -156,7 +156,7 @@ impl PendingAppServerRequests {
|
||||
permissions: granted_permission_profile_from_request(
|
||||
response.permissions.clone(),
|
||||
),
|
||||
scope: response.scope.into(),
|
||||
scope: response.scope.clone().into(),
|
||||
})
|
||||
.map_err(|err| {
|
||||
format!("failed to serialize permissions approval response: {err}")
|
||||
@@ -363,6 +363,7 @@ mod tests {
|
||||
turn_id: "turn-1".to_string(),
|
||||
item_id: "perm-1".to_string(),
|
||||
reason: None,
|
||||
permissions_profile_persistence: None,
|
||||
permissions: serde_json::from_value(json!({
|
||||
"network": { "enabled": null }
|
||||
}))
|
||||
|
||||
@@ -376,7 +376,7 @@ impl AppCommand {
|
||||
Op::UserInputAnswer { id, response } => {
|
||||
AppCommandView::UserInputAnswer { id, response }
|
||||
}
|
||||
Op::RequestPermissionsResponse { id, response } => {
|
||||
Op::RequestPermissionsResponse { id, response, .. } => {
|
||||
AppCommandView::RequestPermissionsResponse { id, response }
|
||||
}
|
||||
Op::ReloadUserConfig => AppCommandView::ReloadUserConfig,
|
||||
|
||||
@@ -26,8 +26,10 @@ use codex_protocol::protocol::NetworkApprovalContext;
|
||||
use codex_protocol::protocol::NetworkPolicyRuleAction;
|
||||
#[cfg(test)]
|
||||
use codex_protocol::protocol::Op;
|
||||
use codex_protocol::protocol::PersistPermissionProfileAction;
|
||||
use codex_protocol::protocol::ReviewDecision;
|
||||
use codex_protocol::request_permissions::PermissionGrantScope;
|
||||
use codex_protocol::request_permissions::PermissionProfilePersistence;
|
||||
use codex_protocol::request_permissions::RequestPermissionProfile;
|
||||
use crossterm::event::KeyCode;
|
||||
use crossterm::event::KeyEvent;
|
||||
@@ -60,6 +62,7 @@ pub(crate) enum ApprovalRequest {
|
||||
call_id: String,
|
||||
reason: Option<String>,
|
||||
permissions: RequestPermissionProfile,
|
||||
permissions_profile_persistence: Option<PermissionProfilePersistence>,
|
||||
},
|
||||
ApplyPatch {
|
||||
thread_id: ThreadId,
|
||||
@@ -166,8 +169,12 @@ impl ApprovalOverlay {
|
||||
},
|
||||
),
|
||||
),
|
||||
ApprovalRequest::Permissions { .. } => (
|
||||
permissions_options(),
|
||||
ApprovalRequest::Permissions {
|
||||
permissions,
|
||||
permissions_profile_persistence,
|
||||
..
|
||||
} => (
|
||||
permissions_options(permissions, permissions_profile_persistence.as_ref()),
|
||||
"Would you like to grant these permissions?".to_string(),
|
||||
),
|
||||
ApprovalRequest::ApplyPatch { .. } => (
|
||||
@@ -228,6 +235,18 @@ impl ApprovalOverlay {
|
||||
},
|
||||
ApprovalDecision::Review(decision),
|
||||
) => self.handle_permissions_decision(call_id, permissions, decision.clone()),
|
||||
(
|
||||
ApprovalRequest::Permissions {
|
||||
call_id,
|
||||
permissions,
|
||||
..
|
||||
},
|
||||
ApprovalDecision::PersistPermissions(permission_profile_amendment),
|
||||
) => self.handle_persist_permissions_decision(
|
||||
call_id,
|
||||
permissions,
|
||||
permission_profile_amendment.clone(),
|
||||
),
|
||||
(ApprovalRequest::ApplyPatch { id, .. }, ApprovalDecision::Review(decision)) => {
|
||||
self.handle_patch_decision(id, decision.clone());
|
||||
}
|
||||
@@ -281,15 +300,18 @@ impl ApprovalOverlay {
|
||||
ReviewDecision::ApprovedExecpolicyAmendment { .. }
|
||||
| ReviewDecision::NetworkPolicyAmendment { .. } => Default::default(),
|
||||
};
|
||||
let scope = if matches!(decision, ReviewDecision::ApprovedForSession) {
|
||||
PermissionGrantScope::Session
|
||||
} else {
|
||||
PermissionGrantScope::Turn
|
||||
let scope = match &decision {
|
||||
ReviewDecision::ApprovedForSession => PermissionGrantScope::Session,
|
||||
ReviewDecision::Approved
|
||||
| ReviewDecision::Denied
|
||||
| ReviewDecision::Abort
|
||||
| ReviewDecision::ApprovedExecpolicyAmendment { .. }
|
||||
| ReviewDecision::NetworkPolicyAmendment { .. } => PermissionGrantScope::Turn,
|
||||
};
|
||||
if request.thread_label().is_none() {
|
||||
let message = if granted_permissions.is_empty() {
|
||||
"You did not grant additional permissions"
|
||||
} else if matches!(scope, PermissionGrantScope::Session) {
|
||||
} else if matches!(&scope, PermissionGrantScope::Session) {
|
||||
"You granted additional permissions for this session"
|
||||
} else {
|
||||
"You granted additional permissions"
|
||||
@@ -309,6 +331,36 @@ impl ApprovalOverlay {
|
||||
);
|
||||
}
|
||||
|
||||
fn handle_persist_permissions_decision(
|
||||
&self,
|
||||
call_id: &str,
|
||||
permissions: &RequestPermissionProfile,
|
||||
permission_profile_amendment: PersistPermissionProfileAction,
|
||||
) {
|
||||
let Some(request) = self.current_request.as_ref() else {
|
||||
return;
|
||||
};
|
||||
if request.thread_label().is_none() {
|
||||
self.app_event_tx.send(AppEvent::InsertHistoryCell(Box::new(
|
||||
crate::history_cell::PlainHistoryCell::new(vec![
|
||||
"You granted additional permissions and saved them to your permissions profile"
|
||||
.into(),
|
||||
]),
|
||||
)));
|
||||
}
|
||||
let thread_id = request.thread_id();
|
||||
self.app_event_tx.request_permissions_response(
|
||||
thread_id,
|
||||
call_id.to_string(),
|
||||
codex_protocol::request_permissions::RequestPermissionsResponse {
|
||||
permissions: permissions.clone(),
|
||||
scope: PermissionGrantScope::Persist {
|
||||
permission_profile_amendment,
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
fn handle_patch_decision(&self, id: &str, decision: ReviewDecision) {
|
||||
let Some(thread_id) = self
|
||||
.current_request
|
||||
@@ -621,6 +673,7 @@ fn build_header(request: &ApprovalRequest) -> Box<dyn Renderable> {
|
||||
#[derive(Clone)]
|
||||
enum ApprovalDecision {
|
||||
Review(ReviewDecision),
|
||||
PersistPermissions(PersistPermissionProfileAction),
|
||||
McpElicitation(ElicitationAction),
|
||||
}
|
||||
|
||||
@@ -796,8 +849,11 @@ fn patch_options() -> Vec<ApprovalOption> {
|
||||
]
|
||||
}
|
||||
|
||||
fn permissions_options() -> Vec<ApprovalOption> {
|
||||
vec![
|
||||
fn permissions_options(
|
||||
permissions: &RequestPermissionProfile,
|
||||
permissions_profile_persistence: Option<&PermissionProfilePersistence>,
|
||||
) -> Vec<ApprovalOption> {
|
||||
let mut options = vec![
|
||||
ApprovalOption {
|
||||
label: "Yes, grant these permissions".to_string(),
|
||||
decision: ApprovalDecision::Review(ReviewDecision::Approved),
|
||||
@@ -816,7 +872,32 @@ fn permissions_options() -> Vec<ApprovalOption> {
|
||||
display_shortcut: None,
|
||||
additional_shortcuts: vec![key_hint::plain(KeyCode::Char('n'))],
|
||||
},
|
||||
]
|
||||
];
|
||||
if let Some(decision) =
|
||||
permission_profile_amendment_decision(permissions, permissions_profile_persistence)
|
||||
{
|
||||
options.insert(
|
||||
1,
|
||||
ApprovalOption {
|
||||
label: "Yes, always allow these permissions".to_string(),
|
||||
decision: ApprovalDecision::PersistPermissions(decision),
|
||||
display_shortcut: None,
|
||||
additional_shortcuts: vec![key_hint::plain(KeyCode::Char('p'))],
|
||||
},
|
||||
);
|
||||
}
|
||||
options
|
||||
}
|
||||
|
||||
fn permission_profile_amendment_decision(
|
||||
permissions: &RequestPermissionProfile,
|
||||
permissions_profile_persistence: Option<&PermissionProfilePersistence>,
|
||||
) -> Option<PersistPermissionProfileAction> {
|
||||
let profile_name = permissions_profile_persistence?.profile_name.clone();
|
||||
Some(PersistPermissionProfileAction {
|
||||
profile_name,
|
||||
permissions: permissions.clone().into(),
|
||||
})
|
||||
}
|
||||
|
||||
fn elicitation_options() -> Vec<ApprovalOption> {
|
||||
@@ -915,6 +996,31 @@ mod tests {
|
||||
write: Some(vec![absolute_path("/tmp/out.txt")]),
|
||||
}),
|
||||
},
|
||||
permissions_profile_persistence: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn make_persistable_permissions_request() -> ApprovalRequest {
|
||||
let ApprovalRequest::Permissions {
|
||||
thread_id,
|
||||
thread_label,
|
||||
call_id,
|
||||
reason,
|
||||
permissions,
|
||||
..
|
||||
} = make_permissions_request()
|
||||
else {
|
||||
unreachable!("permissions request");
|
||||
};
|
||||
ApprovalRequest::Permissions {
|
||||
thread_id,
|
||||
thread_label,
|
||||
call_id,
|
||||
reason,
|
||||
permissions,
|
||||
permissions_profile_persistence: Some(PermissionProfilePersistence {
|
||||
profile_name: "workspace".to_string(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1214,10 +1320,19 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn permissions_options_use_expected_labels() {
|
||||
let labels: Vec<String> = permissions_options()
|
||||
.into_iter()
|
||||
.map(|option| option.label)
|
||||
.collect();
|
||||
let ApprovalRequest::Permissions {
|
||||
permissions,
|
||||
permissions_profile_persistence,
|
||||
..
|
||||
} = make_permissions_request()
|
||||
else {
|
||||
unreachable!("permissions request");
|
||||
};
|
||||
let labels: Vec<String> =
|
||||
permissions_options(&permissions, permissions_profile_persistence.as_ref())
|
||||
.into_iter()
|
||||
.map(|option| option.label)
|
||||
.collect();
|
||||
assert_eq!(
|
||||
labels,
|
||||
vec![
|
||||
@@ -1255,6 +1370,59 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn permissions_persist_shortcut_submits_persist_scope() {
|
||||
let (tx, mut rx) = unbounded_channel::<AppEvent>();
|
||||
let tx = AppEventSender::new(tx);
|
||||
let mut view = ApprovalOverlay::new(
|
||||
make_persistable_permissions_request(),
|
||||
tx,
|
||||
Features::with_defaults(),
|
||||
);
|
||||
|
||||
view.handle_key_event(KeyEvent::new(KeyCode::Char('p'), KeyModifiers::NONE));
|
||||
|
||||
let mut saw_history = false;
|
||||
let mut saw_op = false;
|
||||
while let Ok(ev) = rx.try_recv() {
|
||||
match ev {
|
||||
AppEvent::InsertHistoryCell(cell) => {
|
||||
assert_eq!(
|
||||
cell.display_lines(/*width*/ 120),
|
||||
vec![Line::from(
|
||||
"You granted additional permissions and saved them to your permissions profile"
|
||||
)]
|
||||
);
|
||||
saw_history = true;
|
||||
}
|
||||
AppEvent::SubmitThreadOp {
|
||||
op: Op::RequestPermissionsResponse { response, .. },
|
||||
..
|
||||
} => {
|
||||
let ApprovalRequest::Permissions {
|
||||
permissions: expected_permissions,
|
||||
..
|
||||
} = make_permissions_request()
|
||||
else {
|
||||
unreachable!("permissions request");
|
||||
};
|
||||
assert_eq!(response.permissions, expected_permissions);
|
||||
assert!(matches!(
|
||||
response.scope,
|
||||
PermissionGrantScope::Persist { .. }
|
||||
));
|
||||
saw_op = true;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
assert!(saw_history, "expected permission approval history cell");
|
||||
assert!(
|
||||
saw_op,
|
||||
"expected permission approval decision to emit a persisted response"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn additional_permissions_prompt_shows_permission_rule_line() {
|
||||
let (tx, _rx) = unbounded_channel::<AppEvent>();
|
||||
@@ -1346,6 +1514,20 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn persistable_permissions_prompt_snapshot() {
|
||||
let view = ApprovalOverlay::new(
|
||||
make_persistable_permissions_request(),
|
||||
AppEventSender::new(unbounded_channel::<AppEvent>().0),
|
||||
Features::with_defaults(),
|
||||
);
|
||||
|
||||
assert_snapshot!(
|
||||
"approval_overlay_persistable_permissions_prompt",
|
||||
normalize_snapshot_paths(render_overlay_lines(&view, /*width*/ 72))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn network_exec_prompt_title_includes_host() {
|
||||
let (tx, _rx) = unbounded_channel::<AppEvent>();
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
---
|
||||
source: tui/src/bottom_pane/approval_overlay.rs
|
||||
expression: "normalize_snapshot_paths(render_overlay_lines(&view, 60))"
|
||||
---
|
||||
|
||||
Would you like to grant these permissions?
|
||||
|
||||
Reason: need workspace access
|
||||
|
||||
Permission rule: network; read `/tmp/readme.txt`; write
|
||||
`/tmp/out.txt`
|
||||
|
||||
› 1. Yes, grant these permissions (y)
|
||||
2. Yes, always allow these permissions (p)
|
||||
3. Yes, grant these permissions for this session (a)
|
||||
4. No, continue without permissions (n)
|
||||
|
||||
Press enter to confirm or esc to cancel
|
||||
@@ -1564,6 +1564,7 @@ fn request_permissions_from_params(
|
||||
call_id: params.item_id,
|
||||
reason: params.reason,
|
||||
permissions: params.permissions.into(),
|
||||
permissions_profile_persistence: params.permissions_profile_persistence.map(Into::into),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4570,6 +4571,7 @@ impl ChatWidget {
|
||||
call_id: ev.call_id,
|
||||
reason: ev.reason,
|
||||
permissions: ev.permissions,
|
||||
permissions_profile_persistence: ev.permissions_profile_persistence,
|
||||
};
|
||||
self.bottom_pane
|
||||
.push_approval_request(request, &self.config.features);
|
||||
|
||||
@@ -160,6 +160,7 @@ fn app_server_request_permissions_preserves_file_system_permissions() {
|
||||
write: Some(vec![write_path.clone()]),
|
||||
}),
|
||||
},
|
||||
permissions_profile_persistence: None,
|
||||
});
|
||||
|
||||
assert_eq!(
|
||||
|
||||
Reference in New Issue
Block a user