mirror of
https://github.com/openai/codex.git
synced 2026-11-17 22:10:37 +00:00
## What changed Move `GuardianToolDescriptions` into `codex-guardian-context` and carry structured tool and connector descriptions in `PlannedAction` instead of pre-rendered text. Prepare them during synchronous context composition, escaping closing tags before applying the existing 400-token limit to each source and rendering the untrusted-description fragment. Keep descriptions optional under the context budget and preserve the complete action JSON. Reject descriptions that reach rendering without preparation. ## Testing Strengthen the MCP approval integration test to assert the exact rendered descriptions, including independent truncation and escaped closing markers. Adapt the budget enforcement test to use structured descriptions. GitOrigin-RevId: 4a9f1855f2958758b4be711914c00e4d954cee39
56 lines
1.7 KiB
Rust
56 lines
1.7 KiB
Rust
//! Bounded, untrusted descriptions for the exact MCP action under review.
|
|
//! Sync preparation applies per-source limits before rendering.
|
|
|
|
use codex_context_fragments::ContextualUserFragment;
|
|
use codex_protocol::models::ContentItem;
|
|
use codex_protocol::models::ContentItemKind;
|
|
use codex_protocol::models::input_text;
|
|
|
|
/// Descriptions may be shortened or omitted without changing the required action.
|
|
#[derive(Clone, PartialEq)]
|
|
pub struct GuardianToolDescriptions {
|
|
// Empty until sync preparation; prepared framing is always nonempty.
|
|
pub(crate) text: String,
|
|
pub(crate) tool: String,
|
|
pub(crate) connector: String,
|
|
}
|
|
|
|
impl GuardianToolDescriptions {
|
|
/// Captures descriptions without shortening them; sync preparation applies their caps.
|
|
pub fn new(tool: Option<&str>, connector: Option<&str>) -> Option<Self> {
|
|
if tool.is_none() && connector.is_none() {
|
|
return None;
|
|
}
|
|
Some(Self {
|
|
text: String::new(),
|
|
tool: tool.unwrap_or_default().to_owned(),
|
|
connector: connector.unwrap_or_default().to_owned(),
|
|
})
|
|
}
|
|
}
|
|
|
|
impl ContextualUserFragment for GuardianToolDescriptions {
|
|
fn content_kind(&self) -> ContentItemKind {
|
|
ContentItemKind("guardian.tool_descriptions".to_owned())
|
|
}
|
|
|
|
fn role(&self) -> &'static str {
|
|
"user"
|
|
}
|
|
|
|
fn markers(&self) -> (&'static str, &'static str) {
|
|
Self::type_markers()
|
|
}
|
|
|
|
fn type_markers() -> (&'static str, &'static str) {
|
|
(
|
|
"<guardian_tool_descriptions>",
|
|
"</guardian_tool_descriptions>",
|
|
)
|
|
}
|
|
|
|
fn body(&self) -> ContentItem {
|
|
input_text(self.text.clone())
|
|
}
|
|
}
|