Keep the composer editable during TUI startup (#38642)

## Why

Configuration and app-server initialization can take time before the main TUI is ready, leaving users unable to begin drafting a prompt.

## What changed

- Show a provisional composer while startup work runs and carry its text, cursor position, paste state, and attachments into the initialized chat.
- Limit the provisional composer to safe editing and cancellation, and quarantine input around session pickers, approvals, and other actionable startup screens.
- Preserve configuration validation before terminal checks and recover terminal state cleanly from startup failures and caught panics.

## Testing

- Cover startup editing, multiline and large pastes, keymaps, cancellation, session-picker handoff, approval boundaries, and draft restoration.
- Verify non-interactive launches report configuration errors before terminal errors.

GitOrigin-RevId: fe04a85cfbbcff21ff87fa81fd17474827858575
This commit is contained in:
Charlie Marsh authored and copyberry committed 2026-08-14 20:30:30 +00:00
1 parent 58d2daba45
commit a0bed4be21
26 files changed
+4348 -1151

No files matched your search

+55 -3
View File
@@ -353,6 +353,9 @@ impl App {
ThreadInteractiveRequest::Approval(request) => {
self.render_inactive_patch_preview(&request);
self.chat_widget.push_approval_request(request);
if self.startup_protected_input_boundary && !self.chat_widget.has_active_view() {
self.startup_pending_protected_request = true;
}
}
ThreadInteractiveRequest::McpServerElicitation(request) => {
self.chat_widget
@@ -1570,6 +1573,28 @@ impl App {
self.chat_widget.handle_skills_list_response(response);
}
fn startup_request_may_open_protected_view(&self, request: &ServerRequest) -> bool {
let ServerRequest::McpServerElicitationRequest { request_id, params } = request else {
return true;
};
match &params.request {
codex_app_server_protocol::McpServerElicitationRequest::Form { .. } => true,
codex_app_server_protocol::McpServerElicitationRequest::OpenAiForm { .. } => false,
request @ codex_app_server_protocol::McpServerElicitationRequest::Url { .. } => {
let thread_id = ThreadId::from_string(&params.thread_id)
.unwrap_or_else(|_| self.chat_widget.thread_id().unwrap_or_default());
AppLinkViewParams::from_url_app_server_request(
thread_id,
&params.server_name,
request_id.clone(),
request,
)
.is_some()
}
}
}
pub(super) fn handle_thread_event_now(&mut self, event: ThreadBufferedEvent) {
let needs_refresh = matches!(
&event,
@@ -1591,8 +1616,16 @@ impl App {
.pending_app_server_requests
.contains_server_request(request.as_ref())
{
let may_open_protected_view =
self.startup_request_may_open_protected_view(request.as_ref());
self.chat_widget
.handle_server_request(*request, /*replay_kind*/ None);
if may_open_protected_view
&& self.startup_protected_input_boundary
&& !self.chat_widget.has_active_view()
{
self.startup_pending_protected_request = true;
}
}
}
ThreadBufferedEvent::HistoryEntryResponse(event) => {
@@ -1612,9 +1645,18 @@ impl App {
ThreadBufferedEvent::Notification(notification) => self
.chat_widget
.handle_server_notification(*notification, Some(ReplayKind::ThreadSnapshot)),
ThreadBufferedEvent::Request(request) => self
.chat_widget
.handle_server_request(*request, Some(ReplayKind::ThreadSnapshot)),
ThreadBufferedEvent::Request(request) => {
let may_open_protected_view =
self.startup_request_may_open_protected_view(request.as_ref());
self.chat_widget
.handle_server_request(*request, Some(ReplayKind::ThreadSnapshot));
if may_open_protected_view
&& self.startup_protected_input_boundary
&& !self.chat_widget.has_active_view()
{
self.startup_pending_protected_request = true;
}
}
ThreadBufferedEvent::HistoryEntryResponse(event) => {
self.chat_widget.handle_history_entry_response(event)
}
@@ -1686,7 +1728,17 @@ impl App {
// thread, so unrelated shutdowns cannot consume this marker.
self.pending_shutdown_exit_thread_id = None;
}
let had_active_view = self.chat_widget.has_active_view();
self.handle_thread_event_now(event);
if !had_active_view
&& self.chat_widget.has_active_view()
&& self.startup_protected_input_boundary
{
self.chat_widget.pre_draw_tick();
self.render_chat_widget_frame(tui, tui.terminal.last_known_screen_size)?;
tui.discard_pending_input_before_interactive_screen()?;
self.startup_pending_protected_request = false;
}
if self.backtrack_render_pending {
tui.frame_requester().schedule_frame();
}