mirror of
https://github.com/openai/codex.git
synced 2026-11-25 23:30:49 +00:00
## Why Trusted classifier evidence needs to fit configured entry limits while preserving complete records and metadata that reflects only delivered reviews. ## What changed Apply elastic caps before rendering trusted tools, trusted skills, and previous reviews into developer messages. Omit oversized tool attestations and review fragments whole, retain only complete skill paths that fit, and record omissions for the request's omission notice. Keep review IDs aligned with retained fragments and preserve fixed-budget behavior. ## Testing Add coverage for whole-record omissions, retained review IDs, and omission notices. Exercise orchestrator connector evidence with both fixed budgeting and an elastic tool entry cap. GitOrigin-RevId: 729db452026f93b59765a3936730b9b6dddfcf9a
105 lines
3.1 KiB
Rust
105 lines
3.1 KiB
Rust
//! Bounded rendering of host-verified invoked skill paths for async review.
|
|
//! Ownership checks, turn storage and delegated evidence selection stay in the host.
|
|
|
|
use crate::ContextSection;
|
|
use crate::SectionContributor;
|
|
use crate::SectionError;
|
|
use crate::SectionInput;
|
|
use crate::SectionScope;
|
|
use codex_context_fragments::ContextualUserFragment;
|
|
use codex_protocol::models::ContentItem;
|
|
use codex_protocol::models::ContentItemKind;
|
|
use codex_protocol::models::input_text;
|
|
use codex_protocol::protocol::TruncationPolicy;
|
|
use serde_json::json;
|
|
|
|
const MAX_TRUSTED_SKILL_TOKENS: usize = 768;
|
|
const TRUSTED_SKILLS_PREFIX: &str = "Codex-verified invoked user-owned skill paths:\n";
|
|
|
|
/// Host-verified user-owned skill paths for the current Guardian classification.
|
|
#[derive(Clone, PartialEq, Eq)]
|
|
pub struct TrustedSkills {
|
|
pub paths: Vec<String>,
|
|
}
|
|
|
|
impl TrustedSkills {
|
|
/// Classification attached to this fragment's rendered text.
|
|
pub const KIND: &str = "guardian.trusted_skills";
|
|
|
|
pub(crate) fn render_paths(&self) -> (ContentItem, usize) {
|
|
let mut paths = String::from("[");
|
|
let mut count = 0;
|
|
let max_path_bytes = TruncationPolicy::Tokens(MAX_TRUSTED_SKILL_TOKENS)
|
|
.byte_budget()
|
|
.saturating_sub(TRUSTED_SKILLS_PREFIX.len());
|
|
for path in &self.paths {
|
|
let separator = if paths.ends_with('[') { "" } else { "," };
|
|
let encoded_path = json!(path).to_string();
|
|
if paths
|
|
.len()
|
|
.saturating_add(separator.len())
|
|
.saturating_add(encoded_path.len())
|
|
.saturating_add(1)
|
|
> max_path_bytes
|
|
{
|
|
continue;
|
|
}
|
|
paths.push_str(separator);
|
|
paths.push_str(&encoded_path);
|
|
count += 1;
|
|
}
|
|
paths.push(']');
|
|
(input_text(format!("{TRUSTED_SKILLS_PREFIX}{paths}")), count)
|
|
}
|
|
}
|
|
|
|
impl ContextualUserFragment for TrustedSkills {
|
|
fn content_kind(&self) -> ContentItemKind {
|
|
ContentItemKind(Self::KIND.to_owned())
|
|
}
|
|
|
|
fn role(&self) -> &'static str {
|
|
"developer"
|
|
}
|
|
|
|
fn markers(&self) -> (&'static str, &'static str) {
|
|
Self::type_markers()
|
|
}
|
|
|
|
fn type_markers() -> (&'static str, &'static str) {
|
|
("", "")
|
|
}
|
|
|
|
fn body(&self) -> ContentItem {
|
|
self.render_paths().0
|
|
}
|
|
}
|
|
|
|
impl std::fmt::Debug for TrustedSkills {
|
|
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
formatter
|
|
.debug_struct("TrustedSkills")
|
|
.field("count", &self.paths.len())
|
|
.finish_non_exhaustive()
|
|
}
|
|
}
|
|
|
|
pub(crate) struct TrustedSkillsSection;
|
|
|
|
impl SectionContributor for TrustedSkillsSection {
|
|
fn scope(&self) -> SectionScope {
|
|
SectionScope::AsyncOnly
|
|
}
|
|
fn contribute(&self, input: &SectionInput<'_>) -> Result<Option<ContextSection>, SectionError> {
|
|
Ok((!input.trusted_skill_paths.is_empty()).then(|| {
|
|
ContextSection::TrustedSkills(TrustedSkills {
|
|
paths: input.trusted_skill_paths.to_vec(),
|
|
})
|
|
}))
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
#[path = "trusted_skills_tests.rs"]
|
|
mod tests;
|