Move trusted tool metadata into shared Guardian context (#43597)

## What changed

Represent host-verified tool metadata as `TrustedTool` in `codex-guardian-context` and collect it through an async-only context section. Route Guardian v2 sampling through that section while preserving separate developer-message delivery and the 512-token rendering budget. Omit tool metadata from debug output.

## Testing

Move the rendering-budget test into the shared crate, extend registry coverage for async-only collection and debug redaction, and narrow the scoped approval test to messages tagged `guardian.trusted_tool`.

GitOrigin-RevId: ee7cb4e9b9ceced70438cb58060d1a2973e1dc6a
This commit is contained in:
felixxia-oai authored and copyberry committed 2026-09-07 21:29:31 +00:00
1 parent 0b9b5ecff3
commit 2554239561
16 files changed
+426 -302

No files matched your search

@@ -0,0 +1,20 @@
use super::MAX_TRUSTED_TOOL_CONTEXT_TOKENS;
use super::TRUSTED_TOOL_PREFIX;
use super::TrustedTool;
use codex_context_fragments::ContextualUserFragment;
use codex_protocol::protocol::TruncationPolicy;
#[test]
fn trusted_tool_context_has_a_hard_token_budget() {
let fragment = TrustedTool {
server: "server".into(),
connector_id: None,
source: "unbounded instructions ".repeat(1_000),
};
let context = fragment.render();
assert!(context.starts_with(TRUSTED_TOOL_PREFIX));
assert!(
context.len() <= TruncationPolicy::Tokens(MAX_TRUSTED_TOOL_CONTEXT_TOKENS).byte_budget()
);
assert!(context.contains("<truncated omitted_approx_tokens="));
}