mirror of
https://github.com/openai/codex.git
synced 2026-05-26 05:55:36 +00:00
## Why `ContextualUserFragment` needs to be usable behind `dyn` for render-only paths, but associated constants made the trait non-object-safe. ## What changed - Replaced associated constants with trait methods so `dyn ContextualUserFragment` can render fragments. - Preserved the existing typed `T::matches_text(text)` registration pattern via `type_markers()`. - Kept default `render()` on the main trait so implementations only provide role, markers, and body. - Added unit coverage for rendering a `Box<dyn ContextualUserFragment>`. ## Verification - `cargo test -p codex-core contextual_user_fragment_is_dyn_compatible` - `just fix -p codex-core`
43 lines
1015 B
Rust
43 lines
1015 B
Rust
use codex_protocol::protocol::AgentStatus;
|
|
|
|
use super::ContextualUserFragment;
|
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
|
pub(crate) struct SubagentNotification {
|
|
pub(crate) agent_reference: String,
|
|
pub(crate) status: AgentStatus,
|
|
}
|
|
|
|
impl SubagentNotification {
|
|
pub(crate) fn new(agent_reference: impl Into<String>, status: AgentStatus) -> Self {
|
|
Self {
|
|
agent_reference: agent_reference.into(),
|
|
status,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl ContextualUserFragment for SubagentNotification {
|
|
fn role() -> &'static str {
|
|
"user"
|
|
}
|
|
|
|
fn markers(&self) -> (&'static str, &'static str) {
|
|
Self::type_markers()
|
|
}
|
|
|
|
fn type_markers() -> (&'static str, &'static str) {
|
|
("<subagent_notification>", "</subagent_notification>")
|
|
}
|
|
|
|
fn body(&self) -> String {
|
|
format!(
|
|
"\n{}\n",
|
|
serde_json::json!({
|
|
"agent_path": &self.agent_reference,
|
|
"status": &self.status,
|
|
})
|
|
)
|
|
}
|
|
}
|