Files
codex/codex-rs/core/src/context/memory.rs
T
jif e7f5de0a6a Move v2 extraction chunking into the memory writer (#43808)
Move `extraction_messages` from `MemoryContextFragment` in `codex-core` to
`codex-rs/memories/write/src/rollout_input.rs` and update the phase-one caller.
Preserve the existing 8,900-byte chunk limit and Unicode-safe boundaries.

Move the accompanying test with the helper, retaining coverage that bounded
user messages reconstruct the original evidence without loss.

GitOrigin-RevId: 48ac501acbfa50c4195195fd40efc7588a6c714d
2026-09-08 12:46:39 +00:00

44 lines
1.3 KiB
Rust

//! Typed, bounded v2 memory context.
use super::ContextualUserFragment;
use codex_protocol::models::ContentItemKind;
use codex_utils_output_truncation::TruncationPolicy;
use codex_utils_output_truncation::truncate_text;
/// Memory-owned model context, capped below 10k tokens even for byte-heavy text.
pub enum MemoryContextFragment {
ReadInstructions(String),
ExtractionEvidence(String),
}
impl ContextualUserFragment for MemoryContextFragment {
fn role(&self) -> &'static str {
match self {
Self::ReadInstructions(_) => "developer",
Self::ExtractionEvidence(_) => "user",
}
}
fn content_kind(&self) -> ContentItemKind {
ContentItemKind(
match self {
Self::ReadInstructions(_) => "memories.instructions",
Self::ExtractionEvidence(_) => "memories.extraction_evidence",
}
.to_string(),
)
}
fn requires_separate_message(&self) -> bool {
true
}
fn markers(&self) -> (&'static str, &'static str) {
Self::type_markers()
}
fn type_markers() -> (&'static str, &'static str) {
("", "")
}
fn body(&self) -> String {
let (Self::ReadInstructions(text) | Self::ExtractionEvidence(text)) = self;
truncate_text(text, TruncationPolicy::Bytes(8_900))
}
}