Skip to content

Commit 5600af9

Browse files
committed
ApprovalDecision -> CommandExecutionApprovalDecision + FileChangeApprovalDecision
1 parent 1c63e83 commit 5600af9

File tree

3 files changed

+41
-23
lines changed

3 files changed

+41
-23
lines changed

codex-rs/app-server-protocol/src/protocol/v2.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ pub struct ConfigEdit {
475475
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
476476
#[serde(rename_all = "camelCase")]
477477
#[ts(export_to = "v2/")]
478-
pub enum ApprovalDecision {
478+
pub enum CommandExecutionApprovalDecision {
479479
Accept,
480480
/// Approve and remember the approval for the session.
481481
AcceptForSession,
@@ -486,6 +486,17 @@ pub enum ApprovalDecision {
486486
Cancel,
487487
}
488488

489+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
490+
#[serde(rename_all = "camelCase")]
491+
#[ts(export_to = "v2/")]
492+
pub enum FileChangeApprovalDecision {
493+
Accept,
494+
/// Approve and remember the approval for the session.
495+
AcceptForSession,
496+
Decline,
497+
Cancel,
498+
}
499+
489500
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, Eq, JsonSchema, TS)]
490501
#[serde(rename_all = "camelCase")]
491502
#[ts(export_to = "v2/")]
@@ -1848,7 +1859,7 @@ pub struct CommandExecutionRequestApprovalParams {
18481859
#[serde(rename_all = "camelCase")]
18491860
#[ts(export_to = "v2/")]
18501861
pub struct CommandExecutionRequestApprovalResponse {
1851-
pub decision: ApprovalDecision,
1862+
pub decision: CommandExecutionApprovalDecision,
18521863
}
18531864

18541865
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
@@ -1868,7 +1879,7 @@ pub struct FileChangeRequestApprovalParams {
18681879
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
18691880
#[ts(export_to = "v2/")]
18701881
pub struct FileChangeRequestApprovalResponse {
1871-
pub decision: ApprovalDecision,
1882+
pub decision: FileChangeApprovalDecision,
18721883
}
18731884

18741885
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]

codex-rs/app-server/src/bespoke_event_handling.rs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ use codex_app_server_protocol::AccountRateLimitsUpdatedNotification;
77
use codex_app_server_protocol::AgentMessageDeltaNotification;
88
use codex_app_server_protocol::ApplyPatchApprovalParams;
99
use codex_app_server_protocol::ApplyPatchApprovalResponse;
10-
use codex_app_server_protocol::ApprovalDecision;
1110
use codex_app_server_protocol::CodexErrorInfo as V2CodexErrorInfo;
1211
use codex_app_server_protocol::CommandAction as V2ParsedCommand;
12+
use codex_app_server_protocol::CommandExecutionApprovalDecision;
1313
use codex_app_server_protocol::CommandExecutionOutputDeltaNotification;
1414
use codex_app_server_protocol::CommandExecutionRequestApprovalParams;
1515
use codex_app_server_protocol::CommandExecutionRequestApprovalResponse;
@@ -20,6 +20,7 @@ use codex_app_server_protocol::ErrorNotification;
2020
use codex_app_server_protocol::ExecCommandApprovalParams;
2121
use codex_app_server_protocol::ExecCommandApprovalResponse;
2222
use codex_app_server_protocol::ExecPolicyAmendment as V2ExecPolicyAmendment;
23+
use codex_app_server_protocol::FileChangeApprovalDecision;
2324
use codex_app_server_protocol::FileChangeOutputDeltaNotification;
2425
use codex_app_server_protocol::FileChangeRequestApprovalParams;
2526
use codex_app_server_protocol::FileChangeRequestApprovalResponse;
@@ -1084,14 +1085,17 @@ fn format_file_change_diff(change: &CoreFileChange) -> String {
10841085
}
10851086

10861087
fn map_file_change_approval_decision(
1087-
decision: ApprovalDecision,
1088+
decision: FileChangeApprovalDecision,
10881089
) -> (ReviewDecision, Option<PatchApplyStatus>) {
10891090
match decision {
1090-
ApprovalDecision::Accept => (ReviewDecision::Approved, None),
1091-
ApprovalDecision::AcceptForSession => (ReviewDecision::ApprovedForSession, None),
1092-
ApprovalDecision::AcceptWithExecpolicyAmendment { .. } => (ReviewDecision::Approved, None),
1093-
ApprovalDecision::Decline => (ReviewDecision::Denied, Some(PatchApplyStatus::Declined)),
1094-
ApprovalDecision::Cancel => (ReviewDecision::Abort, Some(PatchApplyStatus::Declined)),
1091+
FileChangeApprovalDecision::Accept => (ReviewDecision::Approved, None),
1092+
FileChangeApprovalDecision::AcceptForSession => (ReviewDecision::ApprovedForSession, None),
1093+
FileChangeApprovalDecision::Decline => {
1094+
(ReviewDecision::Denied, Some(PatchApplyStatus::Declined))
1095+
}
1096+
FileChangeApprovalDecision::Cancel => {
1097+
(ReviewDecision::Abort, Some(PatchApplyStatus::Declined))
1098+
}
10951099
}
10961100
}
10971101

@@ -1113,7 +1117,7 @@ async fn on_file_change_request_approval_response(
11131117
.unwrap_or_else(|err| {
11141118
error!("failed to deserialize FileChangeRequestApprovalResponse: {err}");
11151119
FileChangeRequestApprovalResponse {
1116-
decision: ApprovalDecision::Decline,
1120+
decision: FileChangeApprovalDecision::Decline,
11171121
}
11181122
});
11191123

@@ -1172,28 +1176,30 @@ async fn on_command_execution_request_approval_response(
11721176
.unwrap_or_else(|err| {
11731177
error!("failed to deserialize CommandExecutionRequestApprovalResponse: {err}");
11741178
CommandExecutionRequestApprovalResponse {
1175-
decision: ApprovalDecision::Decline,
1179+
decision: CommandExecutionApprovalDecision::Decline,
11761180
}
11771181
});
11781182

11791183
let decision = response.decision;
11801184

11811185
let (decision, completion_status) = match decision {
1182-
ApprovalDecision::Accept => (ReviewDecision::Approved, None),
1183-
ApprovalDecision::AcceptForSession => (ReviewDecision::ApprovedForSession, None),
1184-
ApprovalDecision::AcceptWithExecpolicyAmendment {
1186+
CommandExecutionApprovalDecision::Accept => (ReviewDecision::Approved, None),
1187+
CommandExecutionApprovalDecision::AcceptForSession => {
1188+
(ReviewDecision::ApprovedForSession, None)
1189+
}
1190+
CommandExecutionApprovalDecision::AcceptWithExecpolicyAmendment {
11851191
execpolicy_amendment,
11861192
} => (
11871193
ReviewDecision::ApprovedExecpolicyAmendment {
11881194
proposed_execpolicy_amendment: execpolicy_amendment.into_core(),
11891195
},
11901196
None,
11911197
),
1192-
ApprovalDecision::Decline => (
1198+
CommandExecutionApprovalDecision::Decline => (
11931199
ReviewDecision::Denied,
11941200
Some(CommandExecutionStatus::Declined),
11951201
),
1196-
ApprovalDecision::Cancel => (
1202+
CommandExecutionApprovalDecision::Cancel => (
11971203
ReviewDecision::Abort,
11981204
Some(CommandExecutionStatus::Declined),
11991205
),
@@ -1336,7 +1342,7 @@ mod tests {
13361342
#[test]
13371343
fn file_change_accept_for_session_maps_to_approved_for_session() {
13381344
let (decision, completion_status) =
1339-
map_file_change_approval_decision(ApprovalDecision::AcceptForSession);
1345+
map_file_change_approval_decision(FileChangeApprovalDecision::AcceptForSession);
13401346
assert_eq!(decision, ReviewDecision::ApprovedForSession);
13411347
assert_eq!(completion_status, None);
13421348
}

codex-rs/app-server/tests/suite/v2/turn_start.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ use app_test_support::create_mock_chat_completions_server_unchecked;
88
use app_test_support::create_shell_command_sse_response;
99
use app_test_support::format_with_current_shell_display;
1010
use app_test_support::to_response;
11-
use codex_app_server_protocol::ApprovalDecision;
11+
use codex_app_server_protocol::CommandExecutionApprovalDecision;
1212
use codex_app_server_protocol::CommandExecutionRequestApprovalResponse;
1313
use codex_app_server_protocol::CommandExecutionStatus;
14+
use codex_app_server_protocol::FileChangeApprovalDecision;
1415
use codex_app_server_protocol::FileChangeOutputDeltaNotification;
1516
use codex_app_server_protocol::FileChangeRequestApprovalResponse;
1617
use codex_app_server_protocol::ItemCompletedNotification;
@@ -426,7 +427,7 @@ async fn turn_start_exec_approval_decline_v2() -> Result<()> {
426427
mcp.send_response(
427428
request_id,
428429
serde_json::to_value(CommandExecutionRequestApprovalResponse {
429-
decision: ApprovalDecision::Decline,
430+
decision: CommandExecutionApprovalDecision::Decline,
430431
})?,
431432
)
432433
.await?;
@@ -722,7 +723,7 @@ async fn turn_start_file_change_approval_v2() -> Result<()> {
722723
mcp.send_response(
723724
request_id,
724725
serde_json::to_value(FileChangeRequestApprovalResponse {
725-
decision: ApprovalDecision::Accept,
726+
decision: FileChangeApprovalDecision::Accept,
726727
})?,
727728
)
728729
.await?;
@@ -883,7 +884,7 @@ async fn turn_start_file_change_approval_accept_for_session_persists_v2() -> Res
883884
mcp.send_response(
884885
request_id,
885886
serde_json::to_value(FileChangeRequestApprovalResponse {
886-
decision: ApprovalDecision::AcceptForSession,
887+
decision: FileChangeApprovalDecision::AcceptForSession,
887888
})?,
888889
)
889890
.await?;
@@ -1072,7 +1073,7 @@ async fn turn_start_file_change_approval_decline_v2() -> Result<()> {
10721073
mcp.send_response(
10731074
request_id,
10741075
serde_json::to_value(FileChangeRequestApprovalResponse {
1075-
decision: ApprovalDecision::Decline,
1076+
decision: FileChangeApprovalDecision::Decline,
10761077
})?,
10771078
)
10781079
.await?;

0 commit comments

Comments
 (0)