From 992b531180fb07dc983dc339a109a6abd4ce8c6b Mon Sep 17 00:00:00 2001 From: jif-oai Date: Thu, 18 Sep 2025 18:18:06 +0100 Subject: [PATCH] fix: some nit Rust reference issues (#3849) Fix some small references issue. No behavioural change. Just making the code cleaner --- codex-rs/core/src/client_common.rs | 9 ++++----- codex-rs/core/src/openai_tools.rs | 4 ++-- codex-rs/core/src/shell.rs | 24 ++++++++++++++---------- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/codex-rs/core/src/client_common.rs b/codex-rs/core/src/client_common.rs index eead654b..3a5eb5b1 100644 --- a/codex-rs/core/src/client_common.rs +++ b/codex-rs/core/src/client_common.rs @@ -34,13 +34,11 @@ pub struct Prompt { } impl Prompt { - pub(crate) fn get_full_instructions(&self, model: &ModelFamily) -> Cow<'_, str> { + pub(crate) fn get_full_instructions<'a>(&'a self, model: &'a ModelFamily) -> Cow<'a, str> { let base = self .base_instructions_override .as_deref() .unwrap_or(model.base_instructions.deref()); - let mut sections: Vec<&str> = vec![base]; - // When there are no custom instructions, add apply_patch_tool_instructions if: // - the model needs special instructions (4.1) // AND @@ -54,9 +52,10 @@ impl Prompt { && model.needs_special_apply_patch_instructions && !is_apply_patch_tool_present { - sections.push(APPLY_PATCH_TOOL_INSTRUCTIONS); + Cow::Owned(format!("{base}\n{APPLY_PATCH_TOOL_INSTRUCTIONS}")) + } else { + Cow::Borrowed(base) } - Cow::Owned(sections.join("\n")) } pub(crate) fn get_formatted_input(&self) -> Vec { diff --git a/codex-rs/core/src/openai_tools.rs b/codex-rs/core/src/openai_tools.rs index f4d72481..b57d1b76 100644 --- a/codex-rs/core/src/openai_tools.rs +++ b/codex-rs/core/src/openai_tools.rs @@ -333,7 +333,7 @@ pub(crate) struct ApplyPatchToolArgs { /// Responses API: /// https://platform.openai.com/docs/guides/function-calling?api-mode=responses pub fn create_tools_json_for_responses_api( - tools: &Vec, + tools: &[OpenAiTool], ) -> crate::error::Result> { let mut tools_json = Vec::new(); @@ -348,7 +348,7 @@ pub fn create_tools_json_for_responses_api( /// Chat Completions API: /// https://platform.openai.com/docs/guides/function-calling?api-mode=chat pub(crate) fn create_tools_json_for_chat_completions_api( - tools: &Vec, + tools: &[OpenAiTool], ) -> crate::error::Result> { // We start with the JSON for the Responses API and than rewrite it to match // the chat completions tool call format. diff --git a/codex-rs/core/src/shell.rs b/codex-rs/core/src/shell.rs index cb278fdd..28cf61dd 100644 --- a/codex-rs/core/src/shell.rs +++ b/codex-rs/core/src/shell.rs @@ -32,15 +32,19 @@ pub enum Shell { impl Shell { pub fn format_default_shell_invocation(&self, command: Vec) -> Option> { match self { - Shell::Zsh(zsh) => { - format_shell_invocation_with_rc(&command, &zsh.shell_path, &zsh.zshrc_path) - } - Shell::Bash(bash) => { - format_shell_invocation_with_rc(&command, &bash.shell_path, &bash.bashrc_path) - } + Shell::Zsh(zsh) => format_shell_invocation_with_rc( + command.as_slice(), + &zsh.shell_path, + &zsh.zshrc_path, + ), + Shell::Bash(bash) => format_shell_invocation_with_rc( + command.as_slice(), + &bash.shell_path, + &bash.bashrc_path, + ), Shell::PowerShell(ps) => { // If model generated a bash command, prefer a detected bash fallback - if let Some(script) = strip_bash_lc(&command) { + if let Some(script) = strip_bash_lc(command.as_slice()) { return match &ps.bash_exe_fallback { Some(bash) => Some(vec![ bash.to_string_lossy().to_string(), @@ -102,7 +106,7 @@ impl Shell { } fn format_shell_invocation_with_rc( - command: &Vec, + command: &[String], shell_path: &str, rc_path: &str, ) -> Option> { @@ -118,8 +122,8 @@ fn format_shell_invocation_with_rc( Some(vec![shell_path.to_string(), "-lc".to_string(), rc_command]) } -fn strip_bash_lc(command: &Vec) -> Option { - match command.as_slice() { +fn strip_bash_lc(command: &[String]) -> Option { + match command { // exactly three items [first, second, third] // first two must be "bash", "-lc"