From c875bc8a333eb492b104d8c9abb2bf4cbde195b7 Mon Sep 17 00:00:00 2001 From: jif-oai Date: Mon, 1 Jun 2026 10:55:14 +0200 Subject: [PATCH] Use templates for goal steering prompts (#25576) ## Why Goal steering prompts have grown into long inline Rust strings, which makes the authored prompt text hard to review and easy to damage while changing the surrounding plumbing. Moving those prompts into embedded Markdown templates keeps the policy text in the shape reviewers actually read, while preserving the existing runtime substitution and objective escaping behavior. ## What changed - Added `ext/goal/templates/goals/continuation.md`, `budget_limit.md`, and `objective_updated.md` for the three goal steering prompts. - Updated `ext/goal/src/steering.rs` to parse those embedded templates once with `codex-utils-template` and render the existing goal values into them. - Kept user objectives XML-escaped before rendering and converted budget counters into template variables. - Added the template directory to `ext/goal/BUILD.bazel` `compile_data` so Bazel has the same embedded prompt inputs as Cargo. ## Testing - Not run locally. --- codex-rs/Cargo.lock | 1 + codex-rs/ext/goal/BUILD.bazel | 3 + codex-rs/ext/goal/Cargo.toml | 1 + codex-rs/ext/goal/src/steering.rs | 136 +++++++++--------- .../ext/goal/templates/goals/budget_limit.md | 16 +++ .../ext/goal/templates/goals/continuation.md | 51 +++++++ .../goal/templates/goals/objective_updated.md | 16 +++ 7 files changed, 152 insertions(+), 72 deletions(-) create mode 100644 codex-rs/ext/goal/templates/goals/budget_limit.md create mode 100644 codex-rs/ext/goal/templates/goals/continuation.md create mode 100644 codex-rs/ext/goal/templates/goals/objective_updated.md diff --git a/codex-rs/Cargo.lock b/codex-rs/Cargo.lock index 2eeafe30b9..710a57bc14 100644 --- a/codex-rs/Cargo.lock +++ b/codex-rs/Cargo.lock @@ -2985,6 +2985,7 @@ dependencies = [ "codex-protocol", "codex-state", "codex-tools", + "codex-utils-template", "pretty_assertions", "serde", "serde_json", diff --git a/codex-rs/ext/goal/BUILD.bazel b/codex-rs/ext/goal/BUILD.bazel index 05b80c3706..e13276ddd5 100644 --- a/codex-rs/ext/goal/BUILD.bazel +++ b/codex-rs/ext/goal/BUILD.bazel @@ -3,5 +3,8 @@ load("//:defs.bzl", "codex_rust_crate") codex_rust_crate( name = "goal", crate_name = "codex_goal_extension", + compile_data = glob([ + "templates/**", + ]), integration_compile_data_extra = ["src/accounting.rs"], ) diff --git a/codex-rs/ext/goal/Cargo.toml b/codex-rs/ext/goal/Cargo.toml index 3bf0eca8d5..667ed5d14d 100644 --- a/codex-rs/ext/goal/Cargo.toml +++ b/codex-rs/ext/goal/Cargo.toml @@ -21,6 +21,7 @@ codex-otel = { workspace = true } codex-protocol = { workspace = true } codex-state = { workspace = true } codex-tools = { workspace = true } +codex-utils-template = { workspace = true } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } tracing = { workspace = true } diff --git a/codex-rs/ext/goal/src/steering.rs b/codex-rs/ext/goal/src/steering.rs index 09b0a9c0ba..6615b6edaa 100644 --- a/codex-rs/ext/goal/src/steering.rs +++ b/codex-rs/ext/goal/src/steering.rs @@ -3,6 +3,36 @@ use codex_core::context::InternalContextSource; use codex_core::context::InternalModelContextFragment; use codex_protocol::models::ResponseItem; use codex_protocol::protocol::ThreadGoal; +use codex_utils_template::Template; +use std::sync::LazyLock; + +static CONTINUATION_PROMPT_TEMPLATE: LazyLock