agents-skills 0.28.1

A minimal, stable, easy-to-understand skill installer and manager for AI agents
Documentation
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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
//! Unit tests for the linking machinery.

use std::fs;

use crate::core::agents::get_agent;
use crate::core::install::{install_skill, move_skill, sanitize_name, scan_installed};
use crate::core::link::outcome::LinkOutcome;
use crate::core::link::{is_agent_linked, link_agent, private_content, unlink_agent};
use crate::core::test_utils::{env_at, skill_frontmatter, symlink_dir, write_and_parse_skill};

/// Sorted copy of a names vec (read_dir order is arbitrary).
fn sorted(mut v: Vec<String>) -> Vec<String> {
    v.sort();
    v
}

#[test]
fn link_agent_creates_a_dir_link_to_canonical() {
    let tmp = tempfile::TempDir::new().unwrap();
    let env = env_at(&tmp);
    fs::create_dir_all(tmp.path().join(".cursor")).unwrap();
    let agent = get_agent("cursor").unwrap();

    let outcome = link_agent(agent, &env);
    assert!(
        matches!(
            outcome,
            LinkOutcome::Linked {
                ref adopted,
                ref quarantined,
                ref conflicts,
            } if adopted.is_empty() && quarantined.is_empty() && conflicts.is_empty()
        ),
        "got {outcome:?}"
    );
    let link = tmp.path().join(".cursor/skills");
    assert!(link.is_symlink());
    // The raw target form is platform-specific — a relative symlink on Unix,
    // an absolute junction on Windows — but it must resolve to the canonical dir.
    let canonical = tmp.path().join(".agents/skills");
    assert_eq!(
        fs::canonicalize(&link).unwrap(),
        fs::canonicalize(&canonical).unwrap()
    );
}

#[test]
fn link_agent_skips_when_agent_root_missing() {
    let tmp = tempfile::TempDir::new().unwrap();
    let env = env_at(&tmp);
    let agent = get_agent("cursor").unwrap(); // ~/.cursor does not exist

    assert!(matches!(link_agent(agent, &env), LinkOutcome::Skipped));
    assert!(!tmp.path().join(".cursor").exists());
}

#[test]
fn link_agent_claude_code_links_even_without_root() {
    let tmp = tempfile::TempDir::new().unwrap();
    let env = env_at(&tmp);
    let agent = get_agent("claude-code").unwrap(); // ~/.claude does not exist

    assert!(matches!(
        link_agent(agent, &env),
        LinkOutcome::Linked { .. }
    ));
    assert!(tmp.path().join(".claude/skills").is_symlink());
}

#[test]
fn link_agent_native_agent_is_already_linked() {
    // Cline's skills dir is ~/.agents/skills itself — nothing to link.
    let tmp = tempfile::TempDir::new().unwrap();
    let env = env_at(&tmp);
    let cline = get_agent("cline").unwrap();
    assert!(matches!(
        link_agent(cline, &env),
        LinkOutcome::AlreadyLinked
    ));
    assert!(is_agent_linked(cline, &env));
    assert!(matches!(unlink_agent(cline, &env), LinkOutcome::NotLinked));
}

#[test]
fn link_agent_skipped_when_dir_cannot_be_resolved() {
    // eve's skills dir is env-var based and the var is unset.
    let tmp = tempfile::TempDir::new().unwrap();
    let env = env_at(&tmp);
    let agent = get_agent("eve").unwrap();
    assert!(matches!(link_agent(agent, &env), LinkOutcome::Skipped));
}

#[test]
fn link_agent_is_idempotent() {
    let tmp = tempfile::TempDir::new().unwrap();
    let env = env_at(&tmp);
    fs::create_dir_all(tmp.path().join(".cursor")).unwrap();
    let agent = get_agent("cursor").unwrap();

    assert!(matches!(
        link_agent(agent, &env),
        LinkOutcome::Linked { .. }
    ));
    assert!(matches!(
        link_agent(agent, &env),
        LinkOutcome::AlreadyLinked
    ));
}

