Remove core protocol dependency [2/2] (#20325)

## Why

With the local model layer and app-server routing in place from PR1,
this PR moves the active TUI runtime onto app-server notifications. The
affected pieces share the same event flow, so the command surface,
session state, bottom-pane prompts, chat rendering, history/status
views, and tests move together to keep the stacked branch buildable.

This PR also removes the obsolete compatibility surface that is no
longer used after the migration. The proposed protocol-boundary verifier
layer was dropped from the stack; enforcing that final boundary will be
simpler once `codex-tui` no longer needs any `codex_protocol`
references.

This PR is part 2 of a 2-PR stack:

1. Add TUI-owned replacement models and extract app-server event
routing.
2. Move the active TUI flow to app-server notifications and delete
obsolete adapter code.

## What changed

- Rewired app command and session handling to use app-server request and
notification shapes.
- Moved approval overlays, request-user-input flows, MCP elicitation,
realtime events, and review commands onto the app-server-facing model
surface.
- Updated chat rendering, history cells, status views, multi-agent UI,
replay state, and TUI tests to use app-server notifications plus the
local models introduced in PR1.
- Deleted `codex-rs/tui/src/app/app_server_adapter.rs` and the
superseded `chatwidget/tests/background_events.rs` fixture path.

## Verification

- `cargo check -p codex-tui --tests`
- Top of stack: `cargo test -p codex-tui`
This commit is contained in:
Eric Traut authored and GitHub committed 2026-04-30 11:34:34 -07:00
1 parent 5cc5f12efc
commit f2bc2f26a9
76 files changed
+5078 -9951

No files matched your search

@@ -1,5 +1,4 @@
use crate::app_command::AppCommand;
use crate::app_command::AppCommandView;
use codex_app_server_protocol::RequestId as AppServerRequestId;
use codex_app_server_protocol::ServerNotification;
use codex_app_server_protocol::ServerRequest;
@@ -10,11 +9,11 @@ use std::collections::HashSet;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
struct ElicitationRequestKey {
server_name: String,
request_id: codex_protocol::mcp::RequestId,
request_id: AppServerRequestId,
}
impl ElicitationRequestKey {
fn new(server_name: String, request_id: codex_protocol::mcp::RequestId) -> Self {
fn new(server_name: String, request_id: AppServerRequestId) -> Self {
Self {
server_name,
request_id,
@@ -33,9 +32,9 @@ impl ElicitationRequestKey {
// - buffer eviction (`note_evicted_event`)
//
// We keep both fast lookup sets (for snapshot filtering by call_id/request key) and
// turn-indexed queues/vectors so `TurnComplete`/`TurnAborted` can clear stale prompts tied
// to a turn. `request_user_input` removal is FIFO because the overlay answers queued prompts
// in FIFO order for a shared `turn_id`.
// turn-indexed queues/vectors so turn completion or interruption can clear
// stale prompts tied to a turn. `request_user_input` removal is FIFO because
// the overlay answers queued prompts in FIFO order for a shared `turn_id`.
pub(super) struct PendingInteractiveReplayState {
exec_approval_call_ids: HashSet<String>,
exec_approval_call_ids_by_turn_id: HashMap<String, Vec<String>>,
@@ -77,13 +76,13 @@ impl PendingInteractiveReplayState {
{
let op: AppCommand = op.into();
matches!(
op.view(),
AppCommandView::ExecApproval { .. }
| AppCommandView::PatchApproval { .. }
| AppCommandView::ResolveElicitation { .. }
| AppCommandView::RequestPermissionsResponse { .. }
| AppCommandView::UserInputAnswer { .. }
| AppCommandView::Shutdown
&op,
AppCommand::ExecApproval { .. }
| AppCommand::PatchApproval { .. }
| AppCommand::ResolveElicitation { .. }
| AppCommand::RequestPermissionsResponse { .. }
| AppCommand::UserInputAnswer { .. }
| AppCommand::Shutdown
)
}
@@ -92,8 +91,8 @@ impl PendingInteractiveReplayState {
T: Into<AppCommand>,
{
let op: AppCommand = op.into();
match op.view() {
AppCommandView::ExecApproval { id, turn_id, .. } => {
match &op {
AppCommand::ExecApproval { id, turn_id, .. } => {
self.exec_approval_call_ids.remove(id);
if let Some(turn_id) = turn_id {
Self::remove_call_id_from_turn_map_entry(
@@ -105,7 +104,7 @@ impl PendingInteractiveReplayState {
self.pending_requests_by_request_id
.retain(|_, pending| !matches!(pending, PendingInteractiveRequest::ExecApproval { approval_id, .. } if approval_id == id));
}
AppCommandView::PatchApproval { id, .. } => {
AppCommand::PatchApproval { id, .. } => {
self.patch_approval_call_ids.remove(id);
Self::remove_call_id_from_turn_map(
&mut self.patch_approval_call_ids_by_turn_id,
@@ -114,7 +113,7 @@ impl PendingInteractiveReplayState {
self.pending_requests_by_request_id
.retain(|_, pending| !matches!(pending, PendingInteractiveRequest::PatchApproval { item_id, .. } if item_id == id));
}
AppCommandView::ResolveElicitation {
AppCommand::ResolveElicitation {
server_name,
request_id,
..
@@ -130,7 +129,7 @@ impl PendingInteractiveReplayState {
},
);
}
AppCommandView::RequestPermissionsResponse { id, .. } => {
AppCommand::RequestPermissionsResponse { id, .. } => {
self.request_permissions_call_ids.remove(id);
Self::remove_call_id_from_turn_map(
&mut self.request_permissions_call_ids_by_turn_id,
@@ -145,7 +144,7 @@ impl PendingInteractiveReplayState {
// `Op::UserInputAnswer` identifies the turn, not the prompt call_id. The UI
// answers queued prompts for the same turn in FIFO order, so remove the oldest
// queued call_id for that turn.
AppCommandView::UserInputAnswer { id, .. } => {
AppCommand::UserInputAnswer { id, .. } => {
let mut remove_turn_entry = false;
if let Some(call_ids) = self.request_user_input_call_ids_by_turn_id.get_mut(id) {
if !call_ids.is_empty() {
@@ -165,7 +164,7 @@ impl PendingInteractiveReplayState {
self.request_user_input_call_ids_by_turn_id.remove(id);
}
}
AppCommandView::Shutdown => self.clear(),
AppCommand::Shutdown => self.clear(),
_ => {}
}
}
@@ -208,10 +207,8 @@ impl PendingInteractiveReplayState {
);
}
ServerRequest::McpServerElicitationRequest { request_id, params } => {
let key = ElicitationRequestKey::new(
params.server_name.clone(),
app_server_request_id_to_mcp_request_id(request_id),
);
let key =
ElicitationRequestKey::new(params.server_name.clone(), request_id.clone());
self.elicitation_requests.insert(key.clone());
self.pending_requests_by_request_id.insert(
request_id.clone(),
@@ -311,7 +308,7 @@ impl PendingInteractiveReplayState {
self.elicitation_requests
.remove(&ElicitationRequestKey::new(
params.server_name.clone(),
app_server_request_id_to_mcp_request_id(request_id),
request_id.clone(),
));
}
ServerRequest::ToolRequestUserInput { params, .. } => {
@@ -366,7 +363,7 @@ impl PendingInteractiveReplayState {
.elicitation_requests
.contains(&ElicitationRequestKey::new(
params.server_name.clone(),
app_server_request_id_to_mcp_request_id(request_id),
request_id.clone(),
)),
ServerRequest::ToolRequestUserInput { params, .. } => {
self.request_user_input_call_ids.contains(&params.item_id)
@@ -549,10 +546,7 @@ impl PendingInteractiveReplayState {
(
PendingInteractiveRequest::Elicitation(key),
ServerRequest::McpServerElicitationRequest { request_id, params },
) => {
key.server_name == params.server_name
&& key.request_id == app_server_request_id_to_mcp_request_id(request_id)
}
) => key.server_name == params.server_name && key.request_id == *request_id,
(
PendingInteractiveRequest::RequestPermissions { turn_id, item_id },
ServerRequest::PermissionsRequestApproval { params, .. },
@@ -566,23 +560,17 @@ impl PendingInteractiveReplayState {
}
}
fn app_server_request_id_to_mcp_request_id(
request_id: &AppServerRequestId,
) -> codex_protocol::mcp::RequestId {
match request_id {
AppServerRequestId::String(value) => codex_protocol::mcp::RequestId::String(value.clone()),
AppServerRequestId::Integer(value) => codex_protocol::mcp::RequestId::Integer(*value),
}
}
#[cfg(test)]
mod tests {
use super::super::ThreadBufferedEvent;
use super::super::ThreadEventStore;
use crate::app_command::AppCommand as Op;
use codex_app_server_protocol::CommandExecutionApprovalDecision;
use codex_app_server_protocol::CommandExecutionRequestApprovalParams;
use codex_app_server_protocol::FileChangeRequestApprovalParams;
use codex_app_server_protocol::McpElicitationObjectType;
use codex_app_server_protocol::McpElicitationSchema;
use codex_app_server_protocol::McpServerElicitationAction;
use codex_app_server_protocol::McpServerElicitationRequest;
use codex_app_server_protocol::McpServerElicitationRequestParams;
use codex_app_server_protocol::RequestId as AppServerRequestId;
@@ -591,11 +579,10 @@ mod tests {
use codex_app_server_protocol::ServerRequestResolvedNotification;
use codex_app_server_protocol::ThreadClosedNotification;
use codex_app_server_protocol::ToolRequestUserInputParams;
use codex_app_server_protocol::ToolRequestUserInputResponse;
use codex_app_server_protocol::Turn;
use codex_app_server_protocol::TurnCompletedNotification;
use codex_app_server_protocol::TurnStatus;
use codex_protocol::protocol::Op;
use codex_protocol::protocol::ReviewDecision;
use codex_utils_absolute_path::test_support::PathBufExt;
use codex_utils_absolute_path::test_support::test_path_buf;
use pretty_assertions::assert_eq;
@@ -724,7 +711,7 @@ mod tests {
store.note_outbound_op(&Op::UserInputAnswer {
id: "turn-1".to_string(),
response: codex_protocol::request_user_input::RequestUserInputResponse {
response: ToolRequestUserInputResponse {
answers: HashMap::new(),
},
});
@@ -767,7 +754,7 @@ mod tests {
store.note_outbound_op(&Op::ExecApproval {
id: "approval-1".to_string(),
turn_id: Some("turn-1".to_string()),
decision: ReviewDecision::Approved,
decision: CommandExecutionApprovalDecision::Accept,
});
let snapshot = store.snapshot();
@@ -809,7 +796,7 @@ mod tests {
store.note_outbound_op(&Op::UserInputAnswer {
id: "turn-1".to_string(),
response: codex_protocol::request_user_input::RequestUserInputResponse {
response: ToolRequestUserInputResponse {
answers: HashMap::new(),
},
});
@@ -833,7 +820,7 @@ mod tests {
store.note_outbound_op(&Op::UserInputAnswer {
id: "turn-1".to_string(),
response: codex_protocol::request_user_input::RequestUserInputResponse {
response: ToolRequestUserInputResponse {
answers: HashMap::new(),
},
});
@@ -854,7 +841,7 @@ mod tests {
store.note_outbound_op(&Op::PatchApproval {
id: "call-1".to_string(),
decision: ReviewDecision::Approved,
decision: codex_app_server_protocol::FileChangeApprovalDecision::Accept,
});
let snapshot = store.snapshot();
@@ -888,13 +875,13 @@ mod tests {
#[test]
fn thread_event_snapshot_drops_resolved_elicitation_after_outbound_resolution() {
let mut store = ThreadEventStore::new(/*capacity*/ 8);
let request_id = codex_protocol::mcp::RequestId::String("request-1".to_string());
let request_id = AppServerRequestId::String("request-1".to_string());
store.push_request(elicitation_request("server-1", "request-1", "turn-1"));
store.note_outbound_op(&Op::ResolveElicitation {
server_name: "server-1".to_string(),
request_id,
decision: codex_protocol::approvals::ElicitationAction::Accept,
decision: McpServerElicitationAction::Accept,
content: None,
meta: None,
});
@@ -920,7 +907,7 @@ mod tests {
store.note_outbound_op(&Op::ExecApproval {
id: "call-1".to_string(),
turn_id: Some("turn-1".to_string()),
decision: ReviewDecision::Approved,
decision: CommandExecutionApprovalDecision::Accept,
});
assert_eq!(store.has_pending_thread_approvals(), false);