mirror of
https://github.com/openai/codex.git
synced 2026-11-01 19:33:35 +00:00
Register hidden context markers from extensions
This commit is contained in:
@@ -17,3 +17,4 @@ workspace = true
|
||||
async-trait = { workspace = true }
|
||||
codex-protocol = { workspace = true }
|
||||
codex-tools = { workspace = true }
|
||||
inventory = { workspace = true }
|
||||
|
||||
@@ -18,6 +18,40 @@ impl HiddenContextMarker {
|
||||
end_marker,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns true when text is wrapped in this marker pair.
|
||||
pub fn matches_text(self, text: &str) -> bool {
|
||||
if self.start_marker.is_empty() || self.end_marker.is_empty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
let trimmed = text.trim_start();
|
||||
let starts_with_marker = trimmed
|
||||
.get(..self.start_marker.len())
|
||||
.is_some_and(|candidate| candidate.eq_ignore_ascii_case(self.start_marker));
|
||||
let trimmed = trimmed.trim_end();
|
||||
let ends_with_marker = trimmed
|
||||
.get(trimmed.len().saturating_sub(self.end_marker.len())..)
|
||||
.is_some_and(|candidate| candidate.eq_ignore_ascii_case(self.end_marker));
|
||||
starts_with_marker && ends_with_marker
|
||||
}
|
||||
}
|
||||
|
||||
/// Compile-time registration for extension-owned hidden context markers.
|
||||
///
|
||||
/// Extensions use this to reserve their hidden context wire tags without adding
|
||||
/// feature-specific tags to core parsing code.
|
||||
pub struct HiddenContextMarkerRegistration {
|
||||
pub marker: HiddenContextMarker,
|
||||
}
|
||||
|
||||
inventory::collect!(HiddenContextMarkerRegistration);
|
||||
|
||||
/// Returns all hidden context markers registered by linked extensions.
|
||||
pub fn registered_hidden_context_markers() -> impl Iterator<Item = HiddenContextMarker> {
|
||||
inventory::iter::<HiddenContextMarkerRegistration>
|
||||
.into_iter()
|
||||
.map(|registration| registration.marker)
|
||||
}
|
||||
|
||||
/// Extension-owned hidden context body with the marker pair used to wrap it.
|
||||
|
||||
@@ -27,6 +27,8 @@ pub use codex_tools::parse_tool_input_schema;
|
||||
pub use codex_tools::parse_tool_input_schema_without_compaction;
|
||||
pub use context::HiddenContext;
|
||||
pub use context::HiddenContextMarker;
|
||||
pub use context::HiddenContextMarkerRegistration;
|
||||
pub use context::registered_hidden_context_markers;
|
||||
pub use contributors::ApprovalReviewContributor;
|
||||
pub use contributors::ConfigContributor;
|
||||
pub use contributors::ContextContributor;
|
||||
|
||||
Reference in New Issue
Block a user