#[test]
fn link_agent_refuses_foreign_symlink() {
    let tmp = tempfile::TempDir::new().unwrap();
    let env = env_at(&tmp);
    fs::create_dir_all(tmp.path().join(".cursor")).unwrap();
    fs::create_dir_all(tmp.path().join("elsewhere")).unwrap();
    symlink_dir(
        &tmp.path().join("elsewhere"),
        &tmp.path().join(".cursor/skills"),
    );
    let agent = get_agent("cursor").unwrap();

    assert!(matches!(
        link_agent(agent, &env),
        LinkOutcome::Refused { .. }
    ));
}

#[test]
fn link_agent_adopts_existing_skills_and_links() {
    let tmp = tempfile::TempDir::new().unwrap();
    let env = env_at(&tmp);
    let existing = tmp.path().join(".claude/skills/my-skill");
    fs::create_dir_all(&existing).unwrap();
    fs::write(existing.join("SKILL.md"), "x").unwrap();
    // A symlinked skill pointing elsewhere (e.g. into a skills hub) is moved
    // as a link, preserving its target.
    fs::create_dir_all(tmp.path().join("hub/hub-skill")).unwrap();
    symlink_dir(
        &tmp.path().join("hub/hub-skill"),
        &tmp.path().join(".claude/skills/hub-skill"),
    );
    let agent = get_agent("claude-code").unwrap();

    match link_agent(agent, &env) {
        LinkOutcome::Linked {
            adopted,
            quarantined,
            conflicts,
        } => {
            assert_eq!(sorted(adopted), vec!["hub-skill", "my-skill"]);
            assert!(quarantined.is_empty());
            assert!(conflicts.is_empty());
        }
        other => panic!("expected Linked, got {other:?}"),
    }
    assert!(tmp.path().join(".agents/skills/my-skill/SKILL.md").exists());
    let moved_link = tmp.path().join(".agents/skills/hub-skill");
    assert!(moved_link.is_symlink());
    // The moved link still resolves to the hub skill (its raw target form is
    // platform-specific).
    assert_eq!(
        fs::canonicalize(&moved_link).unwrap(),
        fs::canonicalize(tmp.path().join("hub/hub-skill")).unwrap()
    );
    assert!(tmp.path().join(".claude/skills").is_symlink());
    // Nothing was quarantined, so no `.misc` dir exists.
    assert!(!tmp.path().join(".agents/skills/.misc").exists());
}

#[test]
fn link_agent_quarantines_non_skill_entries() {
    let tmp = tempfile::TempDir::new().unwrap();
    let env = env_at(&tmp);
    fs::create_dir_all(tmp.path().join(".claude/skills/my-skill")).unwrap();
    fs::write(
        tmp.path().join(".claude/skills/my-skill/SKILL.md"),
        skill_frontmatter("my-skill"),
    )
    .unwrap();
    fs::write(tmp.path().join(".claude/skills/README.txt"), "x").unwrap();
    let agent = get_agent("claude-code").unwrap();

    match link_agent(agent, &env) {
        LinkOutcome::Linked {
            adopted,
            quarantined,
            conflicts,
        } => {
            assert_eq!(adopted, vec!["my-skill"]);
            assert_eq!(quarantined, vec!["README.txt"]);
            assert!(conflicts.is_empty());
        }
        other => panic!("expected Linked, got {other:?}"),
    }
    assert!(tmp.path().join(".agents/skills/my-skill/SKILL.md").exists());
    assert!(
        tmp.path()
            .join(".agents/skills/.misc/claude-code/README.txt")
            .exists()
    );
    assert!(tmp.path().join(".claude/skills").is_symlink());

    // The quarantine dot-dir never shows up as an installed skill.
    let scanned: Vec<String> = scan_installed(&env)
        .iter()
        .map(|s| s.name.clone())
        .collect();
    assert_eq!(scanned, vec!["my-skill".to_string()]);
}

