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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
use anyhow::Result;
use super::style::*;
use rsclaw_cli::SkillsCommand;
use rsclaw_config as config;
use rsclaw_skill as skill;
pub async fn cmd_skills(sub: SkillsCommand) -> Result<()> {
let config = config::load_quiet()?;
let global_dir = skill::default_global_skills_dir().unwrap_or_default();
let registry = skill::load_skills(&global_dir, None, config.ext.skills.as_ref())?;
let language = config.gateway.language.clone();
match sub {
SkillsCommand::List => {
let mut skills: Vec<_> = registry.all().collect();
skills.sort_by_key(|s| s.name.as_str());
if skills.is_empty() {
println!("No skills installed.");
println!();
println!("Install skills with: rsclaw skills install <name>");
println!("Search skills with: rsclaw skills search <query>");
} else {
println!(
"{:<24} {:<8} {}",
bold("NAME"),
bold("TOOLS"),
bold("DESCRIPTION")
);
for s in skills {
let desc = s.description.as_deref().unwrap_or("-");
println!("{:<24} {:<8} {}", cyan(&s.name), s.tools.len(), desc);
}
}
}
SkillsCommand::Info { skill } => match registry.get(&skill) {
Some(s) => {
println!("{}", bold(&s.name));
println!();
println!(
" {:<14} {}",
dim("Version"),
s.version.as_deref().unwrap_or("-")
);
println!(
" {:<14} {}",
dim("Description"),
s.description.as_deref().unwrap_or("-")
);
if !s.tools.is_empty() {
println!();
println!(" {} ({})", bold("Tools"), s.tools.len());
for t in &s.tools {
println!(
" {} {}",
cyan(&t.name),
dim(&format!("-- {}", t.description))
);
}
}
}
None => {
eprintln!("Skill '{}' not found locally.", skill);
eprintln!(
"Use `rsclaw skills search {}` to find it on the registry.",
skill
);
std::process::exit(1);
}
},
SkillsCommand::Use { skill } => {
// Mirror the in-agent `skill_use` tool: resolve the skill dir
// (live registry first, then disk for a just-installed skill),
// print SKILL.md verbatim, and tell the caller where scripts /
// references live so a CLI coding agent can follow the SOP.
let dir = match registry.get(&skill) {
Some(s) => s.dir.clone(),
None => {
if !skill::valid_slug(&skill) {
eprintln!("invalid skill name: {skill:?}");
std::process::exit(1);
}
let disk = config::loader::base_dir().join("skills").join(&skill);
if disk.join("SKILL.md").is_file() {
disk
} else {
eprintln!("Skill '{}' not installed.", skill);
eprintln!(
"Use `rsclaw skills search {}` to find it, then `rsclaw skills install`.",
skill
);
std::process::exit(1);
}
}
};
let skill_md = dir.join("SKILL.md");
match std::fs::read_to_string(&skill_md) {
Ok(body) => {
println!("# Skill: {skill}");
println!("# Directory: {}", dir.display());
println!("# Follow the playbook below; scripts/references are under the directory above.");
println!();
println!("{body}");
}
Err(e) => {
eprintln!("failed to read {}: {e}", skill_md.display());
std::process::exit(1);
}
}
}
SkillsCommand::Check { eligible } => {
let mut skills: Vec<_> = registry.all().collect();
skills.sort_by_key(|s| s.name.as_str());
if skills.is_empty() {
println!("No skills installed.");
return Ok(());
}
for s in skills {
let runnable = s.tools.iter().all(|t| !t.command.is_empty());
if eligible && !runnable {
continue;
}
if runnable {
println!("{} {}", green("ok"), s.name);
} else {
println!("{} {} (missing command)", yellow("!!"), s.name);
}
}
}
SkillsCommand::Install { name } => {
let client = skill::clawhub::ClawhubClient::new().with_language(language.clone());
// Check if already installed before printing "Installing".
let dir_name = name
.rsplit_once('@')
.map(|(_, s)| s)
.unwrap_or(name.rsplit('/').next().unwrap_or(&name));
let already = skill::clawhub::ClawhubClient::check_installed(&global_dir, dir_name);
if already {
print!("Checking '{}'... ", cyan(&name));
} else {
print!("Installing '{}'... ", cyan(&name));
}
// Resolve audited-allowlist slugs to their pinned URL first. The
// desktop "recommended skills" list is built from the allowlist,
// and some entries (e.g. Anthropic's `pptx`) live ONLY there — no
// matching slug exists in the public registries, so
// install_with_fallback would report "not found on clawhub,
// skillhub, or iwencai". Mirror the plugins-install path: when the
// bare name is an allowlist slug with a download url, install from
// that audited url instead. A url/owner-repo/`@` spec the user
// typed bypasses this and resolves as before.
let install_spec: String = {
let looks_like_plain_slug =
!name.contains('/') && !name.contains('@') && !name.starts_with("http");
if looks_like_plain_slug {
if rsclaw_skill::allowlist::snapshot().counts().0 == 0 {
let _ = rsclaw_skill::allowlist::refresh().await; // lazy; fail-open
}
rsclaw_skill::allowlist::snapshot()
.lookup_skill(&name)
.filter(|e| !e.url.is_empty())
.map(|e| e.url)
.unwrap_or_else(|| name.clone())
} else {
name.clone()
}
};
let locked = match client.install_with_fallback(&install_spec, &global_dir).await {
Ok(l) => l,
Err(e) => {
// A failed install can leave an empty skill dir behind
// (the install paths create_dir_all before downloading).
// Remove it if it's empty so a retry / list stays clean.
let d = global_dir.join(dir_name);
let empty = std::fs::read_dir(&d)
.map(|mut it| it.next().is_none())
.unwrap_or(false);
if empty {
let _ = std::fs::remove_dir_all(&d);
}
println!("{}", red("failed"));
return Err(e);
}
};
if already {
println!(
"{}",
dim(&format!("already up to date (v{})", locked.version))
);
} else {
println!(
"{}",
green(&format!(
"v{} -> {}",
locked.version,
locked.install_dir.display()
))
);
}
}
SkillsCommand::Uninstall { name } => {
let skill_dir = global_dir.join(&name);
if !skill_dir.exists() {
anyhow::bail!("skill '{name}' not found in {}", global_dir.display());
}
std::fs::remove_dir_all(&skill_dir)?;
let mut lock = skill::clawhub::LockFile::read(&global_dir).unwrap_or_default();
lock.skills.remove(&name);
lock.write(&global_dir)?;
println!("Uninstalled '{}'.", cyan(&name));
}
SkillsCommand::Search { query } => {
let client = skill::clawhub::ClawhubClient::new().with_language(language.clone());
match client.search_with_fallback(&query).await {
Ok(results) => {
if results.is_empty() {
println!("No skills found matching '{}'.", query);
} else {
let has_stats = results.iter().any(|r| {
r.downloads.is_some() || r.installs.is_some() || r.stars.is_some()
});
if has_stats {
println!(
"{:<36} {:>10} {:>8} {:<12} {}",
bold("NAME"),
bold("INSTALLS"),
bold("STARS"),
bold("REGISTRY"),
bold("DESCRIPTION"),
);
} else {
println!(
"{:<36} {:<12} {}",
bold("NAME"),
bold("REGISTRY"),
bold("DESCRIPTION"),
);
}
for r in &results {
let desc = r.description.as_deref().unwrap_or("-");
let desc: String = if desc.chars().count() > 60 {
desc.chars().take(57).collect::<String>() + "..."
} else {
desc.to_string()
};
let reg = r.registry.as_str();
if has_stats {
let inst =
r.installs.map(format_count).unwrap_or_else(|| "-".into());
let stars = r.stars.map(format_count).unwrap_or_else(|| "-".into());
println!(
"{:<36} {:>10} {:>8} {:<12} {}",
cyan(&r.slug),
inst,
stars,
dim(reg),
desc,
);
} else {
println!("{:<36} {:<12} {}", cyan(&r.slug), dim(reg), desc,);
}
}
println!();
println!("Install with: rsclaw skills install <name>");
}
}
Err(e) => {
eprintln!("Search failed: {e:#}");
std::process::exit(1);
}
}
}
SkillsCommand::Update { name } => {
let client = skill::clawhub::ClawhubClient::new().with_language(language.clone());
let lock = skill::clawhub::LockFile::read(&global_dir).unwrap_or_default();
let slugs: Vec<String> = if let Some(name) = name {
vec![name]
} else {
lock.skills.keys().cloned().collect()
};
if slugs.is_empty() {
println!("No skills to update.");
return Ok(());
}
for slug in &slugs {
print!("Updating '{}'... ", cyan(slug));
// Use install_with_fallback so re-resolution walks the full
// chain (clawhub → skillhub → iwencai). Bare `install` only
// hits clawhub and would mark every iwencai/skillhub skill
// as a "failed" update.
match client.install_with_fallback(slug, &global_dir).await {
Ok(locked) => println!("{}", green(&format!("v{}", locked.version))),
Err(e) => println!("{}", red(&format!("failed: {e:#}"))),
}
}
}
}
Ok(())
}
/// Format a count with K/M suffixes for compact display.
fn format_count(n: u64) -> String {
if n >= 1_000_000 {
format!("{:.1}M", n as f64 / 1_000_000.0)
} else if n >= 1_000 {
format!("{:.1}K", n as f64 / 1_000.0)
} else {
n.to_string()
}
}