Centralize Guardian transcript policy in context profiles (#43806)

## What changed

Add `ContextProfile` to `codex-guardian-context` and route synchronous and asynchronous Guardian transcript rendering through it. Move default limits, retention, formatting, and async chunked eviction into the shared crate while preserving the distinct retention policies and host-managed full/delta cursors.

Carry transcript truncation observations through `RenderedTranscript` into context composition, and derive async image collection flags from the resolved profile.

## Testing

Add a profile regression test covering distinct sync/async retention priorities, original entry numbering, omission notes, and async truncation observations. Adapt existing transcript tests to the updated input API.

GitOrigin-RevId: 7f7dc249629d8017e9547085f6617f815ae43a1b
This commit is contained in:
felixxia-oai authored and copyberry committed 2026-09-08 12:17:28 +00:00
1 parent 0034ef93a7
commit 0337192dfd
11 files changed
+412 -358

No files matched your search

@@ -0,0 +1,61 @@
//! Profile retention keeps the existing sync and async evidence priorities.
use super::*;
use pretty_assertions::assert_eq;
#[test]
fn profiles_preserve_distinct_retention_and_original_numbering() {
let entries = [
(ConversationTranscriptEntryKind::User, "inspect only"),
(
ConversationTranscriptEntryKind::Developer,
"approved action",
),
(ConversationTranscriptEntryKind::Assistant, "working"),
]
.into_iter()
.map(|(kind, text)| ConversationTranscriptEntry {
kind,
text: text.to_owned(),
original_bytes: text.len(),
})
.collect::<Vec<_>>();
let mut sync = ContextProfile::synchronous();
sync.retention.max_recent_non_user_entries = 1;
let mut asynchronous = ContextProfile::asynchronous();
asynchronous.retention.max_recent_non_user_entries = 1;
let sync = sync.render_transcript(&entries, /*entry_number_offset*/ 7);
let asynchronous = asynchronous.render_transcript(&entries, /*entry_number_offset*/ 0);
assert_eq!(
(sync.items, sync.omission_note),
(
vec![
"[8] user: inspect only".to_owned(),
"[10] assistant: working".to_owned()
],
Some("Some conversation entries were omitted.".to_owned()),
),
);
assert_eq!(
(asynchronous.items, asynchronous.omission_note),
(
vec![
"[1] user: inspect only\n".to_owned(),
"[2] developer: approved action\n".to_owned()
],
None,
),
);
assert_eq!(
asynchronous
.truncations
.into_iter()
.map(|observation| (
observation.component,
observation.original_bytes,
observation.retained_bytes,
))
.collect::<Vec<_>>(),
vec![("transcript_message", "working".len(), 0)],
);
}