1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//! `SkillCatalog` — the skills a session can list, invoke and be reminded of.
//!
//! The turn loop asks this, not the skills module, which skills exist, what
//! one expands to, and how often each has been used. A session assembled
//! without skills answers from [`NoSkills`].
use std::path::PathBuf;
use futures::future::BoxFuture;
use crate::interface::tool::ToolContext;
use crate::skill::SkillEntry;
/// One invocation's worth of a skill: the text the conversation receives,
/// and the `(tool, pattern)` grants its `allowed-tools` makes for the rest of
/// the turn — already narrowed to what its source may grant.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct SkillExpansion {
pub text: String,
pub grants: Vec<(String, Option<String>)>,
}
pub trait SkillCatalog: Send + Sync {
/// Sorted by name, so the listing a prompt carries is stable.
fn list(&self) -> Vec<SkillEntry>;
fn get(&self, name: &str) -> Option<SkillEntry>;
/// The body a skill expands to when invoked.
fn body(&self, name: &str) -> Option<String>;
/// Expand `name` for an invocation with `args`, running what its body
/// asks to run through `ctx.inline_commands`. `None` when the catalog does
/// not hold it; `Err` is a message for the model, such as a bundled file
/// that escapes the skill's folder.
fn expand<'a>(
&'a self,
name: &'a str,
args: &'a str,
ctx: &'a ToolContext,
) -> BoxFuture<'a, Option<Result<SkillExpansion, String>>> {
Box::pin(async move {
let entry = self.get(name)?;
let body = self.body(name)?;
let text = crate::skill::expand_skill_vars_named(
&body,
args,
entry.arguments.as_deref().unwrap_or(&[]),
Some(&crate::skill::InvocationVars {
skill_md: &entry.path,
session_id: Some(&ctx.session_id),
}),
);
Some(Ok(SkillExpansion {
text,
grants: Vec::new(),
}))
})
}
/// Reloads skills whose files changed since the last call; how many did.
fn reload_changed(&self) -> usize;
/// Skills found under `paths` that the catalog did not hold yet.
fn discover_for_paths(&self, paths: &[PathBuf]) -> Vec<SkillEntry>;
/// Conditional skills whose `paths` patterns match one of `files`, newly
/// made available.
fn activate_for_paths(&self, files: &[PathBuf]) -> Vec<SkillEntry>;
fn invocation_count(&self, name: &str) -> u32;
/// A sequence number that orders invocations; 0 for one never invoked.
fn last_invoked_seq(&self, name: &str) -> u64;
}
pub struct NoSkills;
impl SkillCatalog for NoSkills {
fn list(&self) -> Vec<SkillEntry> {
Vec::new()
}
fn get(&self, _: &str) -> Option<SkillEntry> {
None
}
fn body(&self, _: &str) -> Option<String> {
None
}
fn reload_changed(&self) -> usize {
0
}
fn discover_for_paths(&self, _: &[PathBuf]) -> Vec<SkillEntry> {
Vec::new()
}
fn activate_for_paths(&self, _: &[PathBuf]) -> Vec<SkillEntry> {
Vec::new()
}
fn invocation_count(&self, _: &str) -> u32 {
0
}
fn last_invoked_seq(&self, _: &str) -> u64 {
0
}
}