mirror of
https://github.com/openai/codex.git
synced 2026-11-25 23:30:49 +00:00
## Summary
- Preserve each skill’s raw permissions block as a permission_profile on
SkillMetadata during skill loading.
- Keep compiling that same metadata into the existing runtime
Permissions object, so current enforcement
behavior stays intact.
- When zsh-fork intercepts execution of a script that belongs to a
skill, include the skill’s
permission_profile in the exec approval request.
- This lets approval UIs show the extra filesystem access the skill
declared when prompting for approval.
103 lines
3.0 KiB
Rust
103 lines
3.0 KiB
Rust
use std::collections::HashMap;
|
|
use std::collections::HashSet;
|
|
use std::path::PathBuf;
|
|
use std::sync::Arc;
|
|
|
|
use crate::config::Permissions;
|
|
use codex_protocol::models::PermissionProfile;
|
|
use codex_protocol::protocol::SkillScope;
|
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
|
pub struct SkillMetadata {
|
|
pub name: String,
|
|
pub description: String,
|
|
pub short_description: Option<String>,
|
|
pub interface: Option<SkillInterface>,
|
|
pub dependencies: Option<SkillDependencies>,
|
|
pub policy: Option<SkillPolicy>,
|
|
pub permission_profile: Option<PermissionProfile>,
|
|
// This is an experimental field.
|
|
pub permissions: Option<Permissions>,
|
|
/// Path to the SKILLS.md file that declares this skill.
|
|
pub path_to_skills_md: PathBuf,
|
|
pub scope: SkillScope,
|
|
}
|
|
|
|
impl SkillMetadata {
|
|
fn allow_implicit_invocation(&self) -> bool {
|
|
self.policy
|
|
.as_ref()
|
|
.and_then(|policy| policy.allow_implicit_invocation)
|
|
.unwrap_or(true)
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
|
pub struct SkillPolicy {
|
|
pub allow_implicit_invocation: Option<bool>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
pub struct SkillInterface {
|
|
pub display_name: Option<String>,
|
|
pub short_description: Option<String>,
|
|
pub icon_small: Option<PathBuf>,
|
|
pub icon_large: Option<PathBuf>,
|
|
pub brand_color: Option<String>,
|
|
pub default_prompt: Option<String>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
pub struct SkillDependencies {
|
|
pub tools: Vec<SkillToolDependency>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
pub struct SkillToolDependency {
|
|
pub r#type: String,
|
|
pub value: String,
|
|
pub description: Option<String>,
|
|
pub transport: Option<String>,
|
|
pub command: Option<String>,
|
|
pub url: Option<String>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
pub struct SkillError {
|
|
pub path: PathBuf,
|
|
pub message: String,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Default)]
|
|
pub struct SkillLoadOutcome {
|
|
pub skills: Vec<SkillMetadata>,
|
|
pub errors: Vec<SkillError>,
|
|
pub disabled_paths: HashSet<PathBuf>,
|
|
pub(crate) implicit_skills_by_scripts_dir: Arc<HashMap<PathBuf, SkillMetadata>>,
|
|
pub(crate) implicit_skills_by_doc_path: Arc<HashMap<PathBuf, SkillMetadata>>,
|
|
}
|
|
|
|
impl SkillLoadOutcome {
|
|
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.allow_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)))
|
|
}
|
|
}
|