From 1e675767a06b8490e2c028cb98441b53372a22a2 Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Wed, 10 Jun 2026 01:06:58 -0700 Subject: [PATCH] codex: simplify goal input materialization cleanup --- codex-rs/tui/src/chatwidget/slash_dispatch.rs | 49 +++++++------------ codex-rs/tui/src/goal_files.rs | 11 +---- 2 files changed, 19 insertions(+), 41 deletions(-) diff --git a/codex-rs/tui/src/chatwidget/slash_dispatch.rs b/codex-rs/tui/src/chatwidget/slash_dispatch.rs index 25c572ca5c..6ed7cc151f 100644 --- a/codex-rs/tui/src/chatwidget/slash_dispatch.rs +++ b/codex-rs/tui/src/chatwidget/slash_dispatch.rs @@ -30,12 +30,6 @@ struct PreparedSlashCommandArgs { source: SlashCommandDispatchSource, } -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -enum PreparedSlashCommandOutcome { - UseDefaultQueuedDrain, - ContinueQueuedDrain, -} - const SIDE_STARTING_CONTEXT_LABEL: &str = "Side starting..."; const SIDE_SLASH_COMMAND_UNAVAILABLE_HINT: &str = "Press Ctrl+C to return to the main thread first."; @@ -626,7 +620,7 @@ impl ChatWidget { &mut self, cmd: SlashCommand, prepared: PreparedSlashCommandArgs, - ) -> PreparedSlashCommandOutcome { + ) -> QueueDrain { let PreparedSlashCommandArgs { args, text_elements, @@ -671,19 +665,19 @@ impl ChatWidget { }, SlashCommand::Rename if !trimmed.is_empty() => { if !self.ensure_thread_rename_allowed() { - return PreparedSlashCommandOutcome::UseDefaultQueuedDrain; + return self.queued_command_drain_result(cmd); } self.session_telemetry .counter("codex.thread.rename", /*inc*/ 1, &[]); let Some(name) = normalize_thread_name(&args) else { self.add_error_message("Thread name cannot be empty.".to_string()); - return PreparedSlashCommandOutcome::UseDefaultQueuedDrain; + return self.queued_command_drain_result(cmd); }; self.app_event_tx.set_thread_name(name); } SlashCommand::Plan if !trimmed.is_empty() => { if !self.apply_plan_slash_command() { - return PreparedSlashCommandOutcome::UseDefaultQueuedDrain; + return self.queued_command_drain_result(cmd); } let user_message = self.prepared_inline_user_message( args, @@ -707,7 +701,7 @@ impl ChatWidget { if source == SlashCommandDispatchSource::Live { self.clear_live_goal_submission(); } - return PreparedSlashCommandOutcome::UseDefaultQueuedDrain; + return self.queued_command_drain_result(cmd); } enum GoalControlCommand { Clear, @@ -722,7 +716,7 @@ impl ChatWidget { if source == SlashCommandDispatchSource::Live { self.clear_live_goal_submission(); } - return PreparedSlashCommandOutcome::UseDefaultQueuedDrain; + return self.queued_command_drain_result(cmd); } "pause" => Some(GoalControlCommand::SetStatus(AppThreadGoalStatus::Paused)), "resume" => Some(GoalControlCommand::SetStatus(AppThreadGoalStatus::Active)), @@ -739,7 +733,7 @@ impl ChatWidget { if source == SlashCommandDispatchSource::Live { self.clear_live_goal_submission(); } - return PreparedSlashCommandOutcome::UseDefaultQueuedDrain; + return self.queued_command_drain_result(cmd); }; match command { GoalControlCommand::Clear => { @@ -755,7 +749,7 @@ impl ChatWidget { if source == SlashCommandDispatchSource::Live { self.clear_live_goal_submission(); } - return PreparedSlashCommandOutcome::UseDefaultQueuedDrain; + return self.queued_command_drain_result(cmd); } let pending_pastes = if source == SlashCommandDispatchSource::Live { self.bottom_pane.composer_pending_pastes() @@ -775,13 +769,10 @@ impl ChatWidget { Ok(objective) => objective, Err(err) => { self.add_error_message(err.to_string()); - return match source { - SlashCommandDispatchSource::Live => { - PreparedSlashCommandOutcome::UseDefaultQueuedDrain - } - SlashCommandDispatchSource::Queued => { - PreparedSlashCommandOutcome::ContinueQueuedDrain - } + return if source == SlashCommandDispatchSource::Queued { + QueueDrain::Continue + } else { + self.queued_command_drain_result(cmd) }; } }; @@ -804,7 +795,7 @@ impl ChatWidget { Some("The session must start before you can set a goal.".to_string()), ); } - return PreparedSlashCommandOutcome::UseDefaultQueuedDrain; + return self.queued_command_drain_result(cmd); }; self.app_event_tx.send(AppEvent::SetThreadGoalObjective { thread_id, @@ -822,7 +813,7 @@ impl ChatWidget { self.add_error_message(format!( "'/{command}' is unavailable before the session starts." )); - return PreparedSlashCommandOutcome::UseDefaultQueuedDrain; + return self.queued_command_drain_result(cmd); }; let user_message = self.prepared_inline_user_message( args, @@ -863,7 +854,7 @@ impl ChatWidget { if source == SlashCommandDispatchSource::Live && cmd != SlashCommand::Goal { self.bottom_pane.drain_pending_submission_state(); } - PreparedSlashCommandOutcome::UseDefaultQueuedDrain + self.queued_command_drain_result(cmd) } pub(super) fn submit_queued_slash_prompt(&mut self, user_message: UserMessage) -> QueueDrain { @@ -951,7 +942,7 @@ impl ChatWidget { rest_offset + leading_trimmed, &text_elements, ); - let outcome = self.dispatch_prepared_command_with_args( + self.dispatch_prepared_command_with_args( cmd, PreparedSlashCommandArgs { args: trimmed_rest.to_string(), @@ -961,13 +952,7 @@ impl ChatWidget { mention_bindings, source: SlashCommandDispatchSource::Queued, }, - ); - match outcome { - PreparedSlashCommandOutcome::UseDefaultQueuedDrain => { - self.queued_command_drain_result(cmd) - } - PreparedSlashCommandOutcome::ContinueQueuedDrain => QueueDrain::Continue, - } + ) } fn builtin_command_flags(&self) -> BuiltinCommandFlags { diff --git a/codex-rs/tui/src/goal_files.rs b/codex-rs/tui/src/goal_files.rs index 8e01cdad63..09f3897385 100644 --- a/codex-rs/tui/src/goal_files.rs +++ b/codex-rs/tui/src/goal_files.rs @@ -178,16 +178,9 @@ fn append_section(objective: &mut String, heading: &str, lines: Vec) { objective.push_str(&lines.join("\n")); } -fn image_extension(path: &Path) -> String { +fn image_extension(path: &Path) -> &str { path.extension() .and_then(|extension| extension.to_str()) - .map(|extension| { - extension - .chars() - .filter(char::is_ascii_alphanumeric) - .take(8) - .collect::() - }) .filter(|extension| !extension.is_empty()) - .unwrap_or_else(|| "png".to_string()) + .unwrap_or("png") }