base/interface/
skill_catalog.rs1use std::path::PathBuf;
8
9use futures::future::BoxFuture;
10
11use crate::interface::tool::ToolContext;
12use crate::skill::SkillEntry;
13
14#[derive(Debug, Clone, Default, PartialEq, Eq)]
18pub struct SkillExpansion {
19 pub text: String,
20 pub grants: Vec<(String, Option<String>)>,
21}
22
23pub trait SkillCatalog: Send + Sync {
24 fn list(&self) -> Vec<SkillEntry>;
26 fn get(&self, name: &str) -> Option<SkillEntry>;
27 fn body(&self, name: &str) -> Option<String>;
29 fn expand<'a>(
34 &'a self,
35 name: &'a str,
36 args: &'a str,
37 ctx: &'a ToolContext,
38 ) -> BoxFuture<'a, Option<Result<SkillExpansion, String>>> {
39 Box::pin(async move {
40 let entry = self.get(name)?;
41 let body = self.body(name)?;
42 let text = crate::skill::expand_skill_vars_named(
43 &body,
44 args,
45 entry.arguments.as_deref().unwrap_or(&[]),
46 Some(&crate::skill::InvocationVars {
47 skill_md: &entry.path,
48 session_id: Some(&ctx.session_id),
49 }),
50 );
51 Some(Ok(SkillExpansion {
52 text,
53 grants: Vec::new(),
54 }))
55 })
56 }
57 fn reload_changed(&self) -> usize;
59 fn discover_for_paths(&self, paths: &[PathBuf]) -> Vec<SkillEntry>;
61 fn activate_for_paths(&self, files: &[PathBuf]) -> Vec<SkillEntry>;
64 fn invocation_count(&self, name: &str) -> u32;
65 fn last_invoked_seq(&self, name: &str) -> u64;
67}
68
69pub struct NoSkills;
70
71impl SkillCatalog for NoSkills {
72 fn list(&self) -> Vec<SkillEntry> {
73 Vec::new()
74 }
75 fn get(&self, _: &str) -> Option<SkillEntry> {
76 None
77 }
78 fn body(&self, _: &str) -> Option<String> {
79 None
80 }
81 fn reload_changed(&self) -> usize {
82 0
83 }
84 fn discover_for_paths(&self, _: &[PathBuf]) -> Vec<SkillEntry> {
85 Vec::new()
86 }
87 fn activate_for_paths(&self, _: &[PathBuf]) -> Vec<SkillEntry> {
88 Vec::new()
89 }
90 fn invocation_count(&self, _: &str) -> u32 {
91 0
92 }
93 fn last_invoked_seq(&self, _: &str) -> u64 {
94 0
95 }
96}