mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
9de568372d
## Stack 1. #25850 - Key request-permission grants by environment: stores and applies sticky permission grants per environment id. 2. #25858 - Add `environmentId` to `request_permissions`: lets the model target a selected environment and resolves relative permission paths against it. 3. This PR (#25862) - Propagate permission approval environment id: carries the selected environment id through approval events, app-server requests, TUI prompts, and delegate forwarding. 4. #25867 - Add remote request permissions integration coverage: verifies the selected remote environment across request, approval, grant reuse, and exec. This PR is stacked on #25858, and #25867 is stacked on this PR. ## Why PR2 lets the model bind a `request_permissions` call to a selected environment, but the approval event and client-facing request still needed to carry that binding. For CCA, the user-facing prompt and delegated approval path should know which environment the grant applies to instead of relying on cwd alone. ## What Changed - Added optional `environmentId` to `RequestPermissionsEvent`. - Emit the selected environment id from core permission approval events. - Preserve the environment id through delegate forwarding, including cwd-based delegated requests. - Added `environmentId` to app-server permission approval params, generated schema/TypeScript artifacts, and README examples. - Preserve and display the environment id in TUI permission approval prompts. - Updated focused core, app-server protocol, and TUI conversion coverage. ## Testing Not run locally per instruction. Performed read-only `git diff --check`.
100 lines
3.1 KiB
Rust
100 lines
3.1 KiB
Rust
use crate::models::AdditionalPermissionProfile;
|
|
use crate::models::FileSystemPermissions;
|
|
use crate::models::NetworkPermissions;
|
|
use codex_utils_absolute_path::AbsolutePathBuf;
|
|
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")]
|
|
pub enum PermissionGrantScope {
|
|
#[default]
|
|
Turn,
|
|
Session,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Default, Deserialize, Serialize, PartialEq, Eq, JsonSchema, TS)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct RequestPermissionProfile {
|
|
pub network: Option<NetworkPermissions>,
|
|
pub file_system: Option<FileSystemPermissions>,
|
|
}
|
|
|
|
impl RequestPermissionProfile {
|
|
pub fn is_empty(&self) -> bool {
|
|
self.network.is_none() && self.file_system.is_none()
|
|
}
|
|
}
|
|
|
|
impl From<RequestPermissionProfile> for AdditionalPermissionProfile {
|
|
fn from(value: RequestPermissionProfile) -> Self {
|
|
Self {
|
|
network: value.network,
|
|
file_system: value.file_system,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<AdditionalPermissionProfile> for RequestPermissionProfile {
|
|
fn from(value: AdditionalPermissionProfile) -> Self {
|
|
Self {
|
|
network: value.network,
|
|
file_system: value.file_system,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, JsonSchema, TS)]
|
|
pub struct RequestPermissionsArgs {
|
|
#[serde(
|
|
default,
|
|
rename = "environment_id",
|
|
alias = "environmentId",
|
|
skip_serializing_if = "Option::is_none"
|
|
)]
|
|
#[ts(optional)]
|
|
pub environment_id: Option<String>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub reason: Option<String>,
|
|
pub permissions: RequestPermissionProfile,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, JsonSchema, TS)]
|
|
pub struct RequestPermissionsResponse {
|
|
pub permissions: RequestPermissionProfile,
|
|
#[serde(default)]
|
|
pub scope: PermissionGrantScope,
|
|
/// Review every subsequent command in this turn before normal sandboxed execution.
|
|
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
|
pub strict_auto_review: bool,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, JsonSchema, TS)]
|
|
pub struct RequestPermissionsEvent {
|
|
/// Responses API call id for the associated tool call, if available.
|
|
pub call_id: String,
|
|
/// Turn ID that this request belongs to.
|
|
/// Uses `#[serde(default)]` for backwards compatibility.
|
|
#[serde(default)]
|
|
pub turn_id: String,
|
|
#[serde(
|
|
default,
|
|
rename = "environmentId",
|
|
alias = "environment_id",
|
|
skip_serializing_if = "Option::is_none"
|
|
)]
|
|
#[ts(optional)]
|
|
#[ts(rename = "environmentId")]
|
|
pub environment_id: Option<String>,
|
|
#[ts(type = "number")]
|
|
pub started_at_ms: i64,
|
|
#[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 cwd: Option<AbsolutePathBuf>,
|
|
}
|