From bffe9b33e9729fa981c14c0aa4dfae32f2746aa2 Mon Sep 17 00:00:00 2001 From: Dylan Hurd Date: Sat, 17 Jan 2026 16:01:26 -0800 Subject: [PATCH] chore(core) Create instructions module (#9422) ## Summary We have a variety of things we refer to as instructions in the code base: our current canonical terms are: - base instructions (raw string) - developer instructions (has a type in protocol) - user instructions We also have `instructions` floating around in various places. We should standardize on the above, and start using types to prevent them from ending up in the wrong place. There will be additional PRs, but I'm going to keep these small so we can easily follow them! ## Testing - [x] Tests pass, this is purely a file move --- codex-rs/core/src/codex.rs | 2 +- codex-rs/core/src/context_manager/history.rs | 4 ++-- codex-rs/core/src/event_mapping.rs | 4 ++-- codex-rs/core/src/instructions/mod.rs | 6 ++++++ codex-rs/core/src/{ => instructions}/user_instructions.rs | 0 codex-rs/core/src/lib.rs | 2 +- codex-rs/core/src/skills/injection.rs | 2 +- 7 files changed, 13 insertions(+), 7 deletions(-) create mode 100644 codex-rs/core/src/instructions/mod.rs rename codex-rs/core/src/{ => instructions}/user_instructions.rs (100%) diff --git a/codex-rs/core/src/codex.rs b/codex-rs/core/src/codex.rs index a9dc1004a..48c689e64 100644 --- a/codex-rs/core/src/codex.rs +++ b/codex-rs/core/src/codex.rs @@ -98,6 +98,7 @@ use crate::error::Result as CodexResult; use crate::exec::StreamOutput; use crate::exec_policy::ExecPolicyUpdateError; use crate::feedback_tags; +use crate::instructions::UserInstructions; use crate::mcp::auth::compute_auth_statuses; use crate::mcp_connection_manager::McpConnectionManager; use crate::model_provider_info::CHAT_WIRE_API_DEPRECATION_SUMMARY; @@ -155,7 +156,6 @@ use crate::tools::spec::ToolsConfig; use crate::tools::spec::ToolsConfigParams; use crate::turn_diff_tracker::TurnDiffTracker; use crate::unified_exec::UnifiedExecProcessManager; -use crate::user_instructions::UserInstructions; use crate::user_notification::UserNotification; use crate::util::backoff; use codex_async_utils::OrCancelExt; diff --git a/codex-rs/core/src/context_manager/history.rs b/codex-rs/core/src/context_manager/history.rs index 2279beef2..0c133bdc2 100644 --- a/codex-rs/core/src/context_manager/history.rs +++ b/codex-rs/core/src/context_manager/history.rs @@ -1,12 +1,12 @@ use crate::codex::TurnContext; use crate::context_manager::normalize; +use crate::instructions::SkillInstructions; +use crate::instructions::UserInstructions; use crate::truncate::TruncationPolicy; use crate::truncate::approx_token_count; use crate::truncate::approx_tokens_from_byte_count; use crate::truncate::truncate_function_output_items_with_policy; use crate::truncate::truncate_text; -use crate::user_instructions::SkillInstructions; -use crate::user_instructions::UserInstructions; use crate::user_shell_command::is_user_shell_command_text; use codex_protocol::models::ContentItem; use codex_protocol::models::FunctionCallOutputContentItem; diff --git a/codex-rs/core/src/event_mapping.rs b/codex-rs/core/src/event_mapping.rs index 6c19c726d..eaa477b08 100644 --- a/codex-rs/core/src/event_mapping.rs +++ b/codex-rs/core/src/event_mapping.rs @@ -17,8 +17,8 @@ use codex_protocol::user_input::UserInput; use tracing::warn; use uuid::Uuid; -use crate::user_instructions::SkillInstructions; -use crate::user_instructions::UserInstructions; +use crate::instructions::SkillInstructions; +use crate::instructions::UserInstructions; use crate::user_shell_command::is_user_shell_command_text; fn is_session_prefix(text: &str) -> bool { diff --git a/codex-rs/core/src/instructions/mod.rs b/codex-rs/core/src/instructions/mod.rs new file mode 100644 index 000000000..9da925ac7 --- /dev/null +++ b/codex-rs/core/src/instructions/mod.rs @@ -0,0 +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_PREFIX; +pub(crate) use user_instructions::UserInstructions; diff --git a/codex-rs/core/src/user_instructions.rs b/codex-rs/core/src/instructions/user_instructions.rs similarity index 100% rename from codex-rs/core/src/user_instructions.rs rename to codex-rs/core/src/instructions/user_instructions.rs diff --git a/codex-rs/core/src/lib.rs b/codex-rs/core/src/lib.rs index e5a21b051..a23ae55aa 100644 --- a/codex-rs/core/src/lib.rs +++ b/codex-rs/core/src/lib.rs @@ -31,6 +31,7 @@ mod exec_policy; pub mod features; mod flags; pub mod git_info; +pub mod instructions; pub mod landlock; pub mod mcp; mod mcp_connection_manager; @@ -50,7 +51,6 @@ mod text_encoding; pub mod token_data; mod truncate; mod unified_exec; -mod user_instructions; pub mod windows_sandbox; pub use model_provider_info::CHAT_WIRE_API_DEPRECATION_SUMMARY; pub use model_provider_info::DEFAULT_LMSTUDIO_PORT; diff --git a/codex-rs/core/src/skills/injection.rs b/codex-rs/core/src/skills/injection.rs index dfd7e2af5..ffe879bcd 100644 --- a/codex-rs/core/src/skills/injection.rs +++ b/codex-rs/core/src/skills/injection.rs @@ -1,9 +1,9 @@ use std::collections::HashSet; use std::path::PathBuf; +use crate::instructions::SkillInstructions; use crate::skills::SkillLoadOutcome; use crate::skills::SkillMetadata; -use crate::user_instructions::SkillInstructions; use codex_protocol::models::ResponseItem; use codex_protocol::user_input::UserInput; use tokio::fs;