Support window prefixes for extension world-state sections (#57276)

## What changed

Add `WorldStateSectionContribution::with_window_prefix()` to render extension developer fragments as separate messages before retained history when building a context window, including after compaction. Updates within an existing window still append to history. Ignore fragments with other roles for sections that opt in.

## Testing

Add a unit test for prefix placement and duplicate avoidance, plus local and remote compaction scenarios covering live updates, persisted replacement history, and rejection of non-developer fragments.

GitOrigin-RevId: 8621457c6eec17f1585ca8e6fa154b1bf3257330
This commit is contained in:
Francis Chalissery
2026-10-26 21:46:26 +00:00
committed by copyberry
parent 166aed9854
commit d416d8a0ff
7 changed files with 928 additions and 2 deletions
+11 -2
View File
@@ -247,11 +247,20 @@ impl ErasedWorldStateSection for ExtensionWorldStateSection {
});
let updates = fragment
.into_iter()
.filter(|fragment| !self.0.is_window_prefix() || fragment.role() == "developer")
.map(|fragment| {
WorldStateUpdate::fragment(WorldStateContextFragment {
let update = WorldStateUpdate::fragment(WorldStateContextFragment {
fragment,
content_kind: ContentItemKind(format!("{}.instructions", self.0.id())),
})
});
if self.0.is_window_prefix() {
WorldStateUpdate {
placement: Placement::Prefix,
..update
}
} else {
update
}
})
.collect();
(snapshot, updates)