Files
codex/codex-rs/ext/skills/src/required.rs
T
Anthony Tafoya 9b865ab31e Prepare skill catalogs before building step tools (#55357)
## Why

Skill tools depended on World State rendering to initialize their catalogs and could return `skill catalog is not ready for this step` before rendering completed.

## What changed

- Add an asynchronous `ToolContributor::prepare_for_step` hook and await all contributors before constructing tools.
- Prepare immutable skill catalogs, aliases, plugin policy, and configuration for each step. Tools, invocation detection, and World State rendering consume the prepared state without relying on rendering to perform discovery.
- Apply configuration reloads to subsequent steps while preserving live authorization checks for skill reads.

## Testing

Add coverage for preparation completing before tool construction and World State rendering, skill tools working before rendering, catalogs remaining stable across steps, and configuration reloads during discovery.

GitOrigin-RevId: 1fb95c58c412488353f3bd4403824d6d1476d3d0
2026-10-19 19:33:11 +00:00

50 lines
1.8 KiB
Rust

//! Checks source-scoped requirements against skills discovered before inference.
use codex_extension_api::ExtensionData;
use crate::step_state::SkillsStepState;
/// Skill names that must be supplied by one selected environment before inference.
pub struct EnvironmentSkillRequirements<'a> {
pub environment_id: &'a str,
pub skill_names: &'a [String],
}
/// Validates requirements against the policy-checked catalog prepared for this step.
pub fn validate_required_skills<'a>(
step_store: &ExtensionData,
environments: impl IntoIterator<Item = EnvironmentSkillRequirements<'a>>,
) -> Result<(), String> {
let mut environments = environments.into_iter().peekable();
if environments.peek().is_none() {
return Ok(());
}
let step_state = step_store.get::<SkillsStepState>().ok_or_else(|| {
"Required skills cannot be validated because the skills extension is unavailable"
.to_string()
})?;
for EnvironmentSkillRequirements {
environment_id,
skill_names,
} in environments
{
for name in skill_names {
let available = step_state.catalog.merged.entries.iter().any(|entry| {
entry.enabled
&& entry.name == name.as_str()
&& (entry.main_prompt.environment_id() == Some(environment_id)
|| entry.sources.iter().any(|source| {
source.enabled
&& source.main_prompt.environment_id() == Some(environment_id)
}))
});
if !available {
return Err(format!(
"Required skill {name:?} from environment {environment_id:?} is unavailable"
));
}
}
}
Ok(())
}