Skip to main content

oxios_kernel/program/
types.rs

1//! Program types — metadata, tool definitions, and installation sources.
2
3use std::collections::HashMap;
4
5use serde::{Deserialize, Serialize};
6
7/// Program metadata — the OS-level "executable header"
8/// Like an ELF header or PE header, but for AI programs
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct ProgramMeta {
11    /// Program name (unique identifier)
12    pub name: String,
13    /// Semantic version
14    pub version: String,
15    /// Human-readable description
16    pub description: String,
17    /// Author name
18    pub author: String,
19    /// Tools this program provides (maps tool name → description)
20    pub tools: Vec<ToolDef>,
21    /// Other programs this program depends on
22    pub dependencies: Vec<String>,
23    /// Host tools this program requires to function
24    pub host_requirements: ProgramHostRequirements,
25    /// MCP servers this program connects to (parsed from [mcp] table)
26    #[serde(default)]
27    pub mcp_servers: Vec<McpServerConfig>,
28}
29
30/// Host tool requirements for a program
31#[derive(Debug, Clone, Default, Serialize, Deserialize)]
32pub struct ProgramHostRequirements {
33    /// Required on host (checked at startup)
34    pub required: Vec<String>,
35    /// Optional on host (checked when needed)
36    pub optional: Vec<String>,
37}
38
39/// MCP server configuration parsed from `[mcp]` in program.toml.
40#[derive(Debug, Clone, Serialize, Deserialize)]
41pub struct McpServerConfig {
42    /// Server name identifier.
43    pub name: String,
44    /// Command to launch the MCP server.
45    pub command: String,
46    /// Command-line arguments.
47    #[serde(default)]
48    pub args: Vec<String>,
49    /// Environment variables for the server process.
50    #[serde(default)]
51    pub env: HashMap<String, String>,
52    /// Whether the server is enabled by default.
53    #[serde(default = "default_enabled")]
54    pub enabled: bool,
55}
56
57fn default_enabled() -> bool {
58    true
59}
60
61/// Definition of a tool exposed by a program.
62#[derive(Debug, Clone, Serialize, Deserialize)]
63pub struct ToolDef {
64    /// Tool name (unique within the program)
65    pub name: String,
66    /// Brief description of what the tool does
67    pub description: String,
68    /// Expected arguments
69    pub arguments: Vec<ArgumentDef>,
70    /// Command to execute (first word = binary, rest = default args)
71    #[serde(default)]
72    pub command: String,
73}
74
75/// Argument definition for a tool
76#[derive(Debug, Clone, Serialize, Deserialize)]
77pub struct ArgumentDef {
78    /// Argument name
79    pub name: String,
80    /// Description of the argument
81    pub description: String,
82    /// Whether this argument is required
83    pub required: bool,
84    /// Default value if not provided
85    pub default: Option<String>,
86}
87
88/// Program installed in the OS
89#[derive(Debug, Clone)]
90pub struct Program {
91    /// Program metadata
92    pub meta: ProgramMeta,
93    /// Path to the program directory
94    pub path: std::path::PathBuf,
95    /// Content of the SKILL.md instruction file
96    pub skill_content: String,
97    /// Whether the program is enabled
98    pub enabled: bool,
99}
100
101/// Installation source for a program.
102pub enum InstallSource {
103    /// Install from a local directory path.
104    Local(std::path::PathBuf),
105    /// Install from a git repository.
106    Git {
107        /// Git repository URL.
108        url: String,
109        /// Optional branch to checkout.
110        branch: Option<String>,
111    },
112    /// Install from a tarball URL.
113    Tarball {
114        /// Tarball URL (http/https).
115        url: String,
116    },
117}
118
119/// Result of checking host requirements
120#[derive(Debug, Clone, Serialize)]
121pub struct HostRequirementsCheck {
122    /// Name of the program checked
123    pub program_name: String,
124    /// Required tools that are missing on the host
125    pub missing_required: Vec<String>,
126    /// Availability status of optional tools
127    pub optional_available: HashMap<String, bool>,
128}
129
130/// Runtime state of an installed program.
131///
132/// Persisted to `state.json` inside the program directory, separately
133/// from `program.toml` (which is author-controlled and read-only).
134#[derive(Debug, Clone, Serialize, Deserialize)]
135pub struct ProgramState {
136    /// Whether the program is enabled.
137    pub enabled: bool,
138    /// When the program was first installed.
139    pub installed_at: String,
140    /// When the state was last modified.
141    pub last_modified: String,
142}
143
144impl Default for ProgramState {
145    fn default() -> Self {
146        let now = chrono::Utc::now().to_rfc3339();
147        Self {
148            enabled: true,
149            installed_at: now.clone(),
150            last_modified: now,
151        }
152    }
153}
154
155impl ProgramState {
156    /// Create a new state with `enabled = true`.
157    pub fn new() -> Self {
158        Self::default()
159    }
160
161    /// Set enabled and update `last_modified`.
162    pub fn with_enabled(mut self, enabled: bool) -> Self {
163        self.enabled = enabled;
164        self.last_modified = chrono::Utc::now().to_rfc3339();
165        self
166    }
167}