#[test]
fn link_agent_drops_conflict_across_name_normalization() {
    // The canonical dir holds the sanitized name (`add` normalizes its target),
    // while the agent dir holds an unnormalized one — same skill, so it clashes.
    let tmp = tempfile::TempDir::new().unwrap();
    let env = env_at(&tmp);
    fs::create_dir_all(tmp.path().join(".agents/skills/pdf-master")).unwrap();
    fs::write(
        tmp.path().join(".agents/skills/pdf-master/SKILL.md"),
        skill_frontmatter("pdf-master"),
    )
    .unwrap();
    let existing = tmp.path().join(".claude/skills/PDF Master");
    fs::create_dir_all(&existing).unwrap();
    fs::write(existing.join("SKILL.md"), "agent copy").unwrap();
    let agent = get_agent("claude-code").unwrap();

    match link_agent(agent, &env) {
        LinkOutcome::Linked {
            adopted, conflicts, ..
        } => {
            assert!(adopted.is_empty());
            assert_eq!(conflicts, vec!["PDF Master"]);
        }
        other => panic!("expected Linked, got {other:?}"),
    }
    // Only the canonical copy survives.
    assert_eq!(
        fs::read_to_string(tmp.path().join(".agents/skills/pdf-master/SKILL.md")).unwrap(),
        skill_frontmatter("pdf-master")
    );
    assert!(!tmp.path().join(".agents/skills/PDF Master").exists());
    let scanned: Vec<String> = scan_installed(&env)
        .iter()
        .map(|s| s.name.clone())
        .collect();
    assert_eq!(scanned, vec!["pdf-master".to_string()]);
}

#[test]
fn link_agent_keeps_only_one_of_two_sibling_names() {
    // Two entries in the same agent dir that normalize to the same name cannot
    // both be adopted; read_dir order decides which one wins.
    let tmp = tempfile::TempDir::new().unwrap();
    let env = env_at(&tmp);
    for dir in [".claude/skills/PDF Master", ".claude/skills/pdf-master"] {
        fs::create_dir_all(tmp.path().join(dir)).unwrap();
        fs::write(
            tmp.path().join(dir).join("SKILL.md"),
            skill_frontmatter("pdf-master"),
        )
        .unwrap();
    }
    let agent = get_agent("claude-code").unwrap();

    match link_agent(agent, &env) {
        LinkOutcome::Linked {
            adopted, conflicts, ..
        } => {
            assert_eq!(adopted.len(), 1);
            assert_eq!(conflicts.len(), 1);
            assert_eq!(sanitize_name(&adopted[0]), sanitize_name(&conflicts[0]));
        }
        other => panic!("expected Linked, got {other:?}"),
    }
    assert_eq!(scan_installed(&env).len(), 1);
}

#[test]
fn link_agent_drops_name_conflicts_in_favour_of_canonical() {
    let tmp = tempfile::TempDir::new().unwrap();
    let env = env_at(&tmp);
    // Same name already installed in canonical; the canonical copy wins.
    fs::create_dir_all(tmp.path().join(".agents/skills/pdf")).unwrap();
    fs::write(tmp.path().join(".agents/skills/pdf/SKILL.md"), "canonical").unwrap();
    let existing = tmp.path().join(".claude/skills/pdf");
    fs::create_dir_all(&existing).unwrap();
    fs::write(existing.join("SKILL.md"), "agent copy").unwrap();
    // Another skill that does not clash is still adopted.
    fs::create_dir_all(tmp.path().join(".claude/skills/notes")).unwrap();
    fs::write(tmp.path().join(".claude/skills/notes/SKILL.md"), "x").unwrap();
    let agent = get_agent("claude-code").unwrap();

    match link_agent(agent, &env) {
        LinkOutcome::Linked {
            adopted,
            quarantined,
            conflicts,
        } => {
            assert_eq!(adopted, vec!["notes"]);
            assert!(quarantined.is_empty());
            assert_eq!(conflicts, vec!["pdf"]);
        }
        other => panic!("expected Linked, got {other:?}"),
    }
    // Canonical copy untouched; the agent-side duplicate is gone.
    assert_eq!(
        fs::read_to_string(tmp.path().join(".agents/skills/pdf/SKILL.md")).unwrap(),
        "canonical"
    );
    assert!(tmp.path().join(".agents/skills/notes/SKILL.md").exists());
    assert!(tmp.path().join(".claude/skills").is_symlink());
}

