Skip to main content

mofa_plugins/skill/
metadata.rs

1//! Skill 元数据结构
2
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5use std::path::PathBuf;
6
7/// Skill YAML Frontmatter(第1层:启动时加载)
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct SkillMetadata {
10    /// Skill 名称(唯一标识符)
11    pub name: String,
12    /// Skill 描述(用于 LLM 判断何时使用)
13    pub description: String,
14    /// Skill 分类
15    #[serde(default)]
16    pub category: Option<String>,
17    /// 标签
18    #[serde(default)]
19    pub tags: Vec<String>,
20    /// 版本
21    #[serde(default)]
22    pub version: Option<String>,
23    /// 作者
24    #[serde(default)]
25    pub author: Option<String>,
26    /// 是否始终加载(always skills)
27    #[serde(default)]
28    pub always: bool,
29    /// 依赖要求
30    #[serde(default)]
31    pub requires: Option<SkillRequirements>,
32    /// 安装指令
33    #[serde(default)]
34    pub install: Option<String>,
35}
36
37/// Skill 版本信息
38#[derive(Debug, Clone, Serialize, Deserialize)]
39pub struct SkillVersion {
40    /// 内容哈希(SHA256)
41    pub content_hash: String,
42    /// 更新时间
43    pub updated_at: DateTime<Utc>,
44}
45
46/// Skill 状态
47#[derive(Debug, Clone, PartialEq)]
48pub enum SkillState {
49    Active,
50    Updating,
51    RolledBack,
52    Disabled,
53}
54
55/// 代码文件定义
56#[derive(Debug, Clone, Serialize, Deserialize)]
57pub struct CodeFile {
58    /// 文件路径(相对于 skill 目录)
59    pub path: PathBuf,
60    /// 语言类型
61    pub language: String,
62    /// 执行命令模板
63    pub command: Option<String>,
64}
65
66/// Skill 依赖要求
67#[derive(Debug, Clone, Serialize, Deserialize, Default)]
68pub struct SkillRequirements {
69    /// 需要的 CLI 工具
70    #[serde(default)]
71    pub cli_tools: Vec<String>,
72    /// 需要的环境变量
73    #[serde(default)]
74    pub env_vars: Vec<String>,
75}
76
77/// 依赖项类型
78#[derive(Debug, Clone, PartialEq)]
79pub enum Requirement {
80    /// CLI 工具
81    CliTool(String),
82    /// 环境变量
83    EnvVar(String),
84}
85
86/// 依赖检查结果
87#[derive(Debug, Clone, Default)]
88pub struct RequirementCheck {
89    /// 是否满足所有要求
90    pub satisfied: bool,
91    /// 缺失的依赖
92    pub missing: Vec<Requirement>,
93}