Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

fix: some nit Rust reference issues (#3849)

jif-oai992b531180fb
diff --git a/codex-rs/core/src/client_common.rs b/codex-rs/core/src/client_common.rs
index eead654b9e..3a5eb5b16b 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<ResponseItem> {
diff --git a/codex-rs/core/src/openai_tools.rs b/codex-rs/core/src/openai_tools.rs
index f4d724815e..b57d1b7692 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<OpenAiTool>,
+ tools: &[OpenAiTool],
) -> crate::error::Result<Vec<serde_json::Value>> {
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<OpenAiTool>,
+ tools: &[OpenAiTool],
) -> crate::error::Result<Vec<serde_json::Value>> {
// 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 cb278fdd46..28cf61dd94 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<String>) -> Option<Vec<String>> {
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<String>,
+ command: &[String],
shell_path: &str,
rc_path: &str,
) -> Option<Vec<String>> {
@@ -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<String>) -> Option<String> {
- match command.as_slice() {
+fn strip_bash_lc(command: &[String]) -> Option<String> {
+ match command {
// exactly three items
[first, second, third]
// first two must be "bash", "-lc"