#[test]
fn link_agent_drops_conflicts_with_disabled_skills() {
    // A skill disabled into the disabled dir must not be re-imported when
    // linking an agent that holds its own copy of the same name.
    let tmp = tempfile::TempDir::new().unwrap();
    let env = env_at(&tmp);
    let src = tmp.path().join("pdf");
    let skill = write_and_parse_skill(&src, "pdf");
    install_skill(&skill, false, &env).unwrap();
    move_skill("pdf", false, &env).unwrap();
    // The agent holds its own copy of the disabled skill plus a fresh one.
    let existing = tmp.path().join(".claude/skills/pdf");
    fs::create_dir_all(&existing).unwrap();
    fs::write(existing.join("SKILL.md"), "agent copy").unwrap();
    fs::create_dir_all(tmp.path().join(".claude/skills/notes")).unwrap();
    fs::write(tmp.path().join(".claude/skills/notes/SKILL.md"), "x").unwrap();
    let agent = get_agent("claude-code").unwrap();

    match link_agent(agent, &env) {
        LinkOutcome::Linked {
            adopted, conflicts, ..
        } => {
            assert_eq!(adopted, vec!["notes"]);
            assert_eq!(conflicts, vec!["pdf"]);
        }
        other => panic!("expected Linked, got {other:?}"),
    }
    // The disabled copy stays disabled; the agent copy is dropped.
    assert!(!tmp.path().join(".agents/skills/pdf").exists());
    assert!(
        tmp.path()
            .join(".agents/disabled-skills/pdf/SKILL.md")
            .exists()
    );
    // The fresh skill was adopted normally.
    assert!(tmp.path().join(".agents/skills/notes/SKILL.md").exists());
}

#[test]
fn link_agent_drops_legacy_per_skill_links() {
    // Old-model agent dirs hold per-skill symlinks into the canonical dir. Their
    // content already lives there, so the links are dropped — moving them in
    // would create a self-referential symlink.
    let tmp = tempfile::TempDir::new().unwrap();
    let env = env_at(&tmp);
    let src = tmp.path().join("pdf");
    let skill = write_and_parse_skill(&src, "pdf");
    install_skill(&skill, false, &env).unwrap();
    fs::create_dir_all(tmp.path().join(".cursor/skills")).unwrap();
    symlink_dir(
        &tmp.path().join(".agents/skills/pdf"),
        &tmp.path().join(".cursor/skills/pdf"),
    );
    let agent = get_agent("cursor").unwrap();

    match link_agent(agent, &env) {
        LinkOutcome::Linked {
            adopted, conflicts, ..
        } => {
            assert!(adopted.is_empty());
            assert_eq!(conflicts, vec!["pdf"]);
        }
        other => panic!("expected Linked, got {other:?}"),
    }
    // The canonical skill is still a real dir, not a self-referential symlink.
    let canonical_skill = tmp.path().join(".agents/skills/pdf");
    assert!(canonical_skill.is_dir());
    assert!(!canonical_skill.is_symlink());
    assert!(canonical_skill.join("SKILL.md").exists());
    assert!(tmp.path().join(".cursor/skills").is_symlink());
}

