mirror of
https://github.com/openai/codex.git
synced 2026-11-13 06:45:07 +00:00
Remove the codex-core-skills crate (#37505)
## What changed - Move `SkillLoadOutcome` and its implicit-path indexing into `codex-skills-extension`. - Import shared skill types directly from `codex-skills` and keep the skill prompt size limit with the extension renderer that uses it. - Remove `codex-core-skills` from the Cargo workspace and dependent crates. GitOrigin-RevId: 4e9e84909fa2f692bcc94af990bb4671affd776f
This commit is contained in:
1 parent
abc5d0b552
commit
45f8cafa4e
20 files changed
+34
-122
No files matched your search
@@ -1,4 +1,4 @@
|
||||
use codex_core_skills::SkillLoadOutcome;
|
||||
use crate::SkillLoadOutcome;
|
||||
use codex_protocol::protocol::SkillScope;
|
||||
use codex_skills::SkillDependencies;
|
||||
use codex_skills::SkillInterface;
|
||||
|
||||
@@ -0,0 +1,191 @@
|
||||
use std::collections::HashMap;
|
||||
use std::collections::HashSet;
|
||||
use std::fmt;
|
||||
use std::io;
|
||||
use std::sync::Arc;
|
||||
|
||||
use codex_exec_server::ExecutorFileSystem;
|
||||
use codex_exec_server::LOCAL_FS;
|
||||
use codex_skills::SkillError;
|
||||
use codex_skills::SkillMetadata;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use codex_utils_path_uri::PathUri;
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct SkillLoadOutcome {
|
||||
pub skills: Vec<SkillMetadata>,
|
||||
pub errors: Vec<SkillError>,
|
||||
pub disabled_paths: HashSet<AbsolutePathBuf>,
|
||||
pub(crate) skill_roots: Vec<AbsolutePathBuf>,
|
||||
pub(crate) skill_root_by_path: Arc<HashMap<AbsolutePathBuf, AbsolutePathBuf>>,
|
||||
pub(crate) skill_discovery_path_by_path: Arc<HashMap<AbsolutePathBuf, AbsolutePathBuf>>,
|
||||
pub(crate) agent_plugin_skill_paths: HashSet<AbsolutePathBuf>,
|
||||
pub(crate) file_systems_by_skill_path: SkillFileSystemsByPath,
|
||||
pub(crate) implicit_skills_by_scripts_dir: Arc<HashMap<AbsolutePathBuf, SkillMetadata>>,
|
||||
pub(crate) implicit_skills_by_doc_path: Arc<HashMap<AbsolutePathBuf, SkillMetadata>>,
|
||||
}
|
||||
|
||||
impl SkillLoadOutcome {
|
||||
/// Builds an already-composed outcome while retaining the filesystem that supplied each skill.
|
||||
pub fn from_parts(
|
||||
skills: Vec<SkillMetadata>,
|
||||
errors: Vec<SkillError>,
|
||||
skill_roots: Vec<AbsolutePathBuf>,
|
||||
skill_root_by_path: HashMap<AbsolutePathBuf, AbsolutePathBuf>,
|
||||
skill_discovery_path_by_path: HashMap<AbsolutePathBuf, AbsolutePathBuf>,
|
||||
agent_plugin_skill_paths: HashSet<AbsolutePathBuf>,
|
||||
file_systems_by_skill_path: HashMap<AbsolutePathBuf, Arc<dyn ExecutorFileSystem>>,
|
||||
) -> Self {
|
||||
Self {
|
||||
skills,
|
||||
errors,
|
||||
skill_roots,
|
||||
skill_root_by_path: Arc::new(skill_root_by_path),
|
||||
skill_discovery_path_by_path: Arc::new(skill_discovery_path_by_path),
|
||||
agent_plugin_skill_paths,
|
||||
file_systems_by_skill_path: SkillFileSystemsByPath::new(file_systems_by_skill_path),
|
||||
..Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_skill_enabled(&self, skill: &SkillMetadata) -> bool {
|
||||
!self.disabled_paths.contains(&skill.path_to_skills_md)
|
||||
}
|
||||
|
||||
pub fn is_skill_allowed_for_implicit_invocation(&self, skill: &SkillMetadata) -> bool {
|
||||
self.is_skill_enabled(skill) && skill.allows_implicit_invocation()
|
||||
}
|
||||
|
||||
pub fn allowed_skills_for_implicit_invocation(&self) -> Vec<SkillMetadata> {
|
||||
self.skills
|
||||
.iter()
|
||||
.filter(|skill| self.is_skill_allowed_for_implicit_invocation(skill))
|
||||
.cloned()
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn skills_with_enabled(&self) -> impl Iterator<Item = (&SkillMetadata, bool)> {
|
||||
self.skills
|
||||
.iter()
|
||||
.map(|skill| (skill, self.is_skill_enabled(skill)))
|
||||
}
|
||||
|
||||
pub fn with_disabled_paths(mut self, disabled_paths: HashSet<AbsolutePathBuf>) -> Self {
|
||||
self.disabled_paths = disabled_paths;
|
||||
let mut by_scripts_dir = HashMap::new();
|
||||
let mut by_doc_path = HashMap::new();
|
||||
for skill in self
|
||||
.skills
|
||||
.iter()
|
||||
.filter(|skill| self.is_skill_enabled(skill))
|
||||
{
|
||||
let skill_doc_path = canonicalize_if_exists(&skill.path_to_skills_md);
|
||||
by_doc_path.insert(skill_doc_path, skill.clone());
|
||||
|
||||
if let Some(skill_dir) = skill.path_to_skills_md.parent() {
|
||||
let scripts_dir = canonicalize_if_exists(&skill_dir.join("scripts"));
|
||||
by_scripts_dir.insert(scripts_dir, skill.clone());
|
||||
}
|
||||
}
|
||||
self.implicit_skills_by_scripts_dir = Arc::new(by_scripts_dir);
|
||||
self.implicit_skills_by_doc_path = Arc::new(by_doc_path);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn is_agent_plugin_skill(&self, skill: &SkillMetadata) -> bool {
|
||||
self.agent_plugin_skill_paths
|
||||
.contains(&skill.path_to_skills_md)
|
||||
}
|
||||
|
||||
/// Returns the discovery root that supplied a loaded skill path.
|
||||
pub fn skill_root_for_path(&self, path: &AbsolutePathBuf) -> Option<&AbsolutePathBuf> {
|
||||
self.skill_root_by_path.get(path)
|
||||
}
|
||||
|
||||
/// Returns the logical path used to discover a canonical skill path.
|
||||
pub fn skill_discovery_path_for_path(
|
||||
&self,
|
||||
path: &AbsolutePathBuf,
|
||||
) -> Option<&AbsolutePathBuf> {
|
||||
self.skill_discovery_path_by_path.get(path)
|
||||
}
|
||||
|
||||
/// Returns loaded skill roots in discovery order.
|
||||
pub fn skill_roots_in_discovery_order(&self) -> impl Iterator<Item = &AbsolutePathBuf> {
|
||||
self.skill_roots.iter()
|
||||
}
|
||||
|
||||
pub(crate) fn file_system_for_skill(
|
||||
&self,
|
||||
skill: &SkillMetadata,
|
||||
) -> Option<Arc<dyn ExecutorFileSystem>> {
|
||||
self.file_systems_by_skill_path
|
||||
.get(&skill.path_to_skills_md)
|
||||
}
|
||||
|
||||
/// Reads one loaded skill through the filesystem that discovered it.
|
||||
pub async fn read_skill_text(&self, skill: &SkillMetadata) -> io::Result<String> {
|
||||
let fs = self
|
||||
.file_system_for_skill(skill)
|
||||
.unwrap_or_else(|| Arc::clone(&LOCAL_FS));
|
||||
let path = PathUri::from_abs_path(&skill.path_to_skills_md);
|
||||
fs.read_file_text(&path, /*sandbox*/ None).await
|
||||
}
|
||||
}
|
||||
|
||||
impl codex_skills::ImplicitSkillLookup for SkillLoadOutcome {
|
||||
fn implicit_skill_for_scripts_dir(&self, path: &AbsolutePathBuf) -> Option<&SkillMetadata> {
|
||||
self.implicit_skills_by_scripts_dir.get(path)
|
||||
}
|
||||
|
||||
fn implicit_skill_for_doc_path(&self, path: &AbsolutePathBuf) -> Option<&SkillMetadata> {
|
||||
self.implicit_skills_by_doc_path.get(path)
|
||||
}
|
||||
}
|
||||
|
||||
impl codex_skills::ExplicitSkillLookup for SkillLoadOutcome {
|
||||
fn skills(&self) -> &[SkillMetadata] {
|
||||
&self.skills
|
||||
}
|
||||
|
||||
fn disabled_paths(&self) -> &HashSet<AbsolutePathBuf> {
|
||||
&self.disabled_paths
|
||||
}
|
||||
|
||||
fn skill_discovery_path_for_path(&self, path: &AbsolutePathBuf) -> Option<&AbsolutePathBuf> {
|
||||
SkillLoadOutcome::skill_discovery_path_for_path(self, path)
|
||||
}
|
||||
|
||||
fn is_skill_enabled(&self, skill: &SkillMetadata) -> bool {
|
||||
SkillLoadOutcome::is_skill_enabled(self, skill)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
pub(crate) struct SkillFileSystemsByPath {
|
||||
values: Arc<HashMap<AbsolutePathBuf, Arc<dyn ExecutorFileSystem>>>,
|
||||
}
|
||||
|
||||
impl SkillFileSystemsByPath {
|
||||
pub(crate) fn new(values: HashMap<AbsolutePathBuf, Arc<dyn ExecutorFileSystem>>) -> Self {
|
||||
Self {
|
||||
values: Arc::new(values),
|
||||
}
|
||||
}
|
||||
|
||||
fn get(&self, path: &AbsolutePathBuf) -> Option<Arc<dyn ExecutorFileSystem>> {
|
||||
self.values.get(path).map(Arc::clone)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for SkillFileSystemsByPath {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("SkillFileSystemsByPath")
|
||||
.field("len", &self.values.len())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
fn canonicalize_if_exists(path: &AbsolutePathBuf) -> AbsolutePathBuf {
|
||||
path.canonicalize().unwrap_or_else(|_| path.clone())
|
||||
}
|
||||
@@ -7,7 +7,6 @@ use codex_config::ConfigLayerEntry;
|
||||
use codex_config::ConfigLayerSource;
|
||||
use codex_config::ConfigLayerStack;
|
||||
use codex_config::ConfigRequirementsToml;
|
||||
use codex_core_skills::SkillMetadata;
|
||||
use codex_exec_server::CopyOptions;
|
||||
use codex_exec_server::CreateDirectoryOptions;
|
||||
use codex_exec_server::ExecutorFileSystem;
|
||||
@@ -21,6 +20,7 @@ use codex_exec_server::RemoveOptions;
|
||||
use codex_exec_server::WalkOptions;
|
||||
use codex_exec_server::WalkOutcome;
|
||||
use codex_protocol::protocol::SkillScope;
|
||||
use codex_skills::SkillMetadata;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use codex_utils_path_uri::PathUri;
|
||||
use codex_utils_plugins::PluginIdentity;
|
||||
|
||||
@@ -22,7 +22,6 @@ use tracing::instrument;
|
||||
use tracing::warn;
|
||||
|
||||
use codex_config::SkillsConfig;
|
||||
use codex_core_skills::SkillLoadOutcome;
|
||||
use codex_skills::LoadedSkills;
|
||||
use codex_skills::SkillLoadFuture;
|
||||
use codex_skills::SkillRootLoadRequest;
|
||||
@@ -31,6 +30,7 @@ use codex_skills::SkillRootSnapshots;
|
||||
use codex_skills::install_system_skills;
|
||||
|
||||
use crate::HostSkillsSnapshot;
|
||||
use crate::SkillLoadOutcome;
|
||||
use crate::host_roots::resolve_skill_roots;
|
||||
use crate::loader::HostSkillRoot;
|
||||
use crate::loader::MAX_CONCURRENT_ROOT_SCANS;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::io;
|
||||
use std::sync::Arc;
|
||||
|
||||
use codex_core_skills::SkillLoadOutcome;
|
||||
use crate::SkillLoadOutcome;
|
||||
use codex_skills::SkillMetadata;
|
||||
|
||||
/// Immutable snapshot of host-owned skills and their source filesystems.
|
||||
|
||||
@@ -6,6 +6,7 @@ mod dynamic_skill_selector;
|
||||
mod extension;
|
||||
mod fragments;
|
||||
mod host_aliases;
|
||||
mod host_outcome;
|
||||
mod host_prompt;
|
||||
mod host_roots;
|
||||
mod host_service;
|
||||
@@ -27,6 +28,7 @@ pub use config::SkillsExtensionConfig;
|
||||
pub use extension::install;
|
||||
pub use extension::install_with_providers;
|
||||
pub use extension::install_with_providers_and_metrics;
|
||||
pub use host_outcome::SkillLoadOutcome;
|
||||
pub use host_prompt::HostSkillPrompts;
|
||||
pub use host_prompt::InjectedHostSkillPrompts;
|
||||
pub use host_service::HostSkillsLoadInput;
|
||||
|
||||
@@ -2,7 +2,6 @@ use std::collections::HashMap;
|
||||
use std::collections::HashSet;
|
||||
use std::sync::Arc;
|
||||
|
||||
use codex_core_skills::SkillLoadOutcome;
|
||||
use codex_exec_server::ExecutorFileSystem;
|
||||
use codex_protocol::protocol::Product;
|
||||
use codex_protocol::protocol::SkillScope;
|
||||
@@ -20,6 +19,7 @@ use super::HostSkillRoot;
|
||||
use super::MAX_CONCURRENT_ROOT_SCANS;
|
||||
use super::host::HostSkillRootSnapshot;
|
||||
use super::load_host_skill_root;
|
||||
use crate::SkillLoadOutcome;
|
||||
|
||||
pub(crate) async fn load_and_merge_host_skill_roots(
|
||||
roots: Vec<HostSkillRoot>,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use codex_core_skills::SkillLoadOutcome;
|
||||
use crate::SkillLoadOutcome;
|
||||
use codex_skills::SkillMetadata;
|
||||
|
||||
use crate::catalog::SkillAuthority;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use std::borrow::Cow;
|
||||
|
||||
use codex_core_skills::MAX_SKILL_PROMPT_BYTES;
|
||||
use codex_protocol::protocol::SkillScope;
|
||||
use codex_utils_string::approx_token_count;
|
||||
use codex_utils_string::take_bytes_at_char_boundary;
|
||||
@@ -15,6 +14,7 @@ use crate::fragments::AvailableSkillsInstructions;
|
||||
use crate::host_aliases::shared_host_alias_roots;
|
||||
|
||||
const DEFAULT_SKILL_METADATA_CHAR_BUDGET: usize = 8_000;
|
||||
const MAX_SKILL_PROMPT_BYTES: usize = 8_000;
|
||||
const SKILL_METADATA_CONTEXT_WINDOW_PERCENT: usize = 2;
|
||||
const MAX_CATALOG_SKILL_DESCRIPTION_CHARS: usize = 1_024;
|
||||
const TRUNCATED_SKILL_DESCRIPTION_SUFFIX: &str = "...";
|
||||
|
||||
Reference in new issue
Block a user