Skip to main content

oxios_kernel/kernel_handle/
extension_api.rs

1//! Extension API — programs, skills, host tools.
2
3use crate::host_tools::HostToolStatus;
4use crate::host_tools::HostToolValidator;
5use crate::program::{HostRequirementsCheck, InstallSource, Program, ProgramManager, ProgramMeta};
6use crate::skill::{Skill, SkillMeta, SkillStore};
7use std::sync::Arc;
8
9/// Extension system calls.
10pub struct ExtensionApi {
11    pub(crate) program_manager: Arc<ProgramManager>,
12    pub(crate) skill_store: Arc<SkillStore>,
13    pub(crate) host_tool_validator: Arc<HostToolValidator>,
14}
15
16impl ExtensionApi {
17    /// Create a new ExtensionApi.
18    pub fn new(
19        program_manager: Arc<ProgramManager>,
20        skill_store: Arc<SkillStore>,
21        host_tool_validator: Arc<HostToolValidator>,
22    ) -> Self {
23        Self {
24            program_manager,
25            skill_store,
26            host_tool_validator,
27        }
28    }
29    /// List installed programs.
30    pub async fn list_programs(&self) -> Vec<ProgramMeta> {
31        self.program_manager
32            .list_programs()
33            .await
34            .into_iter()
35            .map(|p| p.meta)
36            .collect()
37    }
38
39    /// Get program details.
40    pub async fn get_program(&self, name: &str) -> Option<Program> {
41        self.program_manager.get_program(name).await
42    }
43
44    /// Install a program from source.
45    pub async fn install_program(&self, source: InstallSource) -> anyhow::Result<Program> {
46        self.program_manager.install_from(source).await
47    }
48
49    /// Uninstall a program.
50    pub async fn uninstall_program(&self, name: &str) -> anyhow::Result<()> {
51        self.program_manager.uninstall(name).await
52    }
53
54    /// Enable a program.
55    pub async fn enable_program(&self, name: &str) -> anyhow::Result<()> {
56        self.program_manager.set_enabled(name, true).await
57    }
58
59    /// Disable a program.
60    pub async fn disable_program(&self, name: &str) -> anyhow::Result<()> {
61        self.program_manager.set_enabled(name, false).await
62    }
63
64    /// Check host requirements for a program.
65    pub async fn check_host_requirements(
66        &self,
67        name: &str,
68    ) -> anyhow::Result<HostRequirementsCheck> {
69        self.program_manager.check_host_requirements(name).await
70    }
71
72    /// List all skills.
73    pub async fn list_skills(&self) -> anyhow::Result<Vec<SkillMeta>> {
74        self.skill_store.list_skills().await
75    }
76
77    /// Load skill by name.
78    pub async fn load_skill(&self, name: &str) -> anyhow::Result<Option<Skill>> {
79        self.skill_store.load_skill(name).await
80    }
81
82    /// Create a new skill.
83    pub async fn create_skill(
84        &self,
85        name: &str,
86        description: &str,
87        content: &str,
88    ) -> anyhow::Result<()> {
89        self.skill_store
90            .create_skill(name, description, content)
91            .await
92    }
93
94    /// Delete a skill.
95    pub async fn delete_skill(&self, name: &str) -> anyhow::Result<()> {
96        self.skill_store.delete_skill(name).await
97    }
98
99    /// Program manager reference.
100    pub fn program_manager(&self) -> &Arc<ProgramManager> {
101        &self.program_manager
102    }
103
104    /// Full host tool check.
105    pub fn check_host_tools(&self) -> HostToolStatus {
106        self.host_tool_validator.full_check()
107    }
108}