Lightweight coding agent that runs in your terminal
Rust
updating app server types to support execpoilcy amendment (#7747)
zhao-oai0a32acaa2deb
diff --git a/codex-rs/app-server-protocol/src/protocol/v2.rs b/codex-rs/app-server-protocol/src/protocol/v2.rsindex 35d7047661..ea70b805b0 100644--- a/codex-rs/app-server-protocol/src/protocol/v2.rs+++ b/codex-rs/app-server-protocol/src/protocol/v2.rs@@ -3,6 +3,7 @@ use std::path::PathBuf;use crate::protocol::common::AuthMode;use codex_protocol::account::PlanType;+use codex_protocol::approvals::ExecPolicyAmendment as CoreExecPolicyAmendment;use codex_protocol::approvals::SandboxCommandAssessment as CoreSandboxCommandAssessment;use codex_protocol::config_types::ReasoningSummary;use codex_protocol::items::AgentMessageContent as CoreAgentMessageContent;@@ -287,6 +288,11 @@ v2_enum_from_core!(#[ts(export_to = "v2/")]pub enum ApprovalDecision {Accept,+ /// Approve and remember the approval for the session.+ AcceptForSession,+ AcceptWithExecpolicyAmendment {+ execpolicy_amendment: ExecPolicyAmendment,+ },Decline,Cancel,}@@ -382,6 +388,27 @@ impl From<CoreSandboxCommandAssessment> for SandboxCommandAssessment {}}+#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]+#[serde(transparent)]+#[ts(type = "Array<string>", export_to = "v2/")]+pub struct ExecPolicyAmendment {+ pub command: Vec<String>,+}++impl ExecPolicyAmendment {+ pub fn into_core(self) -> CoreExecPolicyAmendment {+ CoreExecPolicyAmendment::new(self.command)+ }+}++impl From<CoreExecPolicyAmendment> for ExecPolicyAmendment {+ fn from(value: CoreExecPolicyAmendment) -> Self {+ Self {+ command: value.command().to_vec(),+ }+ }+}+#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]#[serde(tag = "type", rename_all = "camelCase")]#[ts(tag = "type")]@@ -1468,15 +1495,8 @@ pub struct CommandExecutionRequestApprovalParams {pub reason: Option<String>,/// Optional model-provided risk assessment describing the blocked command.pub risk: Option<SandboxCommandAssessment>,-}--#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]-#[serde(rename_all = "camelCase")]-#[ts(export_to = "v2/")]-pub struct CommandExecutionRequestAcceptSettings {- /// If true, automatically approve this command for the duration of the session.- #[serde(default)]- pub for_session: bool,+ /// Optional proposed execpolicy amendment to allow similar commands without prompting.+ pub proposed_execpolicy_amendment: Option<ExecPolicyAmendment>,}#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]@@ -1484,10 +1504,6 @@ pub struct CommandExecutionRequestAcceptSettings {#[ts(export_to = "v2/")]pub struct CommandExecutionRequestApprovalResponse {pub decision: ApprovalDecision,- /// Optional approval settings for when the decision is `accept`.- /// Ignored if the decision is `decline` or `cancel`.- #[serde(default)]- pub accept_settings: Option<CommandExecutionRequestAcceptSettings>,}#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]diff --git a/codex-rs/app-server-test-client/src/main.rs b/codex-rs/app-server-test-client/src/main.rsindex 8c2a38e46c..92255cecd3 100644--- a/codex-rs/app-server-test-client/src/main.rs+++ b/codex-rs/app-server-test-client/src/main.rs@@ -21,7 +21,6 @@ use codex_app_server_protocol::ApprovalDecision;use codex_app_server_protocol::AskForApproval;use codex_app_server_protocol::ClientInfo;use codex_app_server_protocol::ClientRequest;-use codex_app_server_protocol::CommandExecutionRequestAcceptSettings;use codex_app_server_protocol::CommandExecutionRequestApprovalParams;use codex_app_server_protocol::CommandExecutionRequestApprovalResponse;use codex_app_server_protocol::FileChangeRequestApprovalParams;@@ -754,6 +753,7 @@ impl CodexClient {item_id,reason,risk,+ proposed_execpolicy_amendment,} = params;println!(@@ -765,10 +765,12 @@ impl CodexClient {if let Some(risk) = risk.as_ref() {println!("< risk assessment: {risk:?}");}+ if let Some(execpolicy_amendment) = proposed_execpolicy_amendment.as_ref() {+ println!("< proposed execpolicy amendment: {execpolicy_amendment:?}");+ }let response = CommandExecutionRequestApprovalResponse {decision: ApprovalDecision::Accept,- accept_settings: Some(CommandExecutionRequestAcceptSettings { for_session: false }),};self.send_server_request_response(request_id, &response)?;println!("< approved commandExecution request for item {item_id}");diff --git a/codex-rs/app-server/src/bespoke_event_handling.rs b/codex-rs/app-server/src/bespoke_event_handling.rsindex 94676999b5..2fda7bcf58 100644--- a/codex-rs/app-server/src/bespoke_event_handling.rs+++ b/codex-rs/app-server/src/bespoke_event_handling.rs@@ -18,6 +18,7 @@ use codex_app_server_protocol::ContextCompactedNotification;use codex_app_server_protocol::ErrorNotification;use codex_app_server_protocol::ExecCommandApprovalParams;use codex_app_server_protocol::ExecCommandApprovalResponse;+use codex_app_server_protocol::ExecPolicyAmendment as V2ExecPolicyAmendment;use codex_app_server_protocol::FileChangeOutputDeltaNotification;use codex_app_server_protocol::FileChangeRequestApprovalParams;use codex_app_server_protocol::FileChangeRequestApprovalResponse;@@ -179,7 +180,7 @@ pub(crate) async fn apply_bespoke_event_handling(cwd,reason,risk,- proposed_execpolicy_amendment: _,+ proposed_execpolicy_amendment,parsed_cmd,}) => match api_version {ApiVersion::V1 => {@@ -207,6 +208,8 @@ pub(crate) async fn apply_bespoke_event_handling(.map(V2ParsedCommand::from).collect::<Vec<_>>();let command_string = shlex_join(&command);+ let proposed_execpolicy_amendment_v2 =+ proposed_execpolicy_amendment.map(V2ExecPolicyAmendment::from);let params = CommandExecutionRequestApprovalParams {thread_id: conversation_id.to_string(),@@ -216,6 +219,7 @@ pub(crate) async fn apply_bespoke_event_handling(item_id: item_id.clone(),reason,risk: risk.map(V2SandboxCommandAssessment::from),+ proposed_execpolicy_amendment: proposed_execpolicy_amendment_v2,};let rx = outgoing.send_request(ServerRequestPayload::CommandExecutionRequestApproval(@@ -1047,7 +1051,11 @@ async fn on_file_change_request_approval_response(});let (decision, completion_status) = match response.decision {- ApprovalDecision::Accept => (ReviewDecision::Approved, None),+ ApprovalDecision::Accept+ | ApprovalDecision::AcceptForSession+ | ApprovalDecision::AcceptWithExecpolicyAmendment { .. } => {+ (ReviewDecision::Approved, None)+ }ApprovalDecision::Decline => {(ReviewDecision::Denied, Some(PatchApplyStatus::Declined))}@@ -1109,25 +1117,27 @@ async fn on_command_execution_request_approval_response(error!("failed to deserialize CommandExecutionRequestApprovalResponse: {err}");CommandExecutionRequestApprovalResponse {decision: ApprovalDecision::Decline,- accept_settings: None,}});- let CommandExecutionRequestApprovalResponse {- decision,- accept_settings,- } = response;+ let decision = response.decision;- let (decision, completion_status) = match (decision, accept_settings) {- (ApprovalDecision::Accept, Some(settings)) if settings.for_session => {- (ReviewDecision::ApprovedForSession, None)- }- (ApprovalDecision::Accept, _) => (ReviewDecision::Approved, None),- (ApprovalDecision::Decline, _) => (+ let (decision, completion_status) = match decision {+ ApprovalDecision::Accept => (ReviewDecision::Approved, None),+ ApprovalDecision::AcceptForSession => (ReviewDecision::ApprovedForSession, None),+ ApprovalDecision::AcceptWithExecpolicyAmendment {+ execpolicy_amendment,+ } => (+ ReviewDecision::ApprovedExecpolicyAmendment {+ proposed_execpolicy_amendment: execpolicy_amendment.into_core(),+ },+ None,+ ),+ ApprovalDecision::Decline => (ReviewDecision::Denied,Some(CommandExecutionStatus::Declined),),- (ApprovalDecision::Cancel, _) => (+ ApprovalDecision::Cancel => (ReviewDecision::Abort,Some(CommandExecutionStatus::Declined),),diff --git a/codex-rs/app-server/tests/suite/v2/turn_start.rs b/codex-rs/app-server/tests/suite/v2/turn_start.rsindex e4cd722947..afc22c7072 100644--- a/codex-rs/app-server/tests/suite/v2/turn_start.rs+++ b/codex-rs/app-server/tests/suite/v2/turn_start.rs@@ -427,7 +427,6 @@ async fn turn_start_exec_approval_decline_v2() -> Result<()> {request_id,serde_json::to_value(CommandExecutionRequestApprovalResponse {decision: ApprovalDecision::Decline,- accept_settings: None,})?,).await?;