mirror of
https://github.com/openai/codex.git
synced 2026-11-13 21:30:47 +00:00
## What - Add a small extension capability for injecting model-visible response items into the active turn - Have the goal extension inject hidden goal-context steering when tool-finish accounting reaches `BudgetLimited` - Cover the extension backend path with an assertion on the injected steering item ## Why PR #23696 persists and emits the budget-limited goal update from tool-finish accounting, but it leaves the model unaware of that transition. The existing core runtime steers the model to wrap up in this case; the extension path should do the same through an explicit host capability. ## Testing - `just fmt` - `cargo test -p codex-goal-extension` - `cargo test -p codex-extension-api`
50 lines
1.3 KiB
Rust
50 lines
1.3 KiB
Rust
//! Hidden user-context fragment for runtime-owned goal steering prompts.
|
|
|
|
use super::ContextualUserFragment;
|
|
use codex_protocol::models::ContentItem;
|
|
use codex_protocol::models::ResponseInputItem;
|
|
|
|
/// Hidden runtime-owned goal steering context injected into model input.
|
|
#[derive(Debug, Clone, PartialEq)]
|
|
pub struct GoalContext {
|
|
prompt: String,
|
|
}
|
|
|
|
impl GoalContext {
|
|
/// Creates goal context around an already-rendered steering prompt.
|
|
pub fn new(prompt: impl Into<String>) -> Self {
|
|
Self {
|
|
prompt: prompt.into(),
|
|
}
|
|
}
|
|
|
|
/// Converts the registered fragment into an active-turn injectable item.
|
|
pub fn into_response_input_item(self) -> ResponseInputItem {
|
|
ResponseInputItem::Message {
|
|
role: <Self as ContextualUserFragment>::role().to_string(),
|
|
content: vec![ContentItem::InputText {
|
|
text: self.render(),
|
|
}],
|
|
phase: None,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl ContextualUserFragment for GoalContext {
|
|
fn role() -> &'static str {
|
|
"user"
|
|
}
|
|
|
|
fn markers(&self) -> (&'static str, &'static str) {
|
|
Self::type_markers()
|
|
}
|
|
|
|
fn type_markers() -> (&'static str, &'static str) {
|
|
("<goal_context>", "</goal_context>")
|
|
}
|
|
|
|
fn body(&self) -> String {
|
|
format!("\n{}\n", self.prompt)
|
|
}
|
|
}
|