diff --git a/codex-rs/core/src/context_manager/history.rs b/codex-rs/core/src/context_manager/history.rs index ff7c75a38d..61d1ac68e7 100644 --- a/codex-rs/core/src/context_manager/history.rs +++ b/codex-rs/core/src/context_manager/history.rs @@ -357,7 +357,7 @@ fn process_user_text_item( if let Some(offloaded) = offloader.write_user_message(text) { vec![ContentItem::InputText { text: format!( - "User input was too large for the remaining context window and was saved to {}.", + "User input was too large for the remaining context window and was saved to {}. Use read_file to load it.", offloaded.display() ), }] diff --git a/codex-rs/core/src/context_manager/history_tests.rs b/codex-rs/core/src/context_manager/history_tests.rs index 6e6b3554eb..4e0d01ca75 100644 --- a/codex-rs/core/src/context_manager/history_tests.rs +++ b/codex-rs/core/src/context_manager/history_tests.rs @@ -122,7 +122,7 @@ fn stores_oversized_user_message_in_user_message_dir() { let path = placeholder .split("saved to ") .nth(1) - .and_then(|tail| tail.split(" (").next()) + .and_then(|tail| tail.split(". Use").next()) .expect("capture temp path"); let path = PathBuf::from(path); @@ -208,7 +208,7 @@ fn offloads_each_user_input_item_independently() { let path = placeholder .split("saved to ") .nth(1) - .and_then(|tail| tail.strip_suffix('.')) + .and_then(|tail| tail.split(". Use").next()) .expect("capture temp path"); let path = PathBuf::from(path); diff --git a/codex-rs/core/src/instructions/mod.rs b/codex-rs/core/src/instructions/mod.rs index 9da925ac74..febada5110 100644 --- a/codex-rs/core/src/instructions/mod.rs +++ b/codex-rs/core/src/instructions/mod.rs @@ -1,6 +1,6 @@ mod user_instructions; pub(crate) use user_instructions::SkillInstructions; -pub use user_instructions::USER_INSTRUCTIONS_OPEN_TAG_LEGACY; +pub use user_instructions::USER_INSTRUCTIONS_OPEN_TAG; pub use user_instructions::USER_INSTRUCTIONS_PREFIX; pub(crate) use user_instructions::UserInstructions; diff --git a/codex-rs/core/src/instructions/user_instructions.rs b/codex-rs/core/src/instructions/user_instructions.rs index 9c563c29c5..38f8192aa0 100644 --- a/codex-rs/core/src/instructions/user_instructions.rs +++ b/codex-rs/core/src/instructions/user_instructions.rs @@ -4,9 +4,9 @@ use serde::Serialize; use codex_protocol::models::ContentItem; use codex_protocol::models::ResponseItem; -pub const USER_INSTRUCTIONS_OPEN_TAG_LEGACY: &str = ""; -pub const USER_INSTRUCTIONS_PREFIX: &str = "# AGENTS.md instructions for "; -pub const SKILL_INSTRUCTIONS_PREFIX: &str = " bool { if let [ContentItem::InputText { text }] = message { text.starts_with(USER_INSTRUCTIONS_PREFIX) - || text.starts_with(USER_INSTRUCTIONS_OPEN_TAG_LEGACY) + || text.starts_with(USER_INSTRUCTIONS_OPEN_TAG) } else { false } diff --git a/codex-rs/core/src/user_shell_command.rs b/codex-rs/core/src/user_shell_command.rs index fb8efcc09c..95e41375e1 100644 --- a/codex-rs/core/src/user_shell_command.rs +++ b/codex-rs/core/src/user_shell_command.rs @@ -1,5 +1,7 @@ use std::time::Duration; +pub use codex_protocol::instruction_markers::USER_SHELL_COMMAND_CLOSE; +pub use codex_protocol::instruction_markers::USER_SHELL_COMMAND_OPEN; use codex_protocol::models::ContentItem; use codex_protocol::models::ResponseItem; @@ -7,9 +9,6 @@ use crate::codex::TurnContext; use crate::exec::ExecToolCallOutput; use crate::tools::format_exec_output_str; -pub const USER_SHELL_COMMAND_OPEN: &str = ""; -pub const USER_SHELL_COMMAND_CLOSE: &str = ""; - pub fn is_user_shell_command_text(text: &str) -> bool { let trimmed = text.trim_start(); let lowered = trimmed.to_ascii_lowercase(); diff --git a/codex-rs/core/tests/suite/truncation.rs b/codex-rs/core/tests/suite/truncation.rs index 1e02b67b6c..1dfb85cd6d 100644 --- a/codex-rs/core/tests/suite/truncation.rs +++ b/codex-rs/core/tests/suite/truncation.rs @@ -280,7 +280,7 @@ async fn oversized_user_message_is_written_to_user_message_dir() -> Result<()> { let path = replaced .split("saved to ") .nth(1) - .and_then(|tail| tail.strip_suffix('.')) + .and_then(|tail| tail.split(". Use").next()) .context("extract saved path")?; let saved = fs::read_to_string(path).context("read saved user message")?; diff --git a/codex-rs/protocol/src/instruction_markers.rs b/codex-rs/protocol/src/instruction_markers.rs new file mode 100644 index 0000000000..69c4ba5c82 --- /dev/null +++ b/codex-rs/protocol/src/instruction_markers.rs @@ -0,0 +1,14 @@ +pub const USER_INSTRUCTIONS_PREFIX: &str = "# AGENTS.md instructions for "; +pub const USER_INSTRUCTIONS_OPEN_TAG: &str = ""; +pub const USER_INSTRUCTIONS_CLOSE_TAG: &str = ""; +pub const ENVIRONMENT_CONTEXT_OPEN_TAG: &str = ""; +pub const ENVIRONMENT_CONTEXT_CLOSE_TAG: &str = ""; +pub const COLLABORATION_MODE_OPEN_TAG: &str = ""; +pub const COLLABORATION_MODE_CLOSE_TAG: &str = ""; +pub const SKILL_INSTRUCTIONS_PREFIX: &str = " bool { @@ -97,14 +101,14 @@ impl ContentItem { let trimmed = text.trim_start(); if trimmed.starts_with(USER_INSTRUCTIONS_PREFIX) - || trimmed.starts_with(USER_INSTRUCTIONS_OPEN_TAG_LEGACY) + || trimmed.starts_with(USER_INSTRUCTIONS_OPEN_TAG) || trimmed.starts_with(SKILL_INSTRUCTIONS_PREFIX) { return false; } let lowered = trimmed.to_ascii_lowercase(); - if lowered.starts_with(ENVIRONMENT_CONTEXT_PREFIX) + if lowered.starts_with(ENVIRONMENT_CONTEXT_OPEN_TAG) || lowered.starts_with(USER_SHELL_COMMAND_OPEN) { return false; @@ -406,10 +410,6 @@ fn local_image_error_placeholder( pub const VIEW_IMAGE_TOOL_NAME: &str = "view_image"; -const IMAGE_OPEN_TAG: &str = ""; -const IMAGE_CLOSE_TAG: &str = ""; -const LOCAL_IMAGE_OPEN_TAG_PREFIX: &str = ""; const LOCAL_IMAGE_CLOSE_TAG: &str = IMAGE_CLOSE_TAG; pub fn image_open_tag_text() -> String { diff --git a/codex-rs/protocol/src/protocol.rs b/codex-rs/protocol/src/protocol.rs index 1142f182c0..3fe6d05c82 100644 --- a/codex-rs/protocol/src/protocol.rs +++ b/codex-rs/protocol/src/protocol.rs @@ -16,6 +16,12 @@ use crate::approvals::ElicitationRequestEvent; use crate::config_types::CollaborationMode; use crate::config_types::ReasoningSummary as ReasoningSummaryConfig; use crate::custom_prompts::CustomPrompt; +pub use crate::instruction_markers::COLLABORATION_MODE_CLOSE_TAG; +pub use crate::instruction_markers::COLLABORATION_MODE_OPEN_TAG; +pub use crate::instruction_markers::ENVIRONMENT_CONTEXT_CLOSE_TAG; +pub use crate::instruction_markers::ENVIRONMENT_CONTEXT_OPEN_TAG; +pub use crate::instruction_markers::USER_INSTRUCTIONS_CLOSE_TAG; +pub use crate::instruction_markers::USER_INSTRUCTIONS_OPEN_TAG; use crate::items::TurnItem; use crate::message_history::HistoryEntry; use crate::models::ContentItem; @@ -45,14 +51,6 @@ pub use crate::approvals::ElicitationAction; pub use crate::approvals::ExecApprovalRequestEvent; pub use crate::approvals::ExecPolicyAmendment; -/// Open/close tags for special user-input blocks. Used across crates to avoid -/// duplicated hardcoded strings. -pub const USER_INSTRUCTIONS_OPEN_TAG: &str = ""; -pub const USER_INSTRUCTIONS_CLOSE_TAG: &str = ""; -pub const ENVIRONMENT_CONTEXT_OPEN_TAG: &str = ""; -pub const ENVIRONMENT_CONTEXT_CLOSE_TAG: &str = ""; -pub const COLLABORATION_MODE_OPEN_TAG: &str = ""; -pub const COLLABORATION_MODE_CLOSE_TAG: &str = ""; pub const USER_MESSAGE_BEGIN: &str = "## My request for Codex:"; /// Submission Queue Entry - requests from user