Skip to main content

codex_config/
skills_config.rs

1//! Skill-related configuration types shared across crates.
2
3use codex_utils_absolute_path::AbsolutePathBuf;
4use schemars::JsonSchema;
5use serde::Deserialize;
6use serde::Serialize;
7
8const fn default_enabled() -> bool {
9    true
10}
11
12#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema)]
13#[schemars(deny_unknown_fields)]
14pub struct SkillConfig {
15    /// Path-based selector.
16    #[serde(default, skip_serializing_if = "Option::is_none")]
17    pub path: Option<AbsolutePathBuf>,
18    /// Name-based selector.
19    #[serde(default, skip_serializing_if = "Option::is_none")]
20    pub name: Option<String>,
21    pub enabled: bool,
22}
23
24#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, JsonSchema)]
25#[schemars(deny_unknown_fields)]
26pub struct SkillsConfig {
27    #[serde(default, skip_serializing_if = "Option::is_none")]
28    pub bundled: Option<BundledSkillsConfig>,
29
30    /// Whether turns receive the automatic skills instructions block.
31    #[serde(default, skip_serializing_if = "Option::is_none")]
32    pub include_instructions: Option<bool>,
33
34    #[serde(default, skip_serializing_if = "Vec::is_empty")]
35    pub config: Vec<SkillConfig>,
36}
37
38#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema)]
39#[schemars(deny_unknown_fields)]
40pub struct BundledSkillsConfig {
41    #[serde(default = "default_enabled")]
42    pub enabled: bool,
43}
44
45impl Default for BundledSkillsConfig {
46    fn default() -> Self {
47        Self { enabled: true }
48    }
49}
50
51impl TryFrom<toml::Value> for SkillsConfig {
52    type Error = toml::de::Error;
53
54    fn try_from(value: toml::Value) -> Result<Self, Self::Error> {
55        SkillsConfig::deserialize(value)
56    }
57}