Add turn-scoped context contributions (#28911)

## Summary
- keep context injection on a single ContextContributor trait
- split context injection into thread-scoped and turn-scoped
contribution methods
- wire turn-scoped fragments into initial context assembly so extensions
can contribute context from turn-local state
This commit is contained in:
jif
2026-06-18 18:40:28 +01:00
committed by GitHub
Unverified
parent 790213ded0
commit 9684ec25be
14 changed files with 307 additions and 33 deletions
+26 -2
View File
@@ -11,6 +11,7 @@ use codex_tools::ToolExecutor;
use crate::ExtensionData;
mod context;
mod mcp;
mod prompt;
mod thread_lifecycle;
@@ -18,6 +19,7 @@ mod tool_lifecycle;
mod turn_input;
mod turn_lifecycle;
pub use context::TurnContextContributionInput;
pub use mcp::McpServerContribution;
pub use mcp::McpServerContributionContext;
pub use prompt::PromptFragment;
@@ -62,12 +64,34 @@ pub trait McpServerContributor<C: Sync>: Send + Sync {
}
/// Extension contribution that adds prompt fragments during prompt assembly.
///
/// Implementations should use the method matching the scope needed by the
/// fragment: thread/session context for stable inputs, and turn context for
/// fragments that depend on turn-local host state.
pub trait ContextContributor: Send + Sync {
fn contribute<'a>(
fn contribute_thread_context<'a>(
&'a self,
session_store: &'a ExtensionData,
thread_store: &'a ExtensionData,
) -> ExtensionFuture<'a, Vec<PromptFragment>>;
) -> ExtensionFuture<'a, Vec<PromptFragment>> {
Box::pin(async move {
let _self = self;
let _session_store = session_store;
let _thread_store = thread_store;
Vec::new()
})
}
fn contribute_turn_context<'a>(
&'a self,
input: TurnContextContributionInput<'a>,
) -> ExtensionFuture<'a, Vec<PromptFragment>> {
Box::pin(async move {
let _self = self;
let _input = input;
Vec::new()
})
}
}
/// Contributor for host-owned thread lifecycle gates.
@@ -0,0 +1,20 @@
use codex_protocol::ThreadId;
use crate::ExtensionData;
/// Host context available while extensions contribute turn-scoped context fragments.
#[derive(Clone, Copy)]
pub struct TurnContextContributionInput<'a> {
/// Stable host-owned thread identifier.
pub thread_id: ThreadId,
/// Stable host-owned turn identifier.
pub turn_id: &'a str,
/// Store scoped to the host session runtime.
pub session_store: &'a ExtensionData,
/// Store scoped to this thread runtime.
pub thread_store: &'a ExtensionData,
/// Store scoped to this turn.
pub turn_store: &'a ExtensionData,
/// Effective model context window for this turn, when known.
pub model_context_window: Option<i64>,
}
+1
View File
@@ -54,6 +54,7 @@ pub use contributors::ToolLifecycleContributor;
pub use contributors::ToolLifecycleFuture;
pub use contributors::ToolStartInput;
pub use contributors::TurnAbortInput;
pub use contributors::TurnContextContributionInput;
pub use contributors::TurnErrorInput;
pub use contributors::TurnInputContext;
pub use contributors::TurnInputContributor;