Skip to main content

aidaemon_memory/
skills.rs

1//! Skills a host keeps in its database: drafts promoted from successful
2//! procedures, pending the owner's review, and the deprecated dynamic skills
3//! kept for migration compatibility.
4
5use async_trait::async_trait;
6use serde::{Deserialize, Serialize};
7
8use crate::Procedure;
9
10/// A dynamically added skill (stored in database).
11/// Deprecated: kept for migration compatibility. Use filesystem skills instead.
12#[derive(Debug, Clone, Serialize, Deserialize)]
13pub struct DynamicSkill {
14    pub id: i64,
15    pub name: String,
16    pub description: String,
17    pub triggers_json: String, // JSON array of trigger strings
18    pub body: String,
19    pub source: String, // "url", "inline", "auto", "registry"
20    pub source_url: Option<String>,
21    pub enabled: bool,
22    pub version: Option<String>,
23    pub created_at: String,
24    /// JSON-serialized `Vec<ResourceEntry>` for directory-based skills
25    #[serde(default = "default_empty_json")]
26    pub resources_json: String,
27}
28
29/// A skill draft created by auto-promotion, pending user review.
30#[derive(Debug, Clone, Serialize, Deserialize)]
31pub struct SkillDraft {
32    pub id: i64,
33    pub name: String,
34    pub description: String,
35    pub triggers_json: String,
36    pub body: String,
37    pub source_procedure: String,
38    pub status: String, // "pending", "approved", "dismissed"
39    pub created_at: String,
40}
41
42fn default_empty_json() -> String {
43    "[]".to_string()
44}
45
46/// Skills storage (deprecated dynamic skills + skill drafts).
47#[async_trait]
48pub trait SkillStore: Send + Sync {
49    /// Store a dynamically added skill.
50    /// Deprecated: use filesystem skills instead.
51    #[allow(dead_code)]
52    async fn add_dynamic_skill(&self, _skill: &DynamicSkill) -> anyhow::Result<i64> {
53        Ok(0)
54    }
55
56    /// Get all dynamic skills.
57    /// Deprecated: use filesystem skills instead.
58    async fn get_dynamic_skills(&self) -> anyhow::Result<Vec<DynamicSkill>> {
59        Ok(vec![])
60    }
61
62    /// Delete a dynamic skill by ID.
63    /// Deprecated: use filesystem skills instead.
64    #[allow(dead_code)]
65    async fn delete_dynamic_skill(&self, _id: i64) -> anyhow::Result<()> {
66        Ok(())
67    }
68
69    /// Update the enabled flag of a dynamic skill.
70    /// Deprecated: file existence = active, no enable/disable needed.
71    #[allow(dead_code)]
72    async fn update_dynamic_skill_enabled(&self, _id: i64, _enabled: bool) -> anyhow::Result<()> {
73        Ok(())
74    }
75
76    /// Get procedures eligible for skill promotion (success_count >= min_success, success rate >= min_rate).
77    async fn get_promotable_procedures(
78        &self,
79        _min_success: i32,
80        _min_rate: f32,
81    ) -> anyhow::Result<Vec<Procedure>> {
82        Ok(vec![])
83    }
84
85    /// Store a skill draft from auto-promotion. Returns the draft ID.
86    async fn add_skill_draft(&self, _draft: &SkillDraft) -> anyhow::Result<i64> {
87        Ok(0)
88    }
89
90    /// Get all pending skill drafts.
91    async fn get_pending_skill_drafts(&self) -> anyhow::Result<Vec<SkillDraft>> {
92        Ok(vec![])
93    }
94
95    /// Get a skill draft by ID.
96    async fn get_skill_draft(&self, _id: i64) -> anyhow::Result<Option<SkillDraft>> {
97        Ok(None)
98    }
99
100    /// Update a skill draft's status ("approved" or "dismissed").
101    async fn update_skill_draft_status(&self, _id: i64, _status: &str) -> anyhow::Result<()> {
102        Ok(())
103    }
104
105    /// Check if any draft record already exists for a given procedure name
106    /// (pending, approved, or dismissed).
107    async fn skill_draft_exists_for_procedure(
108        &self,
109        _procedure_name: &str,
110    ) -> anyhow::Result<bool> {
111        Ok(false)
112    }
113}