mirror of
https://github.com/openai/codex.git
synced 2026-09-08 15:50:34 +00:00
codex: simplify goal input materialization cleanup
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -178,16 +178,9 @@ fn append_section(objective: &mut String, heading: &str, lines: Vec<String>) {
|
||||
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::<String>()
|
||||
})
|
||||
.filter(|extension| !extension.is_empty())
|
||||
.unwrap_or_else(|| "png".to_string())
|
||||
.unwrap_or("png")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user