#[test]
fn unlink_agent_does_not_restore_adopted_skills() {
    let tmp = tempfile::TempDir::new().unwrap();
    let env = env_at(&tmp);
    let existing = tmp.path().join(".claude/skills/my-skill");
    fs::create_dir_all(&existing).unwrap();
    fs::write(existing.join("SKILL.md"), "x").unwrap();
    let agent = get_agent("claude-code").unwrap();
    assert!(matches!(
        link_agent(agent, &env),
        LinkOutcome::Linked { .. }
    ));

    assert!(matches!(unlink_agent(agent, &env), LinkOutcome::Unlinked));
    // The adopted skill stays in the canonical dir (managed by `remove`).
    assert!(tmp.path().join(".agents/skills/my-skill/SKILL.md").exists());
    let dir = tmp.path().join(".claude/skills");
    assert!(dir.is_dir());
    assert!(!dir.is_symlink());
    assert!(fs::read_dir(&dir).unwrap().count() == 0);
}

#[test]
fn unlink_agent_removes_link_and_recreates_empty_dir() {
    let tmp = tempfile::TempDir::new().unwrap();
    let env = env_at(&tmp);
    fs::create_dir_all(tmp.path().join(".cursor")).unwrap();
    let agent = get_agent("cursor").unwrap();
    assert!(matches!(
        link_agent(agent, &env),
        LinkOutcome::Linked { .. }
    ));

    assert!(matches!(unlink_agent(agent, &env), LinkOutcome::Unlinked));
    let dir = tmp.path().join(".cursor/skills");
    assert!(dir.is_dir());
    assert!(!dir.is_symlink());
    assert!(fs::read_dir(&dir).unwrap().count() == 0);
}

#[test]
fn unlink_agent_leaves_real_dirs_and_foreign_links_alone() {
    let tmp = tempfile::TempDir::new().unwrap();
    let env = env_at(&tmp);
    fs::create_dir_all(tmp.path().join(".claude/skills/my-skill")).unwrap();
    let agent = get_agent("claude-code").unwrap();
    assert!(matches!(unlink_agent(agent, &env), LinkOutcome::NotLinked));
    assert!(tmp.path().join(".claude/skills/my-skill").exists());

    // Native agents never link.
    let uni = get_agent("cline").unwrap();
    assert!(matches!(unlink_agent(uni, &env), LinkOutcome::NotLinked));
}

#[test]
fn is_agent_linked_reflects_dir_links() {
    let tmp = tempfile::TempDir::new().unwrap();
    let env = env_at(&tmp);
    let agent = get_agent("cursor").unwrap();
    assert!(!is_agent_linked(agent, &env));
    fs::create_dir_all(tmp.path().join(".cursor")).unwrap();
    assert!(matches!(
        link_agent(agent, &env),
        LinkOutcome::Linked { .. }
    ));
    assert!(is_agent_linked(agent, &env));
    // Native agents are always "linked" (canonical is their dir).
    assert!(is_agent_linked(get_agent("cline").unwrap(), &env));
}

#[test]
fn private_content_classifies_skills_and_others() {
    let tmp = tempfile::TempDir::new().unwrap();
    let env = env_at(&tmp);
    fs::create_dir_all(tmp.path().join(".claude/skills/my-skill")).unwrap();
    fs::write(tmp.path().join(".claude/skills/my-skill/SKILL.md"), "x").unwrap();
    fs::write(tmp.path().join(".claude/skills/README.txt"), "x").unwrap();
    let agent = get_agent("claude-code").unwrap();

    let (skills, others) = private_content(agent, &env);
    assert_eq!(skills, vec!["my-skill"]);
    assert_eq!(others, vec!["README.txt"]);

    // A linked (or foreign-symlink) skills dir is not private content.
    assert!(matches!(
        link_agent(agent, &env),
        LinkOutcome::Linked { .. }
    ));
    assert_eq!(private_content(agent, &env), (Vec::new(), Vec::new()));
}