diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 322aad46f4..668897c48e 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,6 +1,7 @@ # Core crate ownership. /codex-rs/core/ @openai/codex-core-agent-team /codex-rs/ext/extension-api/ @openai/codex-core-agent-team +/codex-rs/prompts/ @openai/codex-core-agent-team # Keep ownership changes reviewed by the same team. /.github/CODEOWNERS @openai/codex-core-agent-team diff --git a/codex-rs/Cargo.lock b/codex-rs/Cargo.lock index c5b165d98f..745feb93be 100644 --- a/codex-rs/Cargo.lock +++ b/codex-rs/Cargo.lock @@ -2550,6 +2550,7 @@ dependencies = [ "codex-network-proxy", "codex-otel", "codex-plugin", + "codex-prompts", "codex-protocol", "codex-response-debug-context", "codex-rmcp-client", @@ -2574,7 +2575,6 @@ dependencies = [ "codex-utils-pty", "codex-utils-stream-parser", "codex-utils-string", - "codex-utils-template", "codex-windows-sandbox", "core_test_support", "csv", @@ -3453,6 +3453,19 @@ dependencies = [ "pretty_assertions", ] +[[package]] +name = "codex-prompts" +version = "0.0.0" +dependencies = [ + "anyhow", + "codex-execpolicy", + "codex-git-utils", + "codex-protocol", + "codex-utils-absolute-path", + "codex-utils-template", + "pretty_assertions", +] + [[package]] name = "codex-protocol" version = "0.0.0" diff --git a/codex-rs/Cargo.toml b/codex-rs/Cargo.toml index a56caad775..f0c9b601f9 100644 --- a/codex-rs/Cargo.toml +++ b/codex-rs/Cargo.toml @@ -68,6 +68,7 @@ members = [ "process-hardening", "protocol", "realtime-webrtc", + "prompts", "rollout", "rollout-trace", "rmcp-client", @@ -197,6 +198,7 @@ codex-model-provider = { path = "model-provider" } codex-process-hardening = { path = "process-hardening" } codex-protocol = { path = "protocol" } codex-realtime-webrtc = { path = "realtime-webrtc" } +codex-prompts = { path = "prompts" } codex-responses-api-proxy = { path = "responses-api-proxy" } codex-response-debug-context = { path = "response-debug-context" } codex-rmcp-client = { path = "rmcp-client" } diff --git a/codex-rs/apply-patch/BUILD.bazel b/codex-rs/apply-patch/BUILD.bazel index e68984bc37..b43e8ed6aa 100644 --- a/codex-rs/apply-patch/BUILD.bazel +++ b/codex-rs/apply-patch/BUILD.bazel @@ -1,11 +1,6 @@ load("//:defs.bzl", "codex_rust_crate") -exports_files(["apply_patch_tool_instructions.md"]) - codex_rust_crate( name = "apply-patch", crate_name = "codex_apply_patch", - compile_data = [ - "apply_patch_tool_instructions.md", - ], ) diff --git a/codex-rs/apply-patch/src/lib.rs b/codex-rs/apply-patch/src/lib.rs index 4e79141aab..29d42e1c07 100644 --- a/codex-rs/apply-patch/src/lib.rs +++ b/codex-rs/apply-patch/src/lib.rs @@ -31,9 +31,6 @@ pub use standalone_executable::main; use crate::invocation::ExtractHeredocError; -/// Detailed instructions for gpt-4.1 on how to use the `apply_patch` tool. -pub const APPLY_PATCH_TOOL_INSTRUCTIONS: &str = include_str!("../apply_patch_tool_instructions.md"); - /// Special argv[1] flag used when the Codex executable self-invokes to run the /// internal `apply_patch` path. /// diff --git a/codex-rs/core/BUILD.bazel b/codex-rs/core/BUILD.bazel index 361e958e86..478699c0a1 100644 --- a/codex-rs/core/BUILD.bazel +++ b/codex-rs/core/BUILD.bazel @@ -17,10 +17,6 @@ codex_rust_crate( # that relies on env!("CARGO_MANIFEST_DIR"). "CARGO_MANIFEST_DIR": "codex-rs/core", }, - integration_compile_data_extra = [ - "//codex-rs/apply-patch:apply_patch_tool_instructions.md", - "templates/realtime/backend_prompt.md", - ], integration_test_timeout = "long", test_data_extra = [ "config.schema.json", diff --git a/codex-rs/core/Cargo.toml b/codex-rs/core/Cargo.toml index a51c3db7ca..4f6ab2e777 100644 --- a/codex-rs/core/Cargo.toml +++ b/codex-rs/core/Cargo.toml @@ -54,6 +54,7 @@ codex-plugin = { workspace = true } codex-model-provider = { workspace = true } codex-protocol = { workspace = true } codex-response-debug-context = { workspace = true } +codex-prompts = { workspace = true } codex-rollout = { workspace = true } codex-rollout-trace = { workspace = true } codex-rmcp-client = { workspace = true } @@ -72,7 +73,6 @@ codex-utils-plugins = { workspace = true } codex-utils-pty = { workspace = true } codex-utils-string = { workspace = true } codex-utils-stream-parser = { workspace = true } -codex-utils-template = { workspace = true } codex-windows-sandbox = { package = "codex-windows-sandbox", path = "../windows-sandbox-rs" } csv = { workspace = true } dirs = { workspace = true } diff --git a/codex-rs/core/src/agents_md.rs b/codex-rs/core/src/agents_md.rs index 6daaff4a40..8048552480 100644 --- a/codex-rs/core/src/agents_md.rs +++ b/codex-rs/core/src/agents_md.rs @@ -25,15 +25,13 @@ use codex_exec_server::Environment; use codex_exec_server::ExecutorFileSystem; use codex_exec_server::LOCAL_FS; use codex_features::Feature; +use codex_prompts::HIERARCHICAL_AGENTS_MESSAGE; use codex_utils_absolute_path::AbsolutePathBuf; use dunce::canonicalize as normalize_path; use std::io; use toml::Value as TomlValue; use tracing::error; -pub(crate) const HIERARCHICAL_AGENTS_MESSAGE: &str = - include_str!("../hierarchical_agents_message.md"); - /// Default filename scanned for AGENTS.md instructions. pub const DEFAULT_AGENTS_MD_FILENAME: &str = "AGENTS.md"; /// Preferred local override for AGENTS.md instructions. diff --git a/codex-rs/core/src/client_common.rs b/codex-rs/core/src/client_common.rs index d9edadbed4..d775f9c01c 100644 --- a/codex-rs/core/src/client_common.rs +++ b/codex-rs/core/src/client_common.rs @@ -12,14 +12,6 @@ use std::task::Poll; use tokio::sync::mpsc; use tokio_util::sync::CancellationToken; -/// Review thread system prompt. Edit `core/src/review_prompt.md` to customize. -pub const REVIEW_PROMPT: &str = include_str!("../review_prompt.md"); - -// Centralized templates for review-related user messages -pub const REVIEW_EXIT_SUCCESS_TMPL: &str = include_str!("../templates/review/exit_success.xml"); -pub const REVIEW_EXIT_INTERRUPTED_TMPL: &str = - include_str!("../templates/review/exit_interrupted.xml"); - /// API request payload for a single model turn #[derive(Debug, Clone)] pub struct Prompt { diff --git a/codex-rs/core/src/compact.rs b/codex-rs/core/src/compact.rs index fd388b273c..11386e6bcd 100644 --- a/codex-rs/core/src/compact.rs +++ b/codex-rs/core/src/compact.rs @@ -44,8 +44,8 @@ use tracing::error; use codex_model_provider_info::ModelProviderInfo; -pub const SUMMARIZATION_PROMPT: &str = include_str!("../templates/compact/prompt.md"); -pub const SUMMARY_PREFIX: &str = include_str!("../templates/compact/summary_prefix.md"); +pub use codex_prompts::SUMMARIZATION_PROMPT; +pub use codex_prompts::SUMMARY_PREFIX; const COMPACT_USER_MESSAGE_MAX_TOKENS: usize = 20_000; /// Controls whether compaction replacement history must include initial context. diff --git a/codex-rs/core/src/context/permissions_instructions.rs b/codex-rs/core/src/context/permissions_instructions.rs index e87dceec01..513390d592 100644 --- a/codex-rs/core/src/context/permissions_instructions.rs +++ b/codex-rs/core/src/context/permissions_instructions.rs @@ -1,164 +1,6 @@ use super::ContextualUserFragment; -use codex_execpolicy::Policy; -use codex_protocol::config_types::ApprovalsReviewer; -use codex_protocol::config_types::SandboxMode; -use codex_protocol::models::PermissionProfile; -use codex_protocol::models::format_allow_prefixes; -use codex_protocol::permissions::FileSystemSandboxPolicy; -use codex_protocol::permissions::NetworkSandboxPolicy; -use codex_protocol::protocol::AskForApproval; -use codex_protocol::protocol::GranularApprovalConfig; -use codex_protocol::protocol::NetworkAccess; -use codex_protocol::protocol::WritableRoot; -use codex_utils_template::Template; -use std::path::Path; -use std::sync::LazyLock; -const APPROVAL_POLICY_NEVER: &str = include_str!("prompts/permissions/approval_policy/never.md"); -const APPROVAL_POLICY_UNLESS_TRUSTED: &str = - include_str!("prompts/permissions/approval_policy/unless_trusted.md"); -const APPROVAL_POLICY_ON_FAILURE: &str = - include_str!("prompts/permissions/approval_policy/on_failure.md"); -const APPROVAL_POLICY_ON_REQUEST_RULE: &str = - include_str!("prompts/permissions/approval_policy/on_request.md"); -const APPROVAL_POLICY_ON_REQUEST_RULE_REQUEST_PERMISSION: &str = - include_str!("prompts/permissions/approval_policy/on_request_rule_request_permission.md"); -const AUTO_REVIEW_APPROVAL_SUFFIX: &str = "`approvals_reviewer` is `auto_review`: Sandbox escalations with require_escalated will be reviewed for compliance with the policy. If a rejection happens, you should proceed only with a materially safer alternative, or inform the user of the risk and send a final message to ask for approval."; - -const SANDBOX_MODE_DANGER_FULL_ACCESS: &str = - include_str!("prompts/permissions/sandbox_mode/danger_full_access.md"); -const SANDBOX_MODE_WORKSPACE_WRITE: &str = - include_str!("prompts/permissions/sandbox_mode/workspace_write.md"); -const SANDBOX_MODE_READ_ONLY: &str = include_str!("prompts/permissions/sandbox_mode/read_only.md"); - -static SANDBOX_MODE_DANGER_FULL_ACCESS_TEMPLATE: LazyLock