mirror of
https://github.com/openai/codex.git
synced 2026-10-22 17:58:46 +00:00
## Summary - add a false-by-default `include_skills_usage_instructions` model metadata field - enable the field for the bundled `gpt-5.5` model metadata - consume the metadata in both core and extension skill rendering - remove hardcoded legacy-model matching and its marker plumbing
73 lines
3.0 KiB
Rust
73 lines
3.0 KiB
Rust
use codex_extension_api::ContextualUserFragment;
|
|
use codex_extension_api::PreviousWorldStateSection;
|
|
use codex_extension_api::RenderedWorldStateFragment;
|
|
use codex_extension_api::WorldStateSectionContribution;
|
|
use codex_protocol::protocol::SKILLS_INSTRUCTIONS_CLOSE_TAG;
|
|
use codex_protocol::protocol::SKILLS_INSTRUCTIONS_OPEN_TAG;
|
|
use serde_json::json;
|
|
|
|
use crate::catalog::SkillCatalog;
|
|
use crate::render::available_skills_fragment;
|
|
|
|
pub(crate) const SKILLS_WORLD_STATE_ID: &str = "skills";
|
|
const NO_EXECUTOR_SKILLS_BODY: &str =
|
|
"\n## Skills update\nNo selected-environment skills are currently available.\n";
|
|
const HIDDEN_EXECUTOR_SKILLS_BODY: &str = "\n## Skills update\nSelected-environment skills are not listed automatically. Explicit skill mentions can still be resolved when available.\n";
|
|
|
|
pub(crate) fn executor_skills_world_state_section(
|
|
catalog: &SkillCatalog,
|
|
include_instructions: bool,
|
|
include_skills_usage_instructions: bool,
|
|
) -> WorldStateSectionContribution {
|
|
let body = if include_instructions {
|
|
available_skills_fragment(catalog, include_skills_usage_instructions)
|
|
.map(|fragment| fragment.body())
|
|
} else {
|
|
None
|
|
};
|
|
let snapshot = json!({
|
|
"body": body,
|
|
"includeInstructions": include_instructions,
|
|
});
|
|
let retained_body = body.clone();
|
|
|
|
let contribution =
|
|
WorldStateSectionContribution::new(SKILLS_WORLD_STATE_ID, snapshot, move |previous| {
|
|
let previous_is_absent = matches!(&previous, PreviousWorldStateSection::Absent);
|
|
if let PreviousWorldStateSection::Known(previous) = &previous {
|
|
let previous_body = previous.get("body").and_then(serde_json::Value::as_str);
|
|
let previous_include_instructions = previous
|
|
.get("includeInstructions")
|
|
.and_then(serde_json::Value::as_bool);
|
|
if previous_body == body.as_deref()
|
|
&& previous_include_instructions == Some(include_instructions)
|
|
{
|
|
return None;
|
|
}
|
|
}
|
|
|
|
let body = match body.as_deref() {
|
|
Some(body) => body,
|
|
None if previous_is_absent => return None,
|
|
None if !include_instructions => HIDDEN_EXECUTOR_SKILLS_BODY,
|
|
None => NO_EXECUTOR_SKILLS_BODY,
|
|
};
|
|
Some(RenderedWorldStateFragment::new(
|
|
"developer",
|
|
(SKILLS_INSTRUCTIONS_OPEN_TAG, SKILLS_INSTRUCTIONS_CLOSE_TAG),
|
|
body,
|
|
))
|
|
})
|
|
.with_legacy_matcher(|role, text| {
|
|
role == "developer"
|
|
&& text.trim_start().starts_with(SKILLS_INSTRUCTIONS_OPEN_TAG)
|
|
&& text.trim_end().ends_with(SKILLS_INSTRUCTIONS_CLOSE_TAG)
|
|
});
|
|
match retained_body {
|
|
Some(body) => contribution.with_retained_fragment_matcher(move |role, text| {
|
|
role == "developer" && text.contains(&body)
|
|
}),
|
|
None => contribution,
|
|
}
|
|